snmp_parser/lib.rs
1//! [](./LICENSE-MIT)
2//! [](./LICENSE-APACHE)
3//! [](https://travis-ci.org/rusticata/snmp-parser)
4//! [](https://crates.io/crates/snmp-parser)
5//!
6//! # SNMP Parser
7//!
8//! An SNMP parser, implemented with the [nom](https://github.com/Geal/nom)
9//! parser combinator framework.
10//!
11//! It is written in pure Rust, fast, and makes extensive use of zero-copy.
12//! It also aims to be panic-free.
13//!
14//! The goal of this parser is to implement SNMP messages analysis, for example
15//! to use rules from a network IDS.
16//!
17//! To read a message, different functions must be used depending on the expected message
18//! version.
19//! This crate implements the [`asn1_rs::FromBer`] trait, so to parse a message, use the
20//! expected object and call function `from_ber`.
21//!
22//! For example, to parse a SNMP v1 or v2c message (message structure is the same), use
23//! [`SnmpMessage`]`::from_ber(input)`.
24//! To parse a SNMP v3 message, use [`SnmpV3Message`]`::from_ber(input)`.
25//! If you don't know the version of the message and want to parse a generic SNMP message,
26//! use [`SnmpGenericMessage`]`::from_ber(input)`.
27//!
28//! Other methods of parsing (functions) are provided for compatibility:
29//! these functions are [`parse_snmp_v1`](snmp/fn.parse_snmp_v1.html),
30//! [`parse_snmp_v2c`](snmp/fn.parse_snmp_v2c.html) and
31//! [`parse_snmp_v3`](snmpv3/fn.parse_snmp_v3.html).
32//! If you don't know the version of the message and want to parse a generic SNMP message,
33//! use the [`parse_snmp_generic_message`](fn.parse_snmp_generic_message.html) function.
34//!
35//! The code is available on [Github](https://github.com/rusticata/snmp-parser)
36//! and is part of the [Rusticata](https://github.com/rusticata) project.
37
38#![deny(/*missing_docs,*/unsafe_code,
39 unstable_features,
40 unused_import_braces, unused_qualifications)]
41#![warn(
42 missing_debug_implementations,
43 /* missing_docs,
44 rust_2018_idioms,*/
45 unreachable_pub
46)]
47#![forbid(unsafe_code)]
48#![deny(rustdoc::broken_intra_doc_links)]
49#![doc(test(
50 no_crate_inject,
51 attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
52))]
53#![cfg_attr(docsrs, feature(doc_cfg))]
54
55mod generic;
56mod usm;
57
58pub mod error;
59pub mod snmp;
60pub mod snmpv3;
61
62pub use generic::*;
63pub use snmp::*;
64pub use snmpv3::*;
65
66// re-exports to prevent public dependency on asn1_rs
67pub use asn1_rs;
68pub use asn1_rs::{Oid, OidParseError};
69
70#[cfg(test)]
71mod tests {
72 use asn1_rs::FromBer;
73
74 use super::{SnmpGenericMessage, SnmpMessage, SnmpV3Message, SnmpVariable};
75
76 #[allow(dead_code)]
77 fn assert_is_fromber<'a, E, T: FromBer<'a, E>>() {}
78
79 #[test]
80 fn check_traits() {
81 assert_is_fromber::<_, SnmpVariable>();
82 assert_is_fromber::<_, SnmpMessage>();
83 assert_is_fromber::<_, SnmpV3Message>();
84 assert_is_fromber::<_, SnmpGenericMessage>();
85 }
86}