async_snmp/lib.rs
1// Allow large error types - the Error enum includes OIDs inline for debugging convenience.
2// Boxing them would add complexity and allocations for a marginal size reduction.
3#![allow(clippy::result_large_err)]
4
5//! # async-snmp
6//!
7//! Modern, async-first SNMP client library for Rust.
8//!
9//! ## Features
10//!
11//! - Full SNMPv1, v2c, and v3 support
12//! - Async-first API built on Tokio
13//! - Zero-copy BER encoding/decoding
14//! - Type-safe OID and value handling
15//! - Config-driven client construction
16//!
17//! ## Quick Start
18//!
19//! ```rust,no_run
20//! use async_snmp::{Auth, Client, oid};
21//! use std::time::Duration;
22//!
23//! #[tokio::main]
24//! async fn main() -> Result<(), async_snmp::Error> {
25//! // SNMPv2c client
26//! let client = Client::builder("192.168.1.1:161", Auth::v2c("public"))
27//! .timeout(Duration::from_secs(5))
28//! .connect()
29//! .await?;
30//!
31//! let result = client.get(&oid!(1, 3, 6, 1, 2, 1, 1, 1, 0)).await?;
32//! println!("sysDescr: {:?}", result.value);
33//!
34//! Ok(())
35//! }
36//! ```
37//!
38//! ## SNMPv3 Example
39//!
40//! ```rust,no_run
41//! use async_snmp::{Auth, Client, oid, v3::{AuthProtocol, PrivProtocol}};
42//!
43//! #[tokio::main]
44//! async fn main() -> Result<(), async_snmp::Error> {
45//! let client = Client::builder("192.168.1.1:161",
46//! Auth::usm("admin")
47//! .auth(AuthProtocol::Sha256, "authpass123")
48//! .privacy(PrivProtocol::Aes128, "privpass123"))
49//! .connect()
50//! .await?;
51//!
52//! let result = client.get(&oid!(1, 3, 6, 1, 2, 1, 1, 1, 0)).await?;
53//! println!("sysDescr: {:?}", result.value);
54//!
55//! Ok(())
56//! }
57//! ```
58
59pub mod agent;
60pub mod ber;
61pub mod client;
62pub mod error;
63pub mod format;
64pub mod handler;
65pub mod message;
66pub mod notification;
67pub mod oid;
68pub mod pdu;
69pub mod prelude;
70pub mod transport;
71pub mod v3;
72pub mod value;
73pub mod varbind;
74pub mod version;
75
76pub(crate) mod util;
77
78#[cfg(feature = "cli")]
79pub mod cli;
80
81// Re-exports for convenience
82pub use agent::{Agent, AgentBuilder, VacmBuilder, VacmConfig, View};
83pub use client::{
84 Auth, BulkWalk, Client, ClientBuilder, ClientConfig, CommunityVersion, OidOrdering, UsmAuth,
85 UsmBuilder, V3SecurityConfig, Walk, WalkMode, WalkStream,
86};
87pub use error::{
88 AuthErrorKind, CryptoErrorKind, DecodeErrorKind, EncodeErrorKind, Error, ErrorStatus,
89 OidErrorKind, Result,
90};
91pub use handler::{
92 BoxFuture, GetNextResult, GetResult, MibHandler, OidTable, RequestContext, Response,
93 SecurityModel, SetResult,
94};
95pub use message::SecurityLevel;
96pub use notification::{
97 Notification, NotificationReceiver, NotificationReceiverBuilder, UsmUserConfig,
98 validate_notification_varbinds,
99};
100pub use oid::Oid;
101pub use pdu::{GenericTrap, Pdu, PduType, TrapV1Pdu};
102pub use transport::{SharedUdpHandle, SharedUdpTransport, TcpTransport, Transport, UdpTransport};
103pub use v3::{
104 AuthProtocol, EngineCache, LocalizedKey, MasterKey, MasterKeys, ParseProtocolError,
105 PrivProtocol,
106};
107pub use value::Value;
108pub use varbind::VarBind;
109pub use version::Version;
110
111/// Type alias for a client using the shared UDP transport.
112///
113/// This is useful for high-throughput scenarios where many clients share
114/// a single UDP socket via [`SharedUdpTransport`].
115pub type SharedClient = Client<SharedUdpHandle>;
116
117/// Type alias for a client using a dedicated UDP socket.
118///
119/// This is the default transport type, suitable for most use cases
120/// with up to ~100 concurrent targets.
121pub type UdpClient = Client<UdpTransport>;
122
123/// Type alias for a client using a TCP connection.
124pub type TcpClient = Client<TcpTransport>;
125
126/// Testing utilities exposed via the `testing` feature.
127#[cfg(feature = "testing")]
128pub mod testing {
129 pub use crate::format::hex::{Bytes as HexBytes, DecodeError, decode, encode};
130}