Skip to main content

TargetDescription

Struct TargetDescription 

Source
pub struct TargetDescription { /* private fields */ }
Expand description

Description of a target, used in verification.

Implementations§

Source§

impl TargetDescription

Source

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.

Source

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));
Source

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()));
Source

pub async fn from_reader<R>( read: R, hash_algs: &[HashAlgorithm], ) -> Result<Self>
where R: AsyncRead + Unpin,

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));
Source

pub async fn from_reader_with_custom<R>( read: R, hash_algs: &[HashAlgorithm], custom: HashMap<String, Value>, ) -> Result<Self>
where R: AsyncRead + Unpin,

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()));
})
Source

pub fn length(&self) -> u64

The maximum length of the target.

Source

pub fn hashes(&self) -> &HashMap<HashAlgorithm, HashValue>

An immutable reference to the list of calculated hashes.

Source

pub fn custom(&self) -> &HashMap<String, Value>

An immutable reference to the custom metadata.

Trait Implementations§

Source§

impl Clone for TargetDescription

Source§

fn clone(&self) -> TargetDescription

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TargetDescription

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for TargetDescription

Source§

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

Source§

fn eq(&self, other: &TargetDescription) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for TargetDescription

Source§

fn serialize<S>(&self, ser: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for TargetDescription

Source§

impl StructuralPartialEq for TargetDescription

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,