pub struct MasterKeys { /* private fields */ }Expand description
Pre-computed master keys for SNMPv3 authentication and privacy.
This struct caches the expensive password-to-key derivation results for
both authentication and privacy passwords. When polling many engines with
shared credentials, create a MasterKeys once and use it with
UsmBuilder to avoid repeating the ~850μs key derivation for each engine.
§Example
use async_snmp::{AuthProtocol, PrivProtocol, MasterKeys};
// Create master keys once (expensive)
let master_keys = MasterKeys::new(AuthProtocol::Sha256, b"authpassword")
.with_privacy(PrivProtocol::Aes128, b"privpassword");
// Use with multiple clients - localization is cheap (~1μs per engine)Implementations§
Source§impl MasterKeys
impl MasterKeys
Sourcepub fn new(auth_protocol: AuthProtocol, auth_password: &[u8]) -> Self
pub fn new(auth_protocol: AuthProtocol, auth_password: &[u8]) -> Self
Create master keys with just authentication.
§Example
use async_snmp::{AuthProtocol, MasterKeys};
let keys = MasterKeys::new(AuthProtocol::Sha256, b"authpassword");Sourcepub fn with_privacy_same_password(self, priv_protocol: PrivProtocol) -> Self
pub fn with_privacy_same_password(self, priv_protocol: PrivProtocol) -> Self
Add privacy with the same password as authentication.
This is the common case where auth and priv passwords are identical. The same master key is reused, avoiding duplicate derivation.
Sourcepub fn with_privacy(
self,
priv_protocol: PrivProtocol,
priv_password: &[u8],
) -> Self
pub fn with_privacy( self, priv_protocol: PrivProtocol, priv_password: &[u8], ) -> Self
Add privacy with a different password than authentication.
Use this when auth and priv passwords differ. A separate master key derivation is performed for the privacy password.
Sourcepub fn auth_master(&self) -> &MasterKey
pub fn auth_master(&self) -> &MasterKey
Get the authentication master key.
Sourcepub fn priv_master(&self) -> Option<&MasterKey>
pub fn priv_master(&self) -> Option<&MasterKey>
Get the privacy master key, if configured.
Returns the separate priv master key if set, otherwise returns the auth master key (for same-password case).
Sourcepub fn priv_protocol(&self) -> Option<PrivProtocol>
pub fn priv_protocol(&self) -> Option<PrivProtocol>
Get the configured privacy protocol.
Sourcepub fn auth_protocol(&self) -> AuthProtocol
pub fn auth_protocol(&self) -> AuthProtocol
Get the authentication protocol.
Sourcepub fn localize(&self, engine_id: &[u8]) -> (LocalizedKey, Option<PrivKey>)
pub fn localize(&self, engine_id: &[u8]) -> (LocalizedKey, Option<PrivKey>)
Derive localized keys for a specific engine ID.
Returns (auth_key, priv_key) where priv_key is None if no privacy was configured.
Key extension is automatically applied when needed based on the auth/priv protocol combination:
- AES-192/256 with SHA-1 or MD5: Blumenthal extension (draft-blumenthal-aes-usm-04)
- 3DES with SHA-1 or MD5: Reeder extension (draft-reeder-snmpv3-usm-3desede-00)
§Example
use async_snmp::{AuthProtocol, MasterKeys, PrivProtocol};
let keys = MasterKeys::new(AuthProtocol::Sha1, b"authpassword")
.with_privacy_same_password(PrivProtocol::Aes256);
let engine_id = [0x80, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04];
// SHA-1 only produces 20 bytes, but AES-256 needs 32.
// Blumenthal extension is automatically applied.
let (auth, priv_key) = keys.localize(&engine_id);Trait Implementations§
Source§impl Clone for MasterKeys
impl Clone for MasterKeys
Source§fn clone(&self) -> MasterKeys
fn clone(&self) -> MasterKeys
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more