/rust/registry/src/index.crates.io-1949cf8c6b5b557f/snmp-parser-0.10.0/src/usm.rs
Line | Count | Source |
1 | | //! RFC2274 - User-based Security Model (USM) for version 3 of the Simple Network Management Protocol (SNMPv3) |
2 | | |
3 | | use crate::parse_ber_octetstring_as_str; |
4 | | use asn1_rs::{Error, FromBer, Sequence}; |
5 | | use nom::IResult; |
6 | | |
7 | | #[derive(Debug, PartialEq)] |
8 | | pub struct UsmSecurityParameters<'a> { |
9 | | pub msg_authoritative_engine_id: &'a [u8], |
10 | | pub msg_authoritative_engine_boots: u32, |
11 | | pub msg_authoritative_engine_time: u32, |
12 | | pub msg_user_name: String, |
13 | | pub msg_authentication_parameters: &'a [u8], |
14 | | pub msg_privacy_parameters: &'a [u8], |
15 | | } |
16 | | |
17 | 61.2k | pub fn parse_usm_security_parameters(bytes: &[u8]) -> IResult<&[u8], UsmSecurityParameters, Error> { |
18 | 61.2k | Sequence::from_der_and_then(bytes, |i| { |
19 | 60.1k | let (i, msg_authoritative_engine_id) = <&[u8]>::from_ber(i)?; |
20 | 60.0k | let (i, msg_authoritative_engine_boots) = u32::from_ber(i)?; |
21 | 54.2k | let (i, msg_authoritative_engine_time) = u32::from_ber(i)?; |
22 | 53.5k | let (i, msg_user_name) = parse_ber_octetstring_as_str(i)?; |
23 | 50.7k | let (i, msg_authentication_parameters) = <&[u8]>::from_ber(i)?; |
24 | 50.1k | let (i, msg_privacy_parameters) = <&[u8]>::from_ber(i)?; |
25 | 49.3k | let usm = UsmSecurityParameters { |
26 | 49.3k | msg_authoritative_engine_id, |
27 | 49.3k | msg_authoritative_engine_boots, |
28 | 49.3k | msg_authoritative_engine_time, |
29 | 49.3k | msg_user_name: msg_user_name.to_string(), |
30 | 49.3k | msg_authentication_parameters, |
31 | 49.3k | msg_privacy_parameters, |
32 | 49.3k | }; |
33 | 49.3k | Ok((i, usm)) |
34 | 60.1k | }) |
35 | 61.2k | } |