forked from kellerkindt/asn1rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault_string.rs
83 lines (71 loc) · 1.78 KB
/
default_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
mod test_utils;
use test_utils::*;
asn_to_rust!(
r#"DefaultString DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
MyCleverSeq ::= SEQUENCE {
secret-message UTF8String DEFAULT "hey hee ha"
}
defaultMessage UTF8String ::= "hey hee ha"
MyCleverSeqRef ::= SEQUENCE {
secret-message UTF8String DEFAULT defaultMessage
}
END"#
);
#[test]
pub fn does_it_compile() {
let seq = MyCleverSeq {
secret_message: "woah".to_string(),
};
let mut writer = PrintlnWriter::default();
writer.write(&seq).unwrap();
// Writing sequence MyCleverSeq, tag=Universal(16)
// Writing DEFAULT (default: "hey hee ha")
// Some
// Writing Utf8String(MIN..MAX), tag=ContextSpecific(0)
// "woah"
}
#[test]
pub fn test_seq_with_non_default_value() {
serialize_and_deserialize_uper(
8 * 10 + 1,
&[
0x84, 0xBB, 0xB7, 0xB0, 0xB4, 0x10, 0x3C, 0xB2, 0xB0, 0xB4, 0x00,
],
&MyCleverSeq {
secret_message: "woah yeah".to_string(),
},
);
}
#[test]
pub fn test_seq_with_default_value() {
serialize_and_deserialize_uper(
8 * 0 + 1,
&[0x00],
&MyCleverSeq {
secret_message: "hey hee ha".to_string(),
},
);
}
#[test]
pub fn test_ref_with_non_default_value() {
serialize_and_deserialize_uper(
8 * 10 + 1,
&[
0x84, 0xBB, 0xB7, 0xB0, 0xB4, 0x10, 0x3C, 0xB2, 0xB0, 0xB4, 0x00,
],
&MyCleverSeqRef {
secret_message: "woah yeah".to_string(),
},
);
}
#[test]
pub fn test_ref_with_default_value() {
serialize_and_deserialize_uper(
8 * 0 + 1,
&[0x00],
&MyCleverSeqRef {
secret_message: "hey hee ha".to_string(),
},
);
}