#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum AuthErrorKind {
NoCredentials,
NoAuthKey,
HmacMismatch,
AuthParamsNotFound,
}
impl std::fmt::Display for AuthErrorKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::NoCredentials => write!(f, "no credentials configured"),
Self::NoAuthKey => write!(f, "no authentication key available"),
Self::HmacMismatch => write!(f, "HMAC verification failed"),
Self::AuthParamsNotFound => write!(f, "could not locate auth params in message"),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum CryptoErrorKind {
NoPrivKey,
}
impl std::fmt::Display for CryptoErrorKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::NoPrivKey => write!(f, "no privacy key available"),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum DecodeErrorKind {
UnexpectedTag { expected: u8, actual: u8 },
TruncatedData,
InvalidLength,
IndefiniteLength,
IntegerOverflow,
ZeroLengthInteger,
UnknownVersion(i32),
UnknownPduType(u8),
ConstructedOctetString,
MissingPdu,
InvalidMsgFlags,
UnknownSecurityModel(i32),
MsgMaxSizeTooSmall { value: i32, minimum: i32 },
MsgMaxSizeTooLarge { value: i32 },
InvalidMsgId { value: i32 },
InvalidEngineBoots { value: i32 },
InvalidEngineTime { value: i32 },
InvalidNull,
UnexpectedEncryption,
#[cfg(feature = "agent")]
ExpectedEncryption,
InvalidIpAddressLength { length: usize },
LengthTooLong { octets: usize },
LengthExceedsMax { length: usize, max: usize },
Integer64TooLong { length: usize },
EmptyResponse,
TlvOverflow,
InsufficientData { needed: usize, available: usize },
InvalidOid,
NegativeNonRepeaters { value: i32 },
NegativeMaxRepetitions { value: i32 },
OidTooLong { count: usize, max: usize },
IntegerTooLong { length: usize },
Unsigned32TooLong { length: usize },
Integer64MissingLeadingZero,
Unsigned32MissingLeadingZero,
}
impl std::fmt::Display for DecodeErrorKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::UnexpectedTag { expected, actual } => {
write!(f, "expected tag 0x{:02X}, got 0x{:02X}", expected, actual)
}
Self::TruncatedData => write!(f, "unexpected end of data"),
Self::InvalidLength => write!(f, "invalid length encoding"),
Self::IndefiniteLength => write!(f, "indefinite length encoding not supported"),
Self::IntegerOverflow => write!(f, "integer overflow"),
Self::ZeroLengthInteger => write!(f, "zero-length integer"),
Self::UnknownVersion(v) => write!(f, "unknown SNMP version: {}", v),
Self::UnknownPduType(t) => write!(f, "unknown PDU type: 0x{:02X}", t),
Self::ConstructedOctetString => {
write!(f, "constructed OCTET STRING (0x24) not supported")
}
Self::MissingPdu => write!(f, "missing PDU in message"),
Self::InvalidMsgFlags => write!(f, "invalid msgFlags: privacy without authentication"),
Self::UnknownSecurityModel(m) => write!(f, "unknown security model: {}", m),
Self::MsgMaxSizeTooSmall { value, minimum } => {
write!(f, "msgMaxSize {} below RFC 3412 minimum {}", value, minimum)
}
Self::MsgMaxSizeTooLarge { value } => {
write!(f, "msgMaxSize {} above RFC 3412 maximum 2147483647", value)
}
Self::InvalidMsgId { value } => {
write!(f, "msgID {} outside RFC 3412 range 0..2147483647", value)
}
Self::InvalidEngineBoots { value } => {
write!(
f,
"msgAuthoritativeEngineBoots {} outside RFC 3414 range 0..2147483647",
value
)
}
Self::InvalidEngineTime { value } => {
write!(
f,
"msgAuthoritativeEngineTime {} outside RFC 3414 range 0..2147483647",
value
)
}
Self::InvalidNull => write!(f, "NULL with non-zero length"),
Self::UnexpectedEncryption => write!(f, "expected plaintext scoped PDU"),
#[cfg(feature = "agent")]
Self::ExpectedEncryption => write!(f, "expected encrypted scoped PDU"),
Self::InvalidIpAddressLength { length } => {
write!(f, "IP address must be 4 bytes, got {}", length)
}
Self::LengthTooLong { octets } => {
write!(f, "length encoding too long ({} octets)", octets)
}
Self::LengthExceedsMax { length, max } => {
write!(f, "length {} exceeds maximum {}", length, max)
}
Self::Integer64TooLong { length } => {
write!(f, "integer64 too long: {} bytes", length)
}
Self::EmptyResponse => write!(f, "empty response"),
Self::TlvOverflow => write!(f, "TLV extends past end of data"),
Self::InsufficientData { needed, available } => {
write!(f, "need {} bytes but only {} remaining", needed, available)
}
Self::InvalidOid => write!(f, "invalid OID in notification varbinds"),
Self::NegativeNonRepeaters { value } => {
write!(f, "negative non_repeaters: {}", value)
}
Self::NegativeMaxRepetitions { value } => {
write!(f, "negative max_repetitions: {}", value)
}
Self::OidTooLong { count, max } => {
write!(f, "OID has {} arcs, exceeds maximum {}", count, max)
}
Self::IntegerTooLong { length } => {
write!(f, "integer encoding too long: {} bytes (max 8)", length)
}
Self::Unsigned32TooLong { length } => {
write!(f, "unsigned32 encoding too long: {} bytes (max 9)", length)
}
Self::Integer64MissingLeadingZero => {
write!(f, "9-octet integer64 missing required leading zero byte")
}
Self::Unsigned32MissingLeadingZero => {
write!(f, "5-octet unsigned32 missing required leading zero byte")
}
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum EncodeErrorKind {
MissingAuthParams,
}
impl std::fmt::Display for EncodeErrorKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::MissingAuthParams => {
write!(f, "could not find auth params position in encoded message")
}
}
}
}