MasterKeys

Struct MasterKeys 

Source
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

Source

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");
Source

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.

Source

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.

Source

pub fn auth_master(&self) -> &MasterKey

Get the authentication master key.

Source

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).

Source

pub fn priv_protocol(&self) -> Option<PrivProtocol>

Get the configured privacy protocol.

Source

pub fn auth_protocol(&self) -> AuthProtocol

Get the authentication protocol.

Source

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

Source§

fn clone(&self) -> MasterKeys

Returns a duplicate 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 MasterKeys

Source§

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

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

impl Drop for MasterKeys

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Zeroize for MasterKeys

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.

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, dest: *mut u8)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more