detect/asn1: Update asn1 C files to use rust code

Mark rust extern "C" functions as pub in asn1 module to expose via cbindgen
Update detect-asn1.c/h to use rust functions
pull/5149/head
Emmanuel Thompson 5 years ago committed by Victor Julien
parent 63704fdf13
commit 7af6cdb7ec

@ -234,7 +234,7 @@ fn asn1_decode(
/// input must be a valid buffer of at least input_len bytes
/// pointer must be freed using `rs_asn1_free`
#[no_mangle]
pub(crate) unsafe extern "C" fn rs_asn1_decode(
pub unsafe extern "C" fn rs_asn1_decode(
input: *const u8,
input_len: u32,
ad_ptr: *const DetectAsn1Data,
@ -278,7 +278,7 @@ pub unsafe extern "C" fn rs_asn1_free(ptr: *mut Asn1) {
///
/// Returns 1 if any of the options match, 0 if not
#[no_mangle]
pub(crate) unsafe extern "C" fn rs_asn1_checks(
pub unsafe extern "C" fn rs_asn1_checks(
ptr: *const Asn1,
ad_ptr: *const DetectAsn1Data,
) -> u8 {

@ -34,7 +34,7 @@ const ASN1_DEFAULT_MAX_FRAMES: u16 = 30;
///
/// pointer must be free'd using `rs_detect_asn1_free`
#[no_mangle]
pub(crate) unsafe extern "C" fn rs_detect_asn1_parse(input: *const c_char) -> *mut DetectAsn1Data {
pub unsafe extern "C" fn rs_detect_asn1_parse(input: *const c_char) -> *mut DetectAsn1Data {
if input.is_null() {
return std::ptr::null_mut();
}
@ -71,7 +71,7 @@ pub(crate) unsafe extern "C" fn rs_detect_asn1_parse(input: *const c_char) -> *m
///
/// ptr must be a valid object obtained using `rs_detect_asn1_parse`
#[no_mangle]
pub(crate) unsafe extern "C" fn rs_detect_asn1_free(ptr: *mut DetectAsn1Data) {
pub unsafe extern "C" fn rs_detect_asn1_free(ptr: *mut DetectAsn1Data) {
if ptr.is_null() {
return;
}
@ -80,7 +80,7 @@ pub(crate) unsafe extern "C" fn rs_detect_asn1_free(ptr: *mut DetectAsn1Data) {
/// Struct to hold parsed asn1 keyword options
#[derive(Debug, PartialEq)]
pub(crate) struct DetectAsn1Data {
pub struct DetectAsn1Data {
pub bitstring_overflow: bool,
pub double_overflow: bool,
pub oversize_length: Option<u32>,

File diff suppressed because it is too large Load Diff

@ -1,4 +1,4 @@
/* Copyright (C) 2007-2010 Open Information Security Foundation
/* Copyright (C) 2020 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
@ -18,28 +18,11 @@
/**
* \file detect-asn1.h
*
* \author Pablo Rincon Crespo <pablo.rincon.crespo@gmail.com>
*
* Implements "asn1" keyword
*/
#ifndef __DETECT_ASN1_H__
#define __DETECT_ASN1_H__
/* Function check flags */
#define ASN1_BITSTRING_OVF 0x01
#define ASN1_DOUBLE_OVF 0x02
#define ASN1_OVERSIZE_LEN 0x04
#define ASN1_ABSOLUTE_OFFSET 0x10
#define ASN1_RELATIVE_OFFSET 0x20
typedef struct DetectAsn1Data_ {
uint8_t flags; /* flags indicating the checks loaded */
uint32_t oversize_length; /* Length argument if needed */
uint16_t absolute_offset; /* Length argument if needed */
int32_t relative_offset; /* Length argument if needed */
} DetectAsn1Data;
/* prototypes */
void DetectAsn1Register (void);

Loading…
Cancel
Save