pub struct MessageIntegritySha256 { /* private fields */ }Expand description
The MessageIntegritySha256 Attribute
Implementations§
Source§impl MessageIntegritySha256
impl MessageIntegritySha256
Sourcepub fn new(hmac: &[u8]) -> Result<Self, StunWriteError>
pub fn new(hmac: &[u8]) -> Result<Self, StunWriteError>
Sourcepub fn hmac(&self) -> &[u8] ⓘ
pub fn hmac(&self) -> &[u8] ⓘ
Retrieve the value of the hmac
§Examples
let hmac = [0; 20];
let integrity = MessageIntegritySha256::new(&hmac).unwrap();
assert_eq!(integrity.hmac(), &hmac);Sourcepub fn compute(data: &[u8], key: &[u8]) -> Result<[u8; 32], StunWriteError>
pub fn compute(data: &[u8], key: &[u8]) -> Result<[u8; 32], StunWriteError>
Compute the Message Integrity value of a chunk of data using a key
Note: use MessageIntegritySha256::verify for the actual verification to ensure constant time
checks of the values to defeat certain types of timing attacks.
§Examples
let key = [40; 10];
let data = [10; 30];
let expected = [141, 112, 214, 41, 247, 110, 61, 95, 46, 245, 132, 79, 99, 16, 167, 95, 239, 168, 3, 63, 101, 78, 150, 24, 241, 139, 34, 229, 189, 37, 14, 113];
let integrity = MessageIntegritySha256::compute(&data, &key).unwrap();
assert_eq!(integrity, expected);Sourcepub fn verify(
data: &[u8],
key: &[u8],
expected: &[u8],
) -> Result<(), StunParseError>
pub fn verify( data: &[u8], key: &[u8], expected: &[u8], ) -> Result<(), StunParseError>
Compute the Message Integrity value of a chunk of data using a key
§Examples
let key = [40; 10];
let data = [10; 30];
let expected = [141, 112, 214, 41, 247, 110, 61, 95, 46, 245, 132, 79, 99, 16, 167, 95, 239, 168, 3, 63, 101, 78, 150, 24, 241, 139, 34, 229, 189, 37, 14, 113];
assert_eq!(MessageIntegritySha256::verify(&data, &key, &expected).unwrap(), ());Trait Implementations§
Source§impl Attribute for MessageIntegritySha256
impl Attribute for MessageIntegritySha256
Source§impl AttributeFromRaw<'_> for MessageIntegritySha256
impl AttributeFromRaw<'_> for MessageIntegritySha256
Source§fn from_raw_ref(raw: &RawAttribute<'_>) -> Result<Self, StunParseError>where
Self: Sized,
fn from_raw_ref(raw: &RawAttribute<'_>) -> Result<Self, StunParseError>where
Self: Sized,
Produce an
Attribute from a RawAttributeSource§fn from_raw(raw: RawAttribute<'a>) -> Result<Self, StunParseError>where
Self: Sized,
fn from_raw(raw: RawAttribute<'a>) -> Result<Self, StunParseError>where
Self: Sized,
Produce an
Attribute from a RawAttributeSource§impl AttributeStaticType for MessageIntegritySha256
impl AttributeStaticType for MessageIntegritySha256
Source§const TYPE: AttributeType
const TYPE: AttributeType
The
AttributeTypeSource§impl AttributeWrite for MessageIntegritySha256
impl AttributeWrite for MessageIntegritySha256
Source§fn to_raw(&self) -> RawAttribute<'_>
fn to_raw(&self) -> RawAttribute<'_>
Produce a
RawAttribute from this AttributeSource§fn write_into_unchecked(&self, dest: &mut [u8])
fn write_into_unchecked(&self, dest: &mut [u8])
Write attribute to the provided destination buffer. Read more
Source§impl Clone for MessageIntegritySha256
impl Clone for MessageIntegritySha256
Source§fn clone(&self) -> MessageIntegritySha256
fn clone(&self) -> MessageIntegritySha256
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 MessageIntegritySha256
impl Debug for MessageIntegritySha256
Source§impl Display for MessageIntegritySha256
impl Display for MessageIntegritySha256
Source§impl PartialEq for MessageIntegritySha256
impl PartialEq for MessageIntegritySha256
Source§impl TryFrom<&RawAttribute<'_>> for MessageIntegritySha256
impl TryFrom<&RawAttribute<'_>> for MessageIntegritySha256
Source§type Error = StunParseError
type Error = StunParseError
The type returned in the event of a conversion error.
impl Eq for MessageIntegritySha256
impl StructuralPartialEq for MessageIntegritySha256
Auto Trait Implementations§
impl Freeze for MessageIntegritySha256
impl RefUnwindSafe for MessageIntegritySha256
impl Send for MessageIntegritySha256
impl Sync for MessageIntegritySha256
impl Unpin for MessageIntegritySha256
impl UnwindSafe for MessageIntegritySha256
Blanket Implementations§
Source§impl<A> AttributeExt for A
impl<A> AttributeExt for A
Source§impl<A> AttributeWriteExt for Awhere
A: AttributeWrite + ?Sized,
impl<A> AttributeWriteExt for Awhere
A: AttributeWrite + ?Sized,
Source§fn write_header(&self, dest: &mut [u8]) -> Result<usize, StunWriteError>
fn write_header(&self, dest: &mut [u8]) -> Result<usize, StunWriteError>
Write the 4 byte attribute header into the provided destination buffer returning the
number of bytes written, or an error.
Source§fn write_header_unchecked(&self, dest: &mut [u8]) -> usize
fn write_header_unchecked(&self, dest: &mut [u8]) -> usize
Write the 4 byte attribute header into the provided destination buffer returning the
number of bytes written. Read more
Source§fn write_into(&self, dest: &mut [u8]) -> Result<usize, StunWriteError>
fn write_into(&self, dest: &mut [u8]) -> Result<usize, StunWriteError>
Write this attribute into the provided destination buffer returning the number of bytes
written, or an error.
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