diff --git a/Cargo.toml b/Cargo.toml index 0c2c39b..5634212 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,8 +16,8 @@ features = ["full"] features = ["full", "tokio"] [dependencies] -asn1-rs = "0.6" -snmptools = { version = "^0.1.2", optional = true } +asn1-rs = "0.7.1" +snmptools = { version = "^0.3.0", optional = true} tokio = { version = "1.47", features = ["net"], optional = true } openssl = { version = "0.10", optional = true } diff --git a/src/asyncsession.rs b/src/asyncsession.rs index ee09d41..0c697b5 100644 --- a/src/asyncsession.rs +++ b/src/asyncsession.rs @@ -133,9 +133,10 @@ impl AsyncSession { if let Err(e) = Pdu::from_bytes_inner( Self::send_and_recv(&self.socket, &self.send_pdu, &mut self.recv_buf).await?, Some(security), - ) && e != Error::AuthUpdated - { - return Err(e); + ) { + if e != Error::AuthUpdated { + return Err(e); + } } if security.need_init() { return Err(Error::AuthFailure(v3::AuthErrorKind::NotAuthenticated)); @@ -155,12 +156,12 @@ impl AsyncSession { /// 'Err(error)' when 'init()' failed with error returned from 'init()' #[cfg(feature = "v3")] pub async fn try_another_key_extension_method(&mut self) -> Result> { - if let Some(ref mut security) = self.security - && let Some(new_method) = security.another_key_extension_method() - { - security.authoritative_state = v3::AuthoritativeState::default(); - self.init().await?; - return Ok(Some(new_method)); + if let Some(ref mut security) = self.security { + if let Some(new_method) = security.another_key_extension_method() { + security.authoritative_state = v3::AuthoritativeState::default(); + self.init().await?; + return Ok(Some(new_method)); + } } Ok(None) } diff --git a/src/mibs.rs b/src/mibs.rs index 6c5986d..627c792 100644 --- a/src/mibs.rs +++ b/src/mibs.rs @@ -12,6 +12,7 @@ pub trait MibConversion { fn from_mib_name(name: &str) -> Result where Self: Sized; + fn asn_type(&self) -> Result; } impl MibConversion for Oid<'_> { @@ -27,4 +28,14 @@ impl MibConversion for Oid<'_> { .map_err(move |e| crate::Error::Mib(e.to_string()))? .to_owned()) } + + fn asn_type(&self) -> Result { + let val = snmptools::get_type(self).map_err(|e| crate::Error::Mib(e.to_string()))?; + if val == 255 { + return Err(crate::Error::Mib( + format! {"netsnmp:mib_to_asn_type returned 255 (not found) for {self}"}, + )); + } + Ok(val) + } } diff --git a/src/syncsession.rs b/src/syncsession.rs index a679d62..ad4a643 100644 --- a/src/syncsession.rs +++ b/src/syncsession.rs @@ -164,9 +164,10 @@ impl SyncSession { if let Err(e) = Pdu::from_bytes_inner( Self::send_and_recv(&self.socket, &self.send_pdu, &mut self.recv_buf)?, Some(security), - ) && e != Error::AuthUpdated - { - return Err(e); + ) { + if e != Error::AuthUpdated { + return Err(e); + } } if security.need_init() { return Err(Error::AuthFailure(v3::AuthErrorKind::NotAuthenticated)); @@ -186,12 +187,12 @@ impl SyncSession { /// 'Err(error)' when 'init()' failed with error returned from 'init()' #[cfg(feature = "v3")] pub fn try_another_key_extension_method(&mut self) -> Result> { - if let Some(ref mut security) = self.security - && let Some(new_method) = security.another_key_extension_method() - { - security.authoritative_state = v3::AuthoritativeState::default(); - self.init()?; - return Ok(Some(new_method)); + if let Some(ref mut security) = self.security { + if let Some(new_method) = security.another_key_extension_method() { + security.authoritative_state = v3::AuthoritativeState::default(); + self.init()?; + return Ok(Some(new_method)); + } } Ok(None) } diff --git a/src/v3.rs b/src/v3.rs index 7cc9f7b..42e7e79 100644 --- a/src/v3.rs +++ b/src/v3.rs @@ -301,12 +301,13 @@ impl Security { } pub(crate) fn another_key_extension_method(&mut self) -> Option { - if let Auth::AuthPriv { ref cipher, .. } = self.auth - && cipher.priv_key_needs_extension(&self.auth_protocol) - && let Some(used_method) = self.key_extension_method - { - self.key_extension_method = Some(used_method.other()); - return self.key_extension_method; + if let Auth::AuthPriv { ref cipher, .. } = self.auth { + if cipher.priv_key_needs_extension(&self.auth_protocol) { + if let Some(used_method) = self.key_extension_method { + self.key_extension_method = Some(used_method.other()); + return self.key_extension_method; + } + } } None }