asnfuzzgen_codecs/per/aper/decode/mod.rs
1//! Decode APIs for APER Codec
2
3use bitvec::prelude::*;
4
5#[allow(unused)]
6use crate::per::common::decode::*;
7use crate::per::PerCodecData;
8
9use crate::PerCodecError;
10
11/// Decode a Choice Index.
12///
13/// For an ASN.1 `CHOICE` Type, a CHOICE Index is first decoded. This function is used to `decode`
14/// the choice index. Returns the Index in the 'root' or 'additions' and a flag indicated whether
15/// the value is from the 'root_extensions' or 'addtions'. The caller would then decide the
16/// appropriate `decode` function for the CHOICE variant is called.
17pub fn decode_choice_idx(
18 data: &mut PerCodecData,
19 lb: i128,
20 ub: i128,
21 is_extensible: bool,
22) -> Result<(i128, bool), PerCodecError> {
23
24 decode_choice_idx_common(data, lb, ub, is_extensible, true)
25}
26
27/// Decode The Sequence Header
28///
29/// The Sequence Header consists of potentially two fields
30/// 1. Whether `extensions` are present in the encoding
31/// 2. Which of the OPTIONAL fields (if any) are present as a bitmap.
32pub fn decode_sequence_header(
33 data: &mut PerCodecData,
34 is_extensible: bool,
35 optional_count: usize,
36) -> Result<(BitVec<u8, Msb0>, bool), PerCodecError> {
37
38 decode_sequence_header_common(data, is_extensible, optional_count, true)
39}
40
41/// Decode an Integer
42///
43/// Given an Integer Specification with PER Visible Constraints, decode an Integer Value to obtain
44/// the integer value which will always be returned as an i128 value.
45///
46/// Note: The maximum (and minimum) value to be decoded is limited to an `i128` value. For the
47/// protocols that are currently supported this limit is acceptable.
48///
49/// `lb` and `ub` are upper and lower bounds as determined by the PER Constraints (and hence can be
50/// `None` if no Constraints are not speicifed. `is_extensible` specifies whether the defined type
51/// is extensible (as per PER Constraints). Returned value is the value of the Integer (i128) and
52/// whether the value is outside the extension root (`bool`: `true` if value is outside the
53/// extension root.).
54pub fn decode_integer(
55 data: &mut PerCodecData,
56 lb: Option<i128>,
57 ub: Option<i128>,
58 is_extensible: bool,
59) -> Result<(i128, bool), PerCodecError> {
60
61 decode_integer_common(data, lb, ub, is_extensible, true)
62}
63
64/// Decode a Boolean
65///
66/// Decode a Boolean value. Returns the decoded value as a `bool`.
67pub fn decode_bool(data: &mut PerCodecData) -> Result<bool, PerCodecError> {
68
69 decode_bool_common(data, true)
70}
71
72/// Decode an Enumerated Value
73///
74/// Decodes an Enumerated value as an index into either `root_values` of the ENUMERATED or
75/// `ext_values` of the ENUMERATED and also decodes a flag indicating where the value belongs. If
76/// `false` the value is from the `root_values`, else the value is from the `ext_values` of the
77/// ENUMERATED.
78pub fn decode_enumerated(
79 data: &mut PerCodecData,
80 lb: Option<i128>,
81 ub: Option<i128>,
82 is_extensible: bool,
83) -> Result<(i128, bool), PerCodecError> {
84
85 decode_enumerated_common(data, lb, ub, is_extensible, true)
86}
87
88/// Decode a Bit String
89///
90/// Decodes the value of the BIT STRING from the Buffer.
91pub fn decode_bitstring(
92 data: &mut PerCodecData,
93 lb: Option<i128>,
94 ub: Option<i128>,
95 is_extensible: bool,
96) -> Result<BitVec<u8, Msb0>, PerCodecError> {
97
98 decode_bitstring_common(data, lb, ub, is_extensible, true)
99}
100
101/// Decode an OCTET STRING
102///
103/// Decodes the value of the OCTET STRING from the Buffer.
104pub fn decode_octetstring(
105 data: &mut PerCodecData,
106 lb: Option<i128>,
107 ub: Option<i128>,
108 is_extensible: bool,
109) -> Result<Vec<u8>, PerCodecError> {
110
111 decode_octetstring_common(data, lb, ub, is_extensible, true)
112}
113
114/// Decodes a Length determinent
115pub fn decode_length_determinent(
116 data: &mut PerCodecData,
117 lb: Option<i128>,
118 ub: Option<i128>,
119 normally_small: bool,
120) -> Result<usize, PerCodecError> {
121
122 decode_length_determinent_common(data, lb, ub, normally_small, true)
123}
124
125mod decode_charstrings;
126pub use decode_charstrings::*;