pub struct TargetDescription { /* private fields */ }Expand description
Description of a target, used in verification.
Implementations§
Source§impl TargetDescription
impl TargetDescription
Sourcepub fn new(
length: u64,
hashes: HashMap<HashAlgorithm, HashValue>,
custom: HashMap<String, Value>,
) -> Result<Self>
pub fn new( length: u64, hashes: HashMap<HashAlgorithm, HashValue>, custom: HashMap<String, Value>, ) -> Result<Self>
Create a new TargetDescription.
Note: Creating this manually could lead to errors, and the from_reader method is
preferred.
Sourcepub fn from_slice(buf: &[u8], hash_algs: &[HashAlgorithm]) -> Result<Self>
pub fn from_slice(buf: &[u8], hash_algs: &[HashAlgorithm]) -> Result<Self>
Read the from the given slice and calculate the length and hash values.
let bytes: &[u8] = b"it was a pleasure to burn";
let target_description = TargetDescription::from_slice(
bytes,
&[HashAlgorithm::Sha256, HashAlgorithm::Sha512],
).unwrap();
let s = "Rd9zlbzrdWfeL7gnIEi05X-Yv2TCpy4qqZM1N72ZWQs=";
let sha256 = HashValue::new(BASE64URL.decode(s.as_bytes()).unwrap());
let s ="tuIxwKybYdvJpWuUj6dubvpwhkAozWB6hMJIRzqn2jOUdtDTBg381brV4K\
BU1zKP8GShoJuXEtCf5NkDTCEJgQ==";
let sha512 = HashValue::new(BASE64URL.decode(s.as_bytes()).unwrap());
assert_eq!(target_description.length(), bytes.len() as u64);
assert_eq!(target_description.hashes().get(&HashAlgorithm::Sha256), Some(&sha256));
assert_eq!(target_description.hashes().get(&HashAlgorithm::Sha512), Some(&sha512));Sourcepub fn from_slice_with_custom(
buf: &[u8],
hash_algs: &[HashAlgorithm],
custom: HashMap<String, Value>,
) -> Result<Self>
pub fn from_slice_with_custom( buf: &[u8], hash_algs: &[HashAlgorithm], custom: HashMap<String, Value>, ) -> Result<Self>
Read the from the given reader and custom metadata and calculate the length and hash values.
let bytes: &[u8] = b"it was a pleasure to burn";
let mut custom = HashMap::new();
custom.insert("Hello".into(), "World".into());
let target_description = TargetDescription::from_slice_with_custom(
bytes,
&[HashAlgorithm::Sha256, HashAlgorithm::Sha512],
custom,
).unwrap();
let s = "Rd9zlbzrdWfeL7gnIEi05X-Yv2TCpy4qqZM1N72ZWQs=";
let sha256 = HashValue::new(BASE64URL.decode(s.as_bytes()).unwrap());
let s ="tuIxwKybYdvJpWuUj6dubvpwhkAozWB6hMJIRzqn2jOUdtDTBg381brV4K\
BU1zKP8GShoJuXEtCf5NkDTCEJgQ==";
let sha512 = HashValue::new(BASE64URL.decode(s.as_bytes()).unwrap());
assert_eq!(target_description.length(), bytes.len() as u64);
assert_eq!(target_description.hashes().get(&HashAlgorithm::Sha256), Some(&sha256));
assert_eq!(target_description.hashes().get(&HashAlgorithm::Sha512), Some(&sha512));
assert_eq!(target_description.custom().get("Hello"), Some(&"World".into()));Sourcepub async fn from_reader<R>(
read: R,
hash_algs: &[HashAlgorithm],
) -> Result<Self>
pub async fn from_reader<R>( read: R, hash_algs: &[HashAlgorithm], ) -> Result<Self>
Read the from the given reader and calculate the length and hash values.
let bytes: &[u8] = b"it was a pleasure to burn";
let target_description = TargetDescription::from_reader(
bytes,
&[HashAlgorithm::Sha256, HashAlgorithm::Sha512],
).await.unwrap();
let s = "Rd9zlbzrdWfeL7gnIEi05X-Yv2TCpy4qqZM1N72ZWQs=";
let sha256 = HashValue::new(BASE64URL.decode(s.as_bytes()).unwrap());
let s ="tuIxwKybYdvJpWuUj6dubvpwhkAozWB6hMJIRzqn2jOUdtDTBg381brV4K\
BU1zKP8GShoJuXEtCf5NkDTCEJgQ==";
let sha512 = HashValue::new(BASE64URL.decode(s.as_bytes()).unwrap());
assert_eq!(target_description.length(), bytes.len() as u64);
assert_eq!(target_description.hashes().get(&HashAlgorithm::Sha256), Some(&sha256));
assert_eq!(target_description.hashes().get(&HashAlgorithm::Sha512), Some(&sha512));Sourcepub async fn from_reader_with_custom<R>(
read: R,
hash_algs: &[HashAlgorithm],
custom: HashMap<String, Value>,
) -> Result<Self>
pub async fn from_reader_with_custom<R>( read: R, hash_algs: &[HashAlgorithm], custom: HashMap<String, Value>, ) -> Result<Self>
Read the from the given reader and custom metadata and calculate the length and hash values.
let bytes: &[u8] = b"it was a pleasure to burn";
let mut custom = HashMap::new();
custom.insert("Hello".into(), "World".into());
let target_description = TargetDescription::from_reader_with_custom(
bytes,
&[HashAlgorithm::Sha256, HashAlgorithm::Sha512],
custom,
).await.unwrap();
let s = "Rd9zlbzrdWfeL7gnIEi05X-Yv2TCpy4qqZM1N72ZWQs=";
let sha256 = HashValue::new(BASE64URL.decode(s.as_bytes()).unwrap());
let s ="tuIxwKybYdvJpWuUj6dubvpwhkAozWB6hMJIRzqn2jOUdtDTBg381brV4K\
BU1zKP8GShoJuXEtCf5NkDTCEJgQ==";
let sha512 = HashValue::new(BASE64URL.decode(s.as_bytes()).unwrap());
assert_eq!(target_description.length(), bytes.len() as u64);
assert_eq!(target_description.hashes().get(&HashAlgorithm::Sha256), Some(&sha256));
assert_eq!(target_description.hashes().get(&HashAlgorithm::Sha512), Some(&sha512));
assert_eq!(target_description.custom().get("Hello"), Some(&"World".into()));
})Sourcepub fn hashes(&self) -> &HashMap<HashAlgorithm, HashValue>
pub fn hashes(&self) -> &HashMap<HashAlgorithm, HashValue>
An immutable reference to the list of calculated hashes.
Trait Implementations§
Source§impl Clone for TargetDescription
impl Clone for TargetDescription
Source§fn clone(&self) -> TargetDescription
fn clone(&self) -> TargetDescription
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TargetDescription
impl Debug for TargetDescription
Source§impl<'de> Deserialize<'de> for TargetDescription
impl<'de> Deserialize<'de> for TargetDescription
Source§fn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(de: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for TargetDescription
impl PartialEq for TargetDescription
Source§impl Serialize for TargetDescription
impl Serialize for TargetDescription
impl Eq for TargetDescription
impl StructuralPartialEq for TargetDescription
Auto Trait Implementations§
impl Freeze for TargetDescription
impl RefUnwindSafe for TargetDescription
impl Send for TargetDescription
impl Sync for TargetDescription
impl Unpin for TargetDescription
impl UnsafeUnpin for TargetDescription
impl UnwindSafe for TargetDescription
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more