use nom::IResult;
use nom::number::streaming::be_u32;
use der_parser::der::der_read_element_header;
+use der_parser::ber::BerClass;
use kerberos_parser::krb5_parser;
use kerberos_parser::krb5::{EncryptionType,ErrorCode,MessageType,PrincipalName,Realm};
use crate::applayer::{self, *};
match der_read_element_header(i) {
Ok((_rem,hdr)) => {
// Kerberos messages start with an APPLICATION header
- if hdr.class != 0b01 { return 0; }
+ if hdr.class != BerClass::Application { return 0; }
match hdr.tag.0 {
10 => {
self.req_id = 10;
match der_read_element_header(slice) {
Ok((rem, ref hdr)) => {
// Kerberos messages start with an APPLICATION header
- if hdr.class != 0b01 { return unsafe{ALPROTO_FAILED}; }
+ if hdr.class != BerClass::Application { return unsafe{ALPROTO_FAILED}; }
// Tag number should be <= 30
if hdr.tag.0 >= 30 { return unsafe{ALPROTO_FAILED}; }
// Kerberos messages contain sequences
}
}
-pub struct SNMPState {
+pub struct SNMPState<'a> {
/// SNMP protocol version
pub version: u32,
/// List of transactions for this session
- transactions: Vec<SNMPTransaction>,
+ transactions: Vec<SNMPTransaction<'a>>,
/// tx counter for assigning incrementing id's to tx's
tx_id: u64,
}
-pub struct SNMPPduInfo {
+pub struct SNMPPduInfo<'a> {
pub pdu_type: PduType,
pub err: ErrorStatus,
- pub trap_type: Option<(TrapType,Oid,NetworkAddress)>,
+ pub trap_type: Option<(TrapType,Oid<'a>,NetworkAddress)>,
- pub vars: Vec<Oid>,
+ pub vars: Vec<Oid<'a>>,
}
-pub struct SNMPTransaction {
+pub struct SNMPTransaction<'a> {
/// PDU version
pub version: u32,
/// PDU info, if present (and cleartext)
- pub info: Option<SNMPPduInfo>,
+ pub info: Option<SNMPPduInfo<'a>>,
/// Community, if present (SNMPv2)
pub community: Option<String>,
-impl SNMPState {
- pub fn new() -> SNMPState {
+impl<'a> SNMPState<'a> {
+ pub fn new() -> SNMPState<'a> {
SNMPState{
version: 0,
transactions: Vec::new(),
}
}
-impl Default for SNMPPduInfo {
- fn default() -> SNMPPduInfo {
+impl<'a> Default for SNMPPduInfo<'a> {
+ fn default() -> SNMPPduInfo<'a> {
SNMPPduInfo{
pdu_type: PduType(0),
err: ErrorStatus::NoError,
}
}
-impl SNMPState {
- fn add_pdu_info(&mut self, pdu: &SnmpPdu, tx: &mut SNMPTransaction) {
+impl<'a> SNMPState<'a> {
+ fn add_pdu_info(&mut self, pdu: &SnmpPdu<'a>, tx: &mut SNMPTransaction<'a>) {
let mut pdu_info = SNMPPduInfo::default();
pdu_info.pdu_type = pdu.pdu_type();
match *pdu {
pdu_info.trap_type = Some((t.generic_trap,t.enterprise.clone(),t.agent_addr.clone()));
}
}
- for ref var in pdu.vars_iter() {
- pdu_info.vars.push(var.oid.clone());
+
+ for var in pdu.vars_iter() {
+ pdu_info.vars.push(var.oid.to_owned());
}
tx.info = Some(pdu_info);
}
- fn handle_snmp_v12(&mut self, msg:SnmpMessage, _direction: u8) -> i32 {
+ fn handle_snmp_v12(&mut self, msg: SnmpMessage<'a>, _direction: u8) -> i32 {
let mut tx = self.new_tx();
// in the message, version is encoded as 0 (version 1) or 1 (version 2)
if self.version != msg.version + 1 {
0
}
- fn handle_snmp_v3(&mut self, msg: SnmpV3Message, _direction: u8) -> i32 {
+ fn handle_snmp_v3(&mut self, msg: SnmpV3Message<'a>, _direction: u8) -> i32 {
let mut tx = self.new_tx();
if self.version != msg.version {
SCLogDebug!("SNMP version mismatch: expected {}, received {}", self.version, msg.version);
/// Parse an SNMP request message
///
/// Returns 0 if successful, or -1 on error
- fn parse(&mut self, i: &[u8], direction: u8) -> i32 {
+ fn parse(&mut self, i: &'a [u8], direction: u8) -> i32 {
if self.version == 0 {
match parse_pdu_enveloppe_version(i) {
Ok((_,x)) => self.version = x,
self.transactions.clear();
}
- fn new_tx(&mut self) -> SNMPTransaction {
+ fn new_tx(&mut self) -> SNMPTransaction<'a> {
self.tx_id += 1;
SNMPTransaction::new(self.version, self.tx_id)
}
}
}
-impl SNMPTransaction {
- pub fn new(version: u32, id: u64) -> SNMPTransaction {
+impl<'a> SNMPTransaction<'a> {
+ pub fn new(version: u32, id: u64) -> SNMPTransaction<'a> {
SNMPTransaction {
version,
info: None,
}
}
-impl Drop for SNMPTransaction {
+impl<'a> Drop for SNMPTransaction<'a> {
fn drop(&mut self) {
self.free();
}