[][src]Struct snmp_mp::SnmpMsg

pub struct SnmpMsg {
    pub scoped_pdu_data: ScopedPduData,
    // some fields omitted
}

SNMP message that can be encoded and sent over the network.

The default security model is the User-based Security Model (USM) for version 3 of the Simple Network Management Protocol (SNMPv3).

Examples

use snmp_mp::SnmpMsg;

let mut msg = SnmpMsg::new(1);
msg.set_reportable_flag();

Fields

scoped_pdu_data: ScopedPduData

Implementations

impl SnmpMsg[src]

pub const MSG_ID_MIN: u32[src]

The smallest value that can be used as a message ID.

Examples

assert_eq!(SnmpMsg::MSG_ID_MIN, 0);

pub const MSG_ID_MAX: u32[src]

The largest value that can be used as a message ID.

Examples

assert_eq!(SnmpMsg::MSG_ID_MAX, 2_147_483_647);

pub const MAX_UDP_PACKET_SIZE: usize[src]

The largest UDP packet size for IPv4.

Examples

assert_eq!(SnmpMsg::MAX_UDP_PACKET_SIZE, 65_507);

pub const USER_BASE_SECURITY_MODEL: u32[src]

Security model used for each SnmpMsg.

Examples

assert_eq!(SnmpMsg::USER_BASE_SECURITY_MODEL, 3);

pub fn new(id: u32) -> Self[src]

Constructs a new empty SnmpMsg with the specified ID.

Examples

let msg = SnmpMsg::new(1);

pub fn with_scoped_pdu(id: u32, scoped_pdu: ScopedPdu) -> Self[src]

Constructs a new empty SnmpMsg with the specified ID and scoped PDU.

Examples

let msg = SnmpMsg::with_scoped_pdu(1, ScopedPdu::new(1));

pub fn id(&self) -> u32[src]

Returns the message ID.

The message ID is used to coordinate request messages and responses. It should be generated in a manner that avoids re-use of any outstanding values.

Examples

let msg_id = msg.id();

pub fn set_id(&mut self, id: u32) -> &mut Self[src]

Sets the message ID.

The expected range is is between MSG_ID_MIN and MSG_ID_MAX. The maximum value is not enforced.

Examples

msg.set_id(1234);
assert_eq!(msg.id(), 1234);

pub fn max_size(&self) -> u32[src]

Returns the maximum allowed size supported by the sender of the message when encoded.

The default value is MAX_UDP_PACKET_SIZE.

Examples

let msg = SnmpMsg::new(1);
assert_eq!(msg.max_size(), SnmpMsg::MAX_UDP_PACKET_SIZE as u32);

pub fn set_max_size(&mut self, max_size: u32) -> &Self[src]

Sets the maximum allowed size supported by the sender of the message when encoded.

The default value is MAX_UDP_PACKET_SIZE.

Examples

msg.set_max_size(576);
assert_eq!(msg.max_size(), 576);

pub fn is_reportable(&self) -> bool[src]

Returns true if the message is reportable.

Examples

let mut msg = SnmpMsg::new(1);
msg.set_reportable_flag();
assert!(msg.is_reportable());

pub fn set_reportable_flag(&mut self) -> &mut Self[src]

Sets the reportable flag.

The reportable flag is a secondary aid in determining whether a Report PDU MUST be sent. It is only used in cases where the PDU portion of a message cannot be decoded, due to, for example, an incorrect encryption key.

Examples

let mut msg = SnmpMsg::new(1);
msg.set_reportable_flag();
assert!(msg.is_reportable());

pub fn is_auth(&self) -> bool[src]

Returns true if the message is authenticated.

Examples

let mut msg = SnmpMsg::new(1);
msg.set_auth_flag();
assert!(msg.is_auth());

pub fn set_auth_flag(&mut self) -> &mut Self[src]

Sets the authentication flag.

The security model must identify the security name on whose behalf the SNMP message was generated whether or no the authentication flag is set.

Examples

let mut msg = SnmpMsg::new(1);
msg.set_auth_flag();
assert!(msg.is_auth());

pub fn security_model(&self) -> u32[src]

Returns the security model used by the sender.

The default value is USER_BASE_SECURITY_MODEL.

Examples

let msg = SnmpMsg::new(1);
assert_eq!(msg.security_model(), SnmpMsg::USER_BASE_SECURITY_MODEL);

pub fn set_security_model(&mut self, security_model: u32) -> &Self[src]

Sets the security model used by the sender.

The default value is USER_BASE_SECURITY_MODEL. The expected value range is between 1 and 2_147_483_647.

