Struct bc_envelope::prelude::Digest
source · pub struct Digest(/* private fields */);Expand description
A cryptographically secure digest, implemented with SHA-256.
Implementations§
source§impl Digest
impl Digest
pub const DIGEST_SIZE: usize = 32usize
sourcepub fn from_data_ref(data: impl AsRef<[u8]>) -> Result<Digest, Error>
pub fn from_data_ref(data: impl AsRef<[u8]>) -> Result<Digest, Error>
Create a new digest from data.
Returns None if the data is not the correct length.
sourcepub fn from_image(image: impl AsRef<[u8]>) -> Digest
pub fn from_image(image: impl AsRef<[u8]>) -> Digest
Create a new digest from the given image.
The image is hashed with SHA-256.
sourcepub fn from_image_parts(image_parts: &[&[u8]]) -> Digest
pub fn from_image_parts(image_parts: &[&[u8]]) -> Digest
Create a new digest from an array of data items.
The image parts are concatenated and hashed with SHA-256.
sourcepub fn from_digests(digests: &[Digest]) -> Digest
pub fn from_digests(digests: &[Digest]) -> Digest
Create a new digest from an array of Digests.
The image parts are concatenated and hashed with SHA-256.
sourcepub fn validate(&self, image: impl AsRef<[u8]>) -> bool
pub fn validate(&self, image: impl AsRef<[u8]>) -> bool
Validate the digest against the given image.
The image is hashed with SHA-256 and compared to the digest.
Returns true if the digest matches the image.
sourcepub fn from_hex(hex: impl AsRef<str>) -> Digest
pub fn from_hex(hex: impl AsRef<str>) -> Digest
Create a new digest from the given hexadecimal string.
§Panics
Panics if the string is not exactly 64 hexadecimal digits.
sourcepub fn short_description(&self) -> String
pub fn short_description(&self) -> String
The first four bytes of the digest as a hexadecimal string.
Trait Implementations§
source§impl CBORTagged for Digest
impl CBORTagged for Digest
The CBOR tags assocated with this type. If more than one tag is present,
they are considered equivalent for reading, but only the first one is
used for writing.
source§impl CBORTaggedDecodable for Digest
impl CBORTaggedDecodable for Digest
source§fn from_untagged_cbor(cbor: CBOR) -> Result<Digest, Error>
fn from_untagged_cbor(cbor: CBOR) -> Result<Digest, Error>
Creates an instance of this type by decoding it from untagged CBOR.
source§fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
Creates an instance of this type by decoding it from tagged CBOR.
source§impl CBORTaggedEncodable for Digest
impl CBORTaggedEncodable for Digest
source§fn untagged_cbor(&self) -> CBOR
fn untagged_cbor(&self) -> CBOR
Returns the untagged CBOR encoding of this instance.
source§fn tagged_cbor(&self) -> CBOR
fn tagged_cbor(&self) -> CBOR
Returns the tagged CBOR encoding of this instance.
source§impl EnvelopeEncodable for Digest
impl EnvelopeEncodable for Digest
fn into_envelope(self) -> Envelope
fn to_envelope(&self) -> Envelopewhere
Self: Clone,
source§impl EnvelopeFormat for Digest
impl EnvelopeFormat for Digest
fn format_item(&self, _context: &FormatContext) -> EnvelopeFormatItem
source§impl Ord for Digest
impl Ord for Digest
source§impl PartialEq for Digest
impl PartialEq for Digest
source§impl PartialOrd for Digest
impl PartialOrd for Digest
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read moreimpl Eq for Digest
impl StructuralPartialEq for Digest
Auto Trait Implementations§
impl Freeze for Digest
impl RefUnwindSafe for Digest
impl Send for Digest
impl Sync for Digest
impl Unpin for Digest
impl UnwindSafe for Digest
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
source§impl<T> CBOREncodable for T
impl<T> CBOREncodable for T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§impl<T> ToHex for T
impl<T> ToHex for T
source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
Encode the hex strict representing
self into the result. Lower case
letters are used (e.g. f9b4ca)source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
Encode the hex strict representing
self into the result. Upper case
letters are used (e.g. F9B4CA)