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
impl HMACKey
sourcepub fn new_short_term<S>(password: S) -> Result<Self, StunError>
pub fn new_short_term<S>(password: S) -> Result<Self, StunError>
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.
sourcepub fn new_long_term<A, B, C, T>(
username: A,
realm: B,
password: C,
algorithm: T,
) -> Result<Self, StunError>
pub fn new_long_term<A, B, C, T>( username: A, realm: B, password: C, algorithm: T, ) -> Result<Self, StunError>
Creates a CredentialMechanism::LongTerm
key.
§Arguments:
username
- The user namerealm
- 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 whenMD5
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.
sourcepub fn credential_mechanism(&self) -> CredentialMechanism
pub fn credential_mechanism(&self) -> CredentialMechanism
Gets the bytes representation of the key
Trait Implementations§
impl Eq for HMACKey
impl StructuralPartialEq for HMACKey
Auto Trait Implementations§
impl Freeze for HMACKey
impl RefUnwindSafe for HMACKey
impl !Send for HMACKey
impl !Sync for HMACKey
impl Unpin for HMACKey
impl UnwindSafe for HMACKey
Blanket Implementations§
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)