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