forked from kellerkindt/asn1rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extensible_integer.rs
101 lines (86 loc) · 2.48 KB
/
extensible_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
mod test_utils;
use test_utils::*;
asn_to_rust!(
r"BasicInteger DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
NotRanged ::= Integer
RangedAndExtensible ::= Integer (0..255,...)
RangedOptional ::= SEQUENCE {
value Integer (0..255,...) OPTIONAL
}
END"
);
#[asn(transparent)]
#[derive(Default, Debug, Clone, PartialEq, Hash)]
pub struct RangedAndExtensiblePureRust(#[asn(integer(0..255,...))] pub u64);
#[test]
fn test_extensible_range() {
use asn1rs::syn::numbers::Constraint;
assert_eq!(
Some(0_i64),
___asn1rs_RangedAndExtensiblePureRustField0Constraint::MIN
);
assert_eq!(
Some(0_u64),
___asn1rs_RangedAndExtensiblePureRustField0Constraint::MIN_T
);
assert_eq!(
Some(255_i64),
___asn1rs_RangedAndExtensiblePureRustField0Constraint::MAX
);
assert_eq!(
Some(255_u64),
___asn1rs_RangedAndExtensiblePureRustField0Constraint::MAX_T
);
assert_eq!(
Some(0_i64),
___asn1rs_RangedAndExtensibleField0Constraint::MIN
);
assert_eq!(
Some(0_u64),
___asn1rs_RangedAndExtensibleField0Constraint::MIN_T
);
assert_eq!(
Some(255_i64),
___asn1rs_RangedAndExtensibleField0Constraint::MAX
);
assert_eq!(
Some(255_u64),
___asn1rs_RangedAndExtensibleField0Constraint::MAX_T
);
}
#[test]
fn test_extensible_flag() {
use asn1rs::syn::numbers::Constraint;
assert!(___asn1rs_RangedAndExtensiblePureRustField0Constraint::EXTENSIBLE);
assert!(___asn1rs_RangedAndExtensibleField0Constraint::EXTENSIBLE);
}
#[test]
fn test_extensible_type() {
let _ = RangedAndExtensible(1024); // does not compile if extensible is ignored
let _ = RangedAndExtensiblePureRust(1024); // does not compile if extensible is ignored
}
#[test]
fn test_uper_std_0() {
serialize_and_deserialize_uper(9, &[0x00, 0x00], &RangedAndExtensible(0));
}
#[test]
fn test_uper_opt_std_0() {
serialize_and_deserialize_uper(10, &[0x80, 0x00], &RangedOptional { value: Some(0) });
}
#[test]
fn test_uper_opt_std_254() {
serialize_and_deserialize_uper(10, &[0xBF, 0x80], &RangedOptional { value: Some(254) });
}
#[test]
fn test_uper_opt_std_255() {
serialize_and_deserialize_uper(10, &[0xBF, 0xC0], &RangedOptional { value: Some(255) });
}
#[test]
fn test_uper_opt_std_256() {
serialize_and_deserialize_uper(
26,
&[0xC0, 0x80, 0x40, 0x00],
&RangedOptional { value: Some(256) },
);
}