Skip to content

Commit

Permalink
Some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Corey Bonnell committed Dec 28, 2023
1 parent a4d0ea5 commit 0b71315
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
4 changes: 2 additions & 2 deletions python/pyasn1_fasder/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Tuple
from pyasn1.type.base import Asn1Type

from ._native import decode_der as native_decode
from ._native import decode_der as native_decode_der


def decode_der(substrate, asn1Spec: Asn1Type) -> Tuple[Asn1Type, bytes]:
return native_decode(bytes(substrate), asn1Spec), b''
return native_decode_der(bytes(substrate), asn1Spec), b''
33 changes: 14 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,6 @@ pub fn get_chosen_spec<'py>(m: NativeHelperModule, asn1_spec: &'py PyAny, substr
}


fn decode_tlv(step: DecodeStep) -> PyResult<&PyAny> {
// determine ASN.1 spec to use for value decoding

let chosen_spec = match get_chosen_spec(step.module(), step.asn1_spec(), step.tag_set()) {
Ok(None) => return decode_explicit(step),
Ok(Some(c)) => c,
Err(e) => return Err(e),
};

// create a new step with the chosen ASN.1 spec

let new_step = DecodeStep::new(step.module(), step.substrate(), step.header(), chosen_spec, step.tag_set(), step.offset());

// find decoder for chosen ASN.1 spec and decode substrate value
decode_asn1_spec_value(new_step)
}


fn decode_der_rec<'py>(m: NativeHelperModule<'py>, substrate: &'py [u8], asn1_spec: &'py PyAny, tag_set: Option<&'py PyAny>, offset: usize) -> PyResult<&'py PyAny> {
if asn1_spec.is_none() {
return Err(Pyasn1FasderError::new_err(format!("No ASN.1 specification near substrate offset {}", offset)));
Expand All @@ -148,7 +130,20 @@ fn decode_der_rec<'py>(m: NativeHelperModule<'py>, substrate: &'py [u8], asn1_sp
None => m.create_pyasn1_tagset(substrate_tag, Asn1Tag::new(substrate[0]))?
};

decode_tlv(DecodeStep::new(m, substrate, header, asn1_spec, new_tag_set, offset))
// determine ASN.1 spec to use for value decoding

let chosen_spec = match get_chosen_spec(m, asn1_spec, new_tag_set) {
Ok(None) => return decode_explicit(DecodeStep::new(m, substrate, header, asn1_spec, new_tag_set, offset)),
Ok(Some(c)) => c,
Err(e) => return Err(e),
};

// create a new step with the chosen ASN.1 spec

let step = DecodeStep::new(m, substrate, header, chosen_spec, new_tag_set, offset);

// find decoder for chosen ASN.1 spec and decode substrate value
decode_asn1_spec_value(step)
}


Expand Down

0 comments on commit 0b71315

Please sign in to comment.