forked from kellerkindt/asn1rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault_integer.rs
87 lines (70 loc) · 1.94 KB
/
default_integer.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
mod test_utils;
use test_utils::*;
asn_to_rust!(
r#"DefaultInteger DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
MyCleverSeq ::= SEQUENCE {
secret-code INTEGER DEFAULT 1337
}
theRefValue INTEGER(-9999..9999) ::= -1337
MyCleverSeqRef ::= SEQUENCE {
secret-code INTEGER(-9999..9999) DEFAULT theRefValue
}
MyWrappedInteger ::= Integer {
some-unit(1)
}
MyCleverSeqWrapped ::= SEQUENCE {
secret-code MyWrappedInteger DEFAULT 1337
}
END"#
);
#[test]
pub fn does_it_compile() {
let seq = MyCleverSeq { secret_code: 5 };
let mut writer = PrintlnWriter::default();
writer.write(&seq).unwrap();
// Writing sequence MyCleverSeq, tag=Universal(16)
// Writing DEFAULT (default: 1337)
// Some
// WRITING Integer(MIN..MAX), tag=ContextSpecific(0)
// 5
let _ = MyCleverSeqWrapped {
secret_code: MyWrappedInteger(1337),
};
}
#[test]
pub fn test_seq_with_non_default_value_0() {
serialize_and_deserialize_uper(
8 * 2 + 1,
&[0x80, 0x80, 0x00],
&MyCleverSeq { secret_code: 0 },
);
}
#[test]
pub fn test_seq_with_non_default_value_1500() {
serialize_and_deserialize_uper(
8 * 3 + 1,
&[0x81, 0x02, 0xEE, 0x00],
&MyCleverSeq { secret_code: 1500 },
);
}
#[test]
pub fn test_seq_with_default_value() {
serialize_and_deserialize_uper(8 * 0 + 1, &[0x00], &MyCleverSeq { secret_code: 1337 });
}
#[test]
pub fn test_ref_with_non_default_value_0() {
serialize_and_deserialize_uper(8 * 2 + 0, &[0xA7, 0x0F], &MyCleverSeqRef { secret_code: 0 });
}
#[test]
pub fn test_ref_with_non_default_value_1500() {
serialize_and_deserialize_uper(
8 * 2 + 0,
&[0xAC, 0xEB],
&MyCleverSeqRef { secret_code: 1500 },
);
}
#[test]
pub fn test_ref_with_default_value() {
serialize_and_deserialize_uper(8 * 0 + 1, &[0x00], &MyCleverSeqRef { secret_code: -1337 });
}