stun_rs

Struct HMACKey

source
pub struct HMACKey(/* private fields */);
Expand description

Key used for authentication and message integrity

§Examples:

 // Creates a new long term credential key using MD5 algorithm
 let algorithm = Algorithm::from(AlgorithmId::MD5);
 let key = HMACKey::new_long_term("user", "realm", "pass", algorithm)?;
 assert_eq!(key.credential_mechanism(), CredentialMechanism::LongTerm);

 let expected_hash = [
     0x84, 0x93, 0xFB, 0xC5, 0x3B, 0xA5, 0x82, 0xFB,
     0x4C, 0x04, 0x4C, 0x45, 0x6B, 0xDC, 0x40, 0xEB,
 ];
 assert_eq!(key.as_bytes(), expected_hash);

Implementations§

source§

impl HMACKey

source

pub fn new_short_term<S>(password: S) -> Result<Self, StunError>
where S: AsRef<str>,

Creates a CredentialMechanism::ShortTerm key

§Returns

The new HMACKey used for short term credential mechanism, or a StunError if the password can not be processed using the opaque string profile.

source

pub fn new_long_term<A, B, C, T>( username: A, realm: B, password: C, algorithm: T, ) -> Result<Self, StunError>
where A: AsRef<str>, B: AsRef<str>, C: AsRef<str>, T: AsRef<Algorithm>,

Creates a CredentialMechanism::LongTerm key.

§Arguments:
  • username - The user name
  • realm - The realm.
  • algorithm- Optional value for the algorithm used to generate the key. If algorithm is None, AlgorithmId::MD5 will be used. The resulting key length is 16 bytes when MD5 is used, or 32 bytes if SHA-256 algorithm is used.
§Returns

The new HMACKey used for long term credential mechanism, or a StunError if username, realm or password can not be processed using the opaque string profile.

source

pub fn as_bytes(&self) -> &[u8]

Gets the bytes representation of the key

source

pub fn credential_mechanism(&self) -> CredentialMechanism

Gets the bytes representation of the key

Trait Implementations§

source§

impl Clone for HMACKey

source§

fn clone(&self) -> HMACKey

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for HMACKey

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for HMACKey

source§

fn eq(&self, other: &HMACKey) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for HMACKey

source§

impl StructuralPartialEq for HMACKey

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V