forked from kellerkindt/asn1rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic_set_of.rs
103 lines (87 loc) · 2.21 KB
/
basic_set_of.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
#![recursion_limit = "512"]
mod test_utils;
use test_utils::*;
asn_to_rust!(
r"BasicSequenceOf DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
Unconstrained ::= SET OF INTEGER
BasicConstrained ::= SET SIZE(3) OF INTEGER
BasicConstrainedSmall ::= SET (SIZE(2..3)) OF INTEGER
BasicConstrainedExtensible ::= SET SIZE(2..3,...) OF INTEGER
END"
);
#[test]
fn test_unconstrained() {
// from playground
serialize_and_deserialize_uper(
8 * 11,
&[
0x05, 0x01, 0x01, 0x01, 0x02, 0x01, 0x03, 0x01, 0x04, 0x01, 0x05,
],
&Unconstrained(vec![1, 2, 3, 4, 5]),
);
}
#[test]
fn test_unconstrained_rev() {
// from playground
serialize_and_deserialize_uper(
8 * 11,
&[
0x05, 0x01, 0x05, 0x01, 0x04, 0x01, 0x03, 0x01, 0x02, 0x01, 0x01,
],
&Unconstrained(vec![5, 4, 3, 2, 1]),
);
}
#[test]
fn test_fixed_size() {
// from playground
serialize_and_deserialize_uper(
8 * 6,
&[0x01, 0x01, 0x01, 0x02, 0x01, 0x03],
&BasicConstrained(vec![1, 2, 3]),
);
}
#[test]
#[should_panic(expected = "SizeNotInRange(5, 2, 3)")]
fn test_too_large() {
// from playground
serialize_and_deserialize_uper(0, &[], &BasicConstrainedSmall(vec![1, 2, 3, 4, 5]));
}
#[test]
fn test_small_min() {
// from playground
serialize_and_deserialize_uper(
8 * 4 + 1,
&[0x00, 0x80, 0x80, 0x81, 0x00],
&BasicConstrainedSmall(vec![1, 2]),
);
}
#[test]
fn test_small_max() {
// from playground
serialize_and_deserialize_uper(
8 * 6 + 1,
&[0x80, 0x80, 0x80, 0x81, 0x00, 0x81, 0x80],
&BasicConstrainedSmall(vec![1, 2, 3]),
);
}
#[test]
fn test_extensible_small() {
// from playground
serialize_and_deserialize_uper(
8 * 6 + 2,
&[0x40, 0x40, 0x40, 0x40, 0x80, 0x40, 0xC0],
&BasicConstrainedExtensible(vec![1, 2, 3]),
);
}
#[test]
fn test_extensible_extended() {
// from playground
serialize_and_deserialize_uper(
8 * 11 + 1,
&[
0x82, 0x80, 0x80, 0x80, 0x81, 0x00, 0x81, 0x80, 0x82, 0x80, 0x83, 0x00,
],
&BasicConstrainedExtensible(vec![1, 2, 3, 5, 6]),
);
}