Struct Digest

Source
pub struct Digest(/* private fields */);
Expand description

A hash digest.

Check digest module for usage examples.

Implementations§

Source§

impl Digest

Source

pub const fn new(digest: [u8; 64]) -> Self

Creates a new digest.

Source

pub const fn as_bytes(&self) -> &[u8]

Returns a byte slice of the digest’s contents.

Source

pub fn into_inner(self) -> [u8; 64]

Consumes the digest, returning the digest bytes.

Source

pub fn to_hex_lowercase(&self) -> String

Returns a string in the lowercase hexadecimal representation.

§Example
use chksum_hash_sha2_512 as sha2_512;

#[rustfmt::skip]
let digest = [
    0xCF, 0x83, 0xE1, 0x35,
    0x7E, 0xEF, 0xB8, 0xBD,
    0xF1, 0x54, 0x28, 0x50,
    0xD6, 0x6D, 0x80, 0x07,
    0xD6, 0x20, 0xE4, 0x05,
    0x0B, 0x57, 0x15, 0xDC,
    0x83, 0xF4, 0xA9, 0x21,
    0xD3, 0x6C, 0xE9, 0xCE,
    0x47, 0xD0, 0xD1, 0x3C,
    0x5D, 0x85, 0xF2, 0xB0,
    0xFF, 0x83, 0x18, 0xD2,
    0x87, 0x7E, 0xEC, 0x2F,
    0x63, 0xB9, 0x31, 0xBD,
    0x47, 0x41, 0x7A, 0x81,
    0xA5, 0x38, 0x32, 0x7A,
    0xF9, 0x27, 0xDA, 0x3E,
];
let digest = sha2_512::Digest::new(digest);
assert_eq!(
    digest.to_hex_lowercase(),
    "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"
);
Source

pub fn to_hex_uppercase(&self) -> String

Returns a string in the uppercase hexadecimal representation.

§Example
use chksum_hash_sha2_512 as sha2_512;

#[rustfmt::skip]
let digest = [
    0xCF, 0x83, 0xE1, 0x35,
    0x7E, 0xEF, 0xB8, 0xBD,
    0xF1, 0x54, 0x28, 0x50,
    0xD6, 0x6D, 0x80, 0x07,
    0xD6, 0x20, 0xE4, 0x05,
    0x0B, 0x57, 0x15, 0xDC,
    0x83, 0xF4, 0xA9, 0x21,
    0xD3, 0x6C, 0xE9, 0xCE,
    0x47, 0xD0, 0xD1, 0x3C,
    0x5D, 0x85, 0xF2, 0xB0,
    0xFF, 0x83, 0x18, 0xD2,
    0x87, 0x7E, 0xEC, 0x2F,
    0x63, 0xB9, 0x31, 0xBD,
    0x47, 0x41, 0x7A, 0x81,
    0xA5, 0x38, 0x32, 0x7A,
    0xF9, 0x27, 0xDA, 0x3E,
];
let digest = sha2_512::Digest::new(digest);
assert_eq!(
    digest.to_hex_uppercase(),
    "CF83E1357EEFB8BDF1542850D66D8007D620E4050B5715DC83F4A921D36CE9CE47D0D13C5D85F2B0FF8318D2877EEC2F63B931BD47417A81A538327AF927DA3E"
);

Trait Implementations§

Source§

impl AsRef<[u8]> for Digest

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Digest

Source§

fn clone(&self) -> Digest

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 Digest

Source§

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

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

impl Digest for Digest

Source§

fn as_bytes(&self) -> &[u8]
where Self: AsRef<[u8]>,

Returns the digest as a byte slice.
Source§

fn to_hex_lowercase(&self) -> String
where Self: LowerHex,

Returns the digest as a lowercase hexadecimal string.
Source§

fn to_hex_uppercase(&self) -> String
where Self: UpperHex,

Returns the digest as an uppercase hexadecimal string.
Source§

impl Display for Digest

Source§

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

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

impl From<[u8; 64]> for Digest

Source§

fn from(digest: [u8; 64]) -> Self

Converts to this type from the input type.
Source§

impl From<Digest> for [u8; 64]

Source§

fn from(digest: Digest) -> Self

Converts to this type from the input type.
Source§

impl LowerHex for Digest

Source§

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

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

impl PartialEq for Digest

Source§

fn eq(&self, other: &Digest) -> 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 TryFrom<&str> for Digest

Source§

type Error = FormatError

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

fn try_from(digest: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl UpperHex for Digest

Source§

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

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

impl Copy for Digest

Source§

impl Eq for Digest

Source§

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> 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.

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.