pub struct LocalizedKey { /* private fields */ }Expand description
Localized authentication key.
A key that has been derived from a password and bound to a specific engine ID. This key can be used for HMAC operations on messages to/from that engine.
§Security
Key material is automatically zeroed from memory when the key is dropped,
using the zeroize crate. This provides defense-in-depth against memory
scraping attacks.
Implementations§
Source§impl LocalizedKey
impl LocalizedKey
Sourcepub fn from_password(
protocol: AuthProtocol,
password: &[u8],
engine_id: &[u8],
) -> Self
pub fn from_password( protocol: AuthProtocol, password: &[u8], engine_id: &[u8], ) -> Self
Derive a localized key from a password and engine ID.
This implements the key localization algorithm from RFC 3414 Section A.2:
- Expand password to 1MB by repetition
- Hash the expansion to get the master key
- Hash (master_key || engine_id || master_key) to get the localized key
§Performance Note
This method performs the full key derivation (~850μs for SHA-256). When
polling many engines with shared credentials, use MasterKey to cache
the intermediate result and call MasterKey::localize for each engine.
§Empty and Short Passwords
Empty passwords result in an all-zero key of the appropriate length for
the authentication protocol. This differs from net-snmp, which rejects
passwords shorter than 8 characters with USM_PASSWORDTOOSHORT.
While empty/short passwords are accepted for flexibility, they provide
minimal security. A warning is logged at the WARN level when the
password is shorter than MIN_PASSWORD_LENGTH (8 characters).
Sourcepub fn from_str_password(
protocol: AuthProtocol,
password: &str,
engine_id: &[u8],
) -> Self
pub fn from_str_password( protocol: AuthProtocol, password: &str, engine_id: &[u8], ) -> Self
Derive a localized key from a string password and engine ID.
This is a convenience method that converts the string to bytes and calls
from_password.
Sourcepub fn from_master_key(master: &MasterKey, engine_id: &[u8]) -> Self
pub fn from_master_key(master: &MasterKey, engine_id: &[u8]) -> Self
Create a localized key from a master key and engine ID.
This is the efficient path when you have a cached MasterKey.
Equivalent to calling MasterKey::localize.
Sourcepub fn from_bytes(protocol: AuthProtocol, key: impl Into<Vec<u8>>) -> Self
pub fn from_bytes(protocol: AuthProtocol, key: impl Into<Vec<u8>>) -> Self
Create a localized key from raw bytes.
Use this if you already have a localized key (e.g., from configuration).
Sourcepub fn protocol(&self) -> AuthProtocol
pub fn protocol(&self) -> AuthProtocol
Get the protocol this key is for.
Sourcepub fn compute_hmac(&self, data: &[u8]) -> Vec<u8> ⓘ
pub fn compute_hmac(&self, data: &[u8]) -> Vec<u8> ⓘ
Compute HMAC over a message and return the truncated MAC.
The returned MAC is truncated to the appropriate length for the protocol (12 bytes for MD5/SHA-1, variable for SHA-2).
Sourcepub fn verify_hmac(&self, data: &[u8], expected: &[u8]) -> bool
pub fn verify_hmac(&self, data: &[u8], expected: &[u8]) -> bool
Verify an HMAC.
Returns true if the MAC matches, false otherwise.
Trait Implementations§
Source§impl Clone for LocalizedKey
impl Clone for LocalizedKey
Source§fn clone(&self) -> LocalizedKey
fn clone(&self) -> LocalizedKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LocalizedKey
impl Debug for LocalizedKey
Source§impl Drop for LocalizedKey
impl Drop for LocalizedKey
Auto Trait Implementations§
impl Freeze for LocalizedKey
impl RefUnwindSafe for LocalizedKey
impl Send for LocalizedKey
impl Sync for LocalizedKey
impl Unpin for LocalizedKey
impl UnsafeUnpin for LocalizedKey
impl UnwindSafe for LocalizedKey
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more