* 02110-1301, USA.
*/
+use crate::log::*;
use der_parser::ber::{parse_ber_recursive, BerObject, BerObjectContent, BerTag};
use der_parser::error::BerError;
use std::convert::TryFrom;
/// Errors possible during decoding of Asn1
#[derive(Debug)]
-#[repr(u32)]
-pub enum Asn1DecodeError {
- Success = 0,
+enum Asn1DecodeError {
InvalidKeywordParameter,
MaxFrames,
InvalidStructure,
/// Errors possible during Asn1 checks
#[derive(Debug)]
-#[repr(u32)]
-pub enum Asn1CheckError {
- Success = 0,
+enum Asn1CheckError {
MaxDepth,
}
+impl std::fmt::Display for Asn1CheckError {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+ match self {
+ Asn1CheckError::MaxDepth => write!(f, "MaxDepth"),
+ }
+ }
+}
+
impl Asn1 {
/// Checks each BerObject contained in self with the provided detection
/// data, returns the first successful match if one occurs
let asn1 = &*ptr;
let ad = &*ad_ptr;
- if let Ok(Some(_)) = asn1.check(ad) {
- return 1;
+ match asn1.check(ad) {
+ Ok(Some(_check)) => 1,
+ Ok(None) => 0,
+ Err(e) => {
+ SCLogError!("error during asn1 checks: {}", e.to_string());
+ 0
+ }
}
-
- 0
}
impl From<std::num::TryFromIntError> for Asn1DecodeError {
if let Ok(v) = max_frames.parse::<u16>() {
data.max_frames = v;
} else {
- SCLogDebug!("Could not parse asn1-max-frames: {}", max_frames);
+ SCLogError!("Could not parse asn1-max-frames: {}", max_frames);
+ return std::ptr::null_mut();
};
}
Box::into_raw(Box::new(data))
}
- Err(_) => std::ptr::null_mut(),
+ Err(e) => {
+ SCLogError!("Malformed asn1 argument: {}", e.to_string());
+ std::ptr::null_mut()
+ }
}
}
}
}
+#[macro_export]
+macro_rules!SCLogError {
+ ($($arg:tt)*) => {
+ do_log!(Level::Error, file!(), line!(), function!(), 0, $($arg)*);
+ }
+}
+
// Debug mode: call C SCLogDebug
#[cfg(feature = "debug")]
#[macro_export]