mirror of
https://codeberg.org/Toasterson/ips.git
synced 2026-04-10 21:30:41 +00:00
Add digest parsing
This commit is contained in:
parent
56ec3c718d
commit
f9ede380b1
3 changed files with 49 additions and 3 deletions
|
|
@ -20,14 +20,25 @@ trait FacetedAction {
|
|||
fn remove_facet(&mut self, facet: Facet) -> bool;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Action {
|
||||
kind: ActionKind,
|
||||
payload_reference: String,
|
||||
payload: Payload,
|
||||
properties: Vec<Property>,
|
||||
facets: HashSet<Facet>,
|
||||
}
|
||||
|
||||
impl Action {
|
||||
fn new(kind: ActionKind) -> Action{
|
||||
Action{
|
||||
kind,
|
||||
payload: Payload::default(),
|
||||
properties: Vec::new(),
|
||||
facets: HashSet::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FacetedAction for Action {
|
||||
fn add_facet(&mut self, facet: Facet) -> bool {
|
||||
return self.facets.insert(facet)
|
||||
|
|
@ -59,7 +70,7 @@ impl FacetedAction for Dir {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Debug)]
|
||||
pub struct File {
|
||||
pub payload: Payload,
|
||||
pub path: String,
|
||||
|
|
|
|||
|
|
@ -37,10 +37,44 @@ pub struct Digest {
|
|||
source: DigestSource,
|
||||
}
|
||||
|
||||
|
||||
|
||||
impl FromStr for Digest {
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, failure::Error> {
|
||||
if !s.contains(":") {
|
||||
Ok(Digest{
|
||||
hash: String::from(s),
|
||||
algorithm: DigestAlgorithm::SHA1,
|
||||
source: "primary".to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
let parts = String::from(s).split(':').collect();
|
||||
if parts.len() < 3 {
|
||||
Err(DigestError::InvalidDigestFormat{
|
||||
digest: String::from(s),
|
||||
details: "cannot split into 3 parts".to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
Ok(Digest{
|
||||
source: String::from(&parts[0]),
|
||||
algorithm: String::from(&parts[1]),
|
||||
hash: String::from(&parts[2]),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Fail)]
|
||||
pub enum DigestError {
|
||||
#[fail(display = "hashing algorithm {} is not known by this library", algorithm)]
|
||||
UnknownAlgorithm {
|
||||
algorithm: String,
|
||||
},
|
||||
#[fail(display = "digest {} is not formatted properly: {}", digest, details)]
|
||||
InvalidDigestFormat{
|
||||
digest: String,
|
||||
details: String,
|
||||
},
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
// obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
use crate::digest::Digest;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum PayloadCompressionAlgorithm {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue