pub struct Sha256Digest(/* private fields */);Expand description
Represents a SHA-256 digest, which is a fixed-size array of 32 bytes.
For example, you can obtain the certificate digest with Certificate::hash.
Implementations§
Source§impl Sha256Digest
impl Sha256Digest
Sourcepub fn new(bytes: [u8; 32]) -> Self
pub fn new(bytes: [u8; 32]) -> Self
Creates a new instance from a given array of 32 bytes.
§Examples
use wtransport::tls::Sha256Digest;
// Create a new SHA-256 digest instance.
let digest = Sha256Digest::new([97; 32]);Sourcepub fn from_str_fmt<S>(
s: S,
fmt: Sha256DigestFmt,
) -> Result<Self, InvalidDigest>
pub fn from_str_fmt<S>( s: S, fmt: Sha256DigestFmt, ) -> Result<Self, InvalidDigest>
Attempts to create a new instance from a string representation.
This method parses the string representation of the digest according to the provided
format (fmt) and constructs a new Sha256Digest instance if the parsing is successful.
§Examples
use wtransport::tls::Sha256Digest;
use wtransport::tls::Sha256DigestFmt;
const HASH_ARRAY: &str = "[234, 204, 110, 153, 82, 177, 87, 232, 180, 125, \
234, 158, 66, 129, 212, 250, 217, 48, 47, 32, 83, \
133, 23, 44, 79, 198, 70, 118, 25, 153, 146, 142]";
let digest_bytes_array = Sha256Digest::from_str_fmt(HASH_ARRAY, Sha256DigestFmt::BytesArray);
assert!(digest_bytes_array.is_ok());
const HASH_HEX: &str = "e3:4e:c7:de:b8:da:2d:b8:3c:86:a0:11:76:40:75:b3:\
b9:ba:9d:00:e0:04:b3:38:72:cd:a1:af:4e:e3:11:26";
let digest_dotted_hex = Sha256Digest::from_str_fmt(HASH_HEX, Sha256DigestFmt::DottedHex);
assert!(digest_dotted_hex.is_ok());
let invalid_digest = Sha256Digest::from_str_fmt("invalid_digest", Sha256DigestFmt::BytesArray);
assert!(invalid_digest.is_err());Sourcepub fn fmt(&self, fmt: Sha256DigestFmt) -> String
pub fn fmt(&self, fmt: Sha256DigestFmt) -> String
Formats the digest into a human-readable representation based on the specified format.
§Examples
use wtransport::tls::Sha256Digest;
use wtransport::tls::Sha256DigestFmt;
let digest = Sha256Digest::new([
97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115,
116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 64,
]);
// Represent the digest as a byte array string.
let bytes_array_fmt = digest.fmt(Sha256DigestFmt::BytesArray);
assert_eq!(
bytes_array_fmt,
"[97, 98, 99, 100, 101, 102, 103, 104, 105, 106, \
107, 108, 109, 110, 111, 112, 113, 114, 115, 116, \
117, 118, 119, 120, 121, 122, 123, 124, 125, 126, \
127, 64]"
);
// Represent the digest as a dotted hexadecimal string.
let dotted_hex_fmt = digest.fmt(Sha256DigestFmt::DottedHex);
assert_eq!(
dotted_hex_fmt,
"61:62:63:64:65:66:67:68:69:6a:6b:6c:6d:6e:6f:70:\
71:72:73:74:75:76:77:78:79:7a:7b:7c:7d:7e:7f:40"
);Trait Implementations§
Source§impl Clone for Sha256Digest
impl Clone for Sha256Digest
Source§fn clone(&self) -> Sha256Digest
fn clone(&self) -> Sha256Digest
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 Sha256Digest
impl Debug for Sha256Digest
Source§impl Display for Sha256Digest
impl Display for Sha256Digest
Source§impl FromIterator<Sha256Digest> for ServerHashVerification
impl FromIterator<Sha256Digest> for ServerHashVerification
Source§fn from_iter<T: IntoIterator<Item = Sha256Digest>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = Sha256Digest>>(iter: T) -> Self
Creates a value from an iterator. Read more
Source§impl FromStr for Sha256Digest
impl FromStr for Sha256Digest
Source§impl Hash for Sha256Digest
impl Hash for Sha256Digest
Source§impl Ord for Sha256Digest
impl Ord for Sha256Digest
Source§fn cmp(&self, other: &Sha256Digest) -> Ordering
fn cmp(&self, other: &Sha256Digest) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for Sha256Digest
impl PartialEq for Sha256Digest
Source§impl PartialOrd for Sha256Digest
impl PartialOrd for Sha256Digest
impl Eq for Sha256Digest
impl StructuralPartialEq for Sha256Digest
Auto Trait Implementations§
impl Freeze for Sha256Digest
impl RefUnwindSafe for Sha256Digest
impl Send for Sha256Digest
impl Sync for Sha256Digest
impl Unpin for Sha256Digest
impl UnwindSafe for Sha256Digest
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<S> IntoConnectOptions for Swhere
S: ToString,
impl<S> IntoConnectOptions for Swhere
S: ToString,
Source§fn into_options(self) -> ConnectOptions
fn into_options(self) -> ConnectOptions
Perform value-to-value conversion into
ConnectOptions.