Examples

let mut msg = SnmpMsg::new(1);
msg.set_security_model(1);
assert_eq!(msg.security_model(), 1);

pub fn security_params(&self) -> &[u8][src]

Returns the security parameters.

The security parameters are exclusively used by the security model.

Examples

let security_params = msg.security_params();

pub fn set_security_params(&mut self, params: &[u8])[src]

Sets the security parameters.

Examples

let mut msg = SnmpMsg::new(1);
let security_params = msg.set_security_params(b"security_params");
assert_eq!(msg.security_params(), b"security_params");

pub fn is_private(&self) -> bool[src]

Returns true if the message is private.

Examples

let mut msg = SnmpMsg::new(1);
msg.set_encrypted_scoped_pdu(encrypted_scoped_pdu);
assert!(msg.is_private());

pub fn set_privacy_flag(&mut self) -> &Self[src]

Sets the privacy flag.

This flag has to be set if the encrypted scoped PDU is directly assigned (see set_encrypted_scoped_pdu).

Examples

let mut msg = SnmpMsg::new(1);
let security_params = msg.set_privacy_flag();
assert!(msg.is_private());

pub fn set_encrypted_scoped_pdu(&mut self, encrypted_scoped_pdu: Vec<u8>)[src]

Sets the encrypted scoped PDU and the privacy flag.

It consumes the encrypted scoped PDU.

Examples

let mut msg = SnmpMsg::new(1);
msg.set_encrypted_scoped_pdu(encrypted_scoped_pdu.clone());
assert!(msg.is_private());
assert_eq!(msg.scoped_pdu_data.encrypted().unwrap(), &encrypted_scoped_pdu[..]);

pub fn encrypt_scoped_pdu<F>(&mut self, encrypt: F) where
    F: FnOnce(Vec<u8>) -> Vec<u8>, 
[src]

Encrypts the scoped PDU of the message.

It takes a closure that accepts an encoded scoped PDU and returns an encrypted scoped PDU. If the message's scoped PDU is already encrypted this function does nothing.

Examples

let mut msg = SnmpMsg::new(1);
msg.encrypt_scoped_pdu(|scoped_pdu| {
    // Use the security model to encrypt the scoped PDU. Ex.:
    // `let encrypted_scoped_pdu = priv_key.encrypt(scoped_pdu, &security_params, salt);`
    // Return the encrypted scoped PDU.
    encrypted_scoped_pdu
});

pub fn decrypt_scoped_pdu<F>(
    &mut self,
    decrypt: F
) -> Result<&ScopedPdu, MsgProcessingError> where
    F: FnOnce(Vec<u8>) -> Option<Vec<u8>>, 
[src]

Decrypts the encrypted scoped PDU of the message.

It takes a closure that accepts an encrypted scoped PDU and returns an encoded scoped PDU. If the message's scoped PDU is already decrypted this function does nothing and returns a reference to the scoped PDU.

Examples

let mut msg = SnmpMsg::new(1);
msg.decrypt_scoped_pdu(|encrypted_scoped_pdu| {
    // Use the security model to decrypt the scoped PDU. Ex.:
    // `let scoped_pdu = priv_key.decrypt(encrypted_scoped_pdu, &security_params);`
    // Return the decrypted scoped PDU.
    scoped_pdu
});

pub fn encode(&self) -> Vec<u8>[src]

Encodes an outgoing message.

Examples

let msg = SnmpMsg::new(1);
let encoded_msg = msg.encode();

pub fn decode(buf: &[u8]) -> MsgProcessingResult<Self>[src]

Decodes an incoming message.

Errors

When a value field in a variable binding is invalid a result with BadValue error is returned.

If the version of the message is not 3 a result with BadVersion error is returned.

When the message is not properly formed a result with MalformedMsg error is returned.

Examples

let msg = SnmpMsg::decode(&encoded_msg)?;

Trait Implementations

impl Clone for SnmpMsg[src]

impl Debug for SnmpMsg[src]

impl Default for SnmpMsg[src]

impl Eq for SnmpMsg[src]

impl Hash for SnmpMsg[src]

impl PartialEq<SnmpMsg> for SnmpMsg[src]

impl StructuralEq for SnmpMsg[src]

impl StructuralPartialEq for SnmpMsg[src]

Auto Trait Implementations

impl RefUnwindSafe for SnmpMsg

impl Send for SnmpMsg

impl Sync for SnmpMsg

impl Unpin for SnmpMsg

impl UnwindSafe for SnmpMsg

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.