1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! Functionality for decoding character strings

use crate::per::common::decode::decode_string_common;
use crate::per::PerCodecData;
use crate::PerCodecError;

// 27.5.3 and 27.5.4
/// Decode a VisibleString CharacterString Type.
pub fn decode_visible_string(
    data: &mut PerCodecData,
    lb: Option<i128>,
    ub: Option<i128>,
    is_extensible: bool,
) -> Result<String, PerCodecError> {
    decode_string_common(data, lb, ub, is_extensible, 8, true)
}

/// Decode a PrintableString CharacterString Type.
pub fn decode_printable_string(
    data: &mut PerCodecData,
    lb: Option<i128>,
    ub: Option<i128>,
    is_extensible: bool,
) -> Result<String, PerCodecError> {
    decode_string_common(data, lb, ub, is_extensible, 8, true)
}

// UTF-8 String is always - indefinite length case as it's not a fixed character width string. It's
// almost like decoding an octet string.
// 27.6
/// Decode a UTF8String CharacterString Type.
pub fn decode_utf8_string(
    data: &mut PerCodecData,
    lb: Option<i128>,
    ub: Option<i128>,
    is_extensible: bool,
) -> Result<String, PerCodecError> {
    decode_string_common(data, lb, ub, is_extensible, 8, true)
}