Struct stun_types::attribute::MessageIntegrity
source · pub struct MessageIntegrity { /* private fields */ }Expand description
The MessageIntegrity Attribute
Implementations§
source§impl MessageIntegrity
impl MessageIntegrity
sourcepub fn hmac(&self) -> &[u8; 20]
pub fn hmac(&self) -> &[u8; 20]
Retrieve the value of the hmac
§Examples
let hmac = [0; 20];
let integrity = MessageIntegrity::new(hmac);
assert_eq!(integrity.hmac(), &hmac);sourcepub fn compute(data: &[u8], key: &[u8]) -> Result<[u8; 20], StunWriteError>
pub fn compute(data: &[u8], key: &[u8]) -> Result<[u8; 20], StunWriteError>
Compute the Message Integrity value of a chunk of data using a key
Note: use MessageIntegrity::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 = [209, 217, 210, 15, 124, 78, 87, 181, 211, 233, 165, 180, 44, 142, 81, 233, 138, 186, 184, 97];
let integrity = MessageIntegrity::compute(&data, &key).unwrap();
assert_eq!(integrity, expected);sourcepub fn verify(
data: &[u8],
key: &[u8],
expected: &[u8; 20],
) -> Result<(), StunParseError>
pub fn verify( data: &[u8], key: &[u8], expected: &[u8; 20], ) -> 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 = [209, 217, 210, 15, 124, 78, 87, 181, 211, 233, 165, 180, 44, 142, 81, 233, 138, 186, 184, 97];
assert_eq!(MessageIntegrity::verify(&data, &key, &expected).unwrap(), ());Trait Implementations§
source§impl Attribute for MessageIntegrity
impl Attribute for MessageIntegrity
source§impl Clone for MessageIntegrity
impl Clone for MessageIntegrity
source§fn clone(&self) -> MessageIntegrity
fn clone(&self) -> MessageIntegrity
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 MessageIntegrity
impl Debug for MessageIntegrity
source§impl Display for MessageIntegrity
impl Display for MessageIntegrity
source§impl<'a> From<&'a MessageIntegrity> for RawAttribute<'a>
impl<'a> From<&'a MessageIntegrity> for RawAttribute<'a>
source§fn from(value: &'a MessageIntegrity) -> RawAttribute<'a>
fn from(value: &'a MessageIntegrity) -> RawAttribute<'a>
Converts to this type from the input type.
source§impl PartialEq for MessageIntegrity
impl PartialEq for MessageIntegrity
source§fn eq(&self, other: &MessageIntegrity) -> bool
fn eq(&self, other: &MessageIntegrity) -> bool
This method tests for
self and other values to be equal, and is used
by ==.source§impl<'a> TryFrom<&RawAttribute<'a>> for MessageIntegrity
impl<'a> TryFrom<&RawAttribute<'a>> for MessageIntegrity
§type Error = StunParseError
type Error = StunParseError
The type returned in the event of a conversion error.
impl Eq for MessageIntegrity
impl StructuralPartialEq for MessageIntegrity
Auto Trait Implementations§
impl Freeze for MessageIntegrity
impl RefUnwindSafe for MessageIntegrity
impl Send for MessageIntegrity
impl Sync for MessageIntegrity
impl Unpin for MessageIntegrity
impl UnwindSafe for MessageIntegrity
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)