Trait snmp_usm::PrivKey

source ·
pub trait PrivKey {
    type Salt;

    // Required methods
    fn encrypt(
        &self,
        scoped_pdu: Vec<u8>,
        security_params: &SecurityParams,
        salt: Self::Salt
    ) -> (Vec<u8>, Vec<u8>);
    fn decrypt(
        &self,
        encrypted_scoped_pdu: Vec<u8>,
        security_params: &SecurityParams
    ) -> SecurityResult<Vec<u8>>;
}
Expand description

A trait for privacy keys.

Privacy keys are used to encrypt scoped PDUs.

Required Associated Types§

source

type Salt

The type of the “salt” used for encryption.

Required Methods§

source

fn encrypt( &self, scoped_pdu: Vec<u8>, security_params: &SecurityParams, salt: Self::Salt ) -> (Vec<u8>, Vec<u8>)

Encrypts a scoped PDU in place.

It returns the encrypted scoped PDU and the “salt” that was used for the encryption. This “salt” must be placed in the privacy parameters to enable the receiving entity to compute the correct IV and to decrypt the scoped PDU.

Arguments
  • scoped_pdu - The encoded scoped PDU
  • security_params - Security parameters related to the scoped PDU to encrypt
  • salt - “Salt” integer that as to be modified after being used to encrypt a message. How exactly the value of the “salt” (and thus of the IV) varies, is an implementation issue, as long as the measures are taken to avoid producing a duplicate IV
Examples
use snmp_usm::{Aes128PrivKey, PrivKey, WithLocalizedKey};

let priv_key = Aes128PrivKey::with_localized_key(localized_key);
let (encrypted_scoped_pdu, salt) = priv_key.encrypt(scoped_pdu, &security_params, 0);
source

fn decrypt( &self, encrypted_scoped_pdu: Vec<u8>, security_params: &SecurityParams ) -> SecurityResult<Vec<u8>>

Decrypts an encrypted scoped PDU in place.

Arguments
  • encrypted_scoped_pdu - The encrypted scoped PDU
  • security_params - Security parameters related to the scoped PDU to decrypt
Errors

If the decryption failed a result with DecryptError error is returned.

Examples
use snmp_usm::{DesPrivKey, PrivKey, WithLocalizedKey};

let priv_key = DesPrivKey::with_localized_key(localized_key);
let decrypted_scoped_pdu = priv_key.decrypt(encrypted_scoped_pdu, &security_params)?;

Implementors§

source§

impl<'a, D> PrivKey for Aes128PrivKey<'a, D>

§

type Salt = u64

source§

impl<'a, D> PrivKey for DesPrivKey<'a, D>

§

type Salt = u32