Struct stun_types::attribute::MessageIntegritySha256
source · 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 Clone for MessageIntegritySha256
impl Clone for MessageIntegritySha256
source§fn clone(&self) -> MessageIntegritySha256
fn clone(&self) -> MessageIntegritySha256
Returns a copy 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<'a> From<&'a MessageIntegritySha256> for RawAttribute<'a>
impl<'a> From<&'a MessageIntegritySha256> for RawAttribute<'a>
source§fn from(value: &'a MessageIntegritySha256) -> RawAttribute<'a>
fn from(value: &'a MessageIntegritySha256) -> RawAttribute<'a>
Converts to this type from the input type.
source§impl PartialEq for MessageIntegritySha256
impl PartialEq for MessageIntegritySha256
source§fn eq(&self, other: &MessageIntegritySha256) -> bool
fn eq(&self, other: &MessageIntegritySha256) -> bool
This method tests for
self and other values to be equal, and is used
by ==.source§impl<'a> TryFrom<&RawAttribute<'a>> for MessageIntegritySha256
impl<'a> TryFrom<&RawAttribute<'a>> for MessageIntegritySha256
§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<E, T> AttributeFromRaw<E> for T
impl<E, T> AttributeFromRaw<E> for T
source§fn from_raw(raw: &RawAttribute<'_>) -> Result<T, E>
fn from_raw(raw: &RawAttribute<'_>) -> Result<T, E>
Convert an
Attribute from a RawAttributesource§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§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)