From bdcfce7abd2a5310c260955d76eebe9572ed07f0 Mon Sep 17 00:00:00 2001 From: Corey Bonnell Date: Mon, 25 Dec 2023 19:33:18 -0500 Subject: [PATCH] More code --- src/decoder.rs | 4 +++- src/lib.rs | 43 ------------------------------------------- 2 files changed, 3 insertions(+), 44 deletions(-) diff --git a/src/decoder.rs b/src/decoder.rs index cd96f97..3410d73 100644 --- a/src/decoder.rs +++ b/src/decoder.rs @@ -363,6 +363,7 @@ pub enum DecoderType { OctetString, Null, ObjectIdentifier, + Enumerated, // ... } @@ -374,12 +375,13 @@ fn map_decoder_type_to_initializer(decoder_type: DecoderType) -> Option Some(OctetStringDecoder::new), DecoderType::Null => Some(NullDecoder::new), DecoderType::ObjectIdentifier => Some(ObjectIdentifierDecoder::new), + DecoderType::Enumerated => Some(IntegerDecoder::new), _ => None, } } -fn init_module<'py>(m: &'py PyModule) -> PyResult<()> { +pub fn init_module<'py>(m: &'py PyModule) -> PyResult<()> { let py = m.py(); let helper_mod = m.getattr("_HELPER")?; diff --git a/src/lib.rs b/src/lib.rs index 94ded0c..bdfa76f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -83,51 +83,8 @@ impl NativeHelperModule { -fn decode_oid<'py>(asn1_schema_obj: &'py PyAny, header: Header, value_substrate: &[u8]) -> PyResult<&'py PyAny> { - if header.tag.is_constructed() { - return Err(PyValueError::new_err("Invalid format for OBJECT IDENTIFIER")) - } - - } -} -type SubstrateValueDecoder = for<'py> fn(&'py PyAny, Header, &[u8]) -> PyResult<&'py PyAny>; - - -const UNIVERSAL_TAG_TO_FUNC: [Option; 31] = [ - None, // 0: doesn't exist - Some(decode_boolean), // 1: BOOLEAN - Some(decode_integer), // 2: INTEGER - Some(decode_bitstring), // 3: BIT STRING - Some(decode_octet_string), // 4: OCTET STRING - Some(decode_null), // 5: NULL - Some(decode_oid), // 6: OBJECT IDENTIFIER - None, // 7: not used - None, // 8: not used - None, // 9: REAL - not implemented - Some(decode_integer), // 10: ENUMERATED - None, // 11: not used - Some(decode_octet_string), // 12: UTF8STRING - None, // 13: not used - None, // 14: not used - None, // 15: not used - None, // 16: not used - None, // 17: not used - Some(decode_octet_string), // 18: NUMERICSTRING - Some(decode_octet_string), // 19: PRINTABLSTRING - Some(decode_octet_string), // 20: TELETEXSTRING - Some(decode_octet_string), // 21: VIDEOTEXSTRING - Some(decode_octet_string), // 22: IA5STRING - Some(decode_octet_string), // 23: UTCTIME - Some(decode_octet_string), // 24: GENERALIZEDTIME - None, // 25: not used - Some(decode_octet_string), // 26: VISIBLESTRING - None, // 27: not used - None, // 28: not used - None, // 29: not used - Some(decode_octet_string), // 30: BMPSTRING -]; fn decode_explicit<'py>(module: &'py PyModule, value_substrate: &[u8], asn1_spec: &'py PyAny, substrate_tag_set: &'py PyAny) -> PyResult<&'py PyAny> {