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 AttributeFromRaw<'_> for MessageIntegrity
impl AttributeFromRaw<'_> for MessageIntegrity
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 RawAttribute
Source§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 RawAttribute
Source§impl AttributeStaticType for MessageIntegrity
impl AttributeStaticType for MessageIntegrity
Source§const TYPE: AttributeType
const TYPE: AttributeType
The
AttributeType
Source§impl AttributeWrite for MessageIntegrity
impl AttributeWrite for MessageIntegrity
Source§fn to_raw(&self) -> RawAttribute<'_>
fn to_raw(&self) -> RawAttribute<'_>
Produce a
RawAttribute
from this Attribute
Source§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 MessageIntegrity
impl Clone for MessageIntegrity
Source§fn clone(&self) -> MessageIntegrity
fn clone(&self) -> MessageIntegrity
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 MessageIntegrity
impl Debug for MessageIntegrity
Source§impl Display for MessageIntegrity
impl Display for MessageIntegrity
Source§impl PartialEq for MessageIntegrity
impl PartialEq for MessageIntegrity
Source§impl TryFrom<&RawAttribute<'_>> for MessageIntegrity
impl TryFrom<&RawAttribute<'_>> for MessageIntegrity
Source§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<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