-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathbasic_numeric_string.rs
131 lines (115 loc) · 2.56 KB
/
basic_numeric_string.rs
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#![recursion_limit = "512"]
mod test_utils;
use test_utils::*;
asn_to_rust!(
r"BasicBitString DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
Unconstrained ::= SEQUENCE {
abc NumericString
}
BasicConstrained ::= SEQUENCE {
abc NumericString (SIZE(8))
}
BasicConstrainedSmall ::= SEQUENCE {
abc NumericString (SIZE(4..6))
}
BasicConstrainedExtensible ::= SEQUENCE {
abc NumericString (SIZE(4..6,...))
}
END"
);
#[test]
fn detect_only_invalid_character() {
let mut writer = UperWriter::default();
let result = Unconstrained {
abc: " 0123456789x".to_string(),
}
.write(&mut writer);
assert_eq!(
Err(asn1rs::protocol::per::ErrorKind::InvalidString(
asn1rs::model::asn::Charset::Numeric,
'x',
11
)
.into()),
result
)
}
#[test]
fn test_unconstrained() {
// from playground
serialize_and_deserialize_uper(
8 * 6 + 4,
&[0x0B, 0x01, 0x23, 0x45, 0x67, 0x89, 0xA0],
&Unconstrained {
abc: " 0123456789".to_string(),
},
);
}
#[test]
fn test_fixed_size() {
// from playground
serialize_and_deserialize_uper(
8 * 4,
&[0x23, 0x45, 0x67, 0x89],
&BasicConstrained {
abc: "12345678".to_string(),
},
);
}
#[test]
#[should_panic(expected = "SizeNotInRange(8, 4, 6)")]
fn test_too_large() {
// from playground
serialize_and_deserialize_uper(
0,
&[],
&BasicConstrainedSmall {
abc: "12345678".to_string(),
},
);
}
#[test]
fn test_small_min() {
// from playground
serialize_and_deserialize_uper(
8 * 2 + 2,
&[0x08, 0xD1, 0x40],
&BasicConstrainedSmall {
abc: "1234".to_string(),
},
);
}
#[test]
fn test_small_max() {
// from playground
serialize_and_deserialize_uper(
8 * 3 + 2,
&[0x88, 0xD1, 0x59, 0xC0],
&BasicConstrainedSmall {
abc: "123456".to_string(),
},
);
}
#[test]
fn test_extensible_small() {
// from playground
serialize_and_deserialize_uper(
8 * 2 + 3,
&[0x04, 0x68, 0xA0],
&BasicConstrainedExtensible {
abc: "1234".to_string(),
},
);
}
#[test]
fn test_extensible_extended() {
// from playground
serialize_and_deserialize_uper(
8 * 4 + 5,
&[0x83, 0x91, 0xA2, 0xB3, 0xC0],
&BasicConstrainedExtensible {
abc: "1234567".to_string(),
},
);
}