Skip to content

Commit c872bb3

Browse files
authored
const-oid: test max arc edge case; more coverage (#1594)
Changes an example to test the `u32::MAX` edge case for OIDs, and ensures all of the relevant methods are tested.
1 parent 13ddc41 commit c872bb3

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

const-oid/tests/oid.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ const EXAMPLE_OID_LARGE_ARC_1_BER: &[u8] = &hex!("0992268993F22C640101");
3434
const EXAMPLE_OID_LARGE_ARC_1: ObjectIdentifier =
3535
ObjectIdentifier::new_unwrap(EXAMPLE_OID_LARGE_ARC_1_STR);
3636

37-
/// Example OID value with a large arc
38-
const EXAMPLE_OID_LARGE_ARC_2_STR: &str = "1.2.840.10045.4.3.4.1111111111";
39-
const EXAMPLE_OID_LARGE_ARC_2_BER: &[u8] = &hex!("2A8648CE3D0403048491E8EB47");
37+
/// Example OID value with a large arc (namely `u32::MAX`, the edge case)
38+
const EXAMPLE_OID_LARGE_ARC_2_STR: &str = "1.2.4294967295";
39+
const EXAMPLE_OID_LARGE_ARC_2_BER: &[u8] = &hex!("2A8FFFFFFF7F");
4040
const EXAMPLE_OID_LARGE_ARC_2: ObjectIdentifier =
4141
ObjectIdentifier::new_unwrap(crate::EXAMPLE_OID_LARGE_ARC_2_STR);
4242

@@ -87,16 +87,11 @@ fn from_bytes() {
8787
assert_eq!(oid_largearc1.arc(6).unwrap(), 1);
8888
assert_eq!(oid_largearc1, EXAMPLE_OID_LARGE_ARC_1);
8989

90-
// 1.2.840.10045.4.3.4.1111111111
90+
// 1.2.4294967295
9191
let oid_largearc2 = ObjectIdentifier::from_bytes(EXAMPLE_OID_LARGE_ARC_2_BER).unwrap();
9292
assert_eq!(oid_largearc2.arc(0).unwrap(), 1);
9393
assert_eq!(oid_largearc2.arc(1).unwrap(), 2);
94-
assert_eq!(oid_largearc2.arc(2).unwrap(), 840);
95-
assert_eq!(oid_largearc2.arc(3).unwrap(), 10045);
96-
assert_eq!(oid_largearc2.arc(4).unwrap(), 4);
97-
assert_eq!(oid_largearc2.arc(5).unwrap(), 3);
98-
assert_eq!(oid_largearc2.arc(6).unwrap(), 4);
99-
assert_eq!(oid_largearc2.arc(7).unwrap(), 1111111111);
94+
assert_eq!(oid_largearc2.arc(2).unwrap(), 4294967295);
10095
assert_eq!(oid_largearc2, EXAMPLE_OID_LARGE_ARC_2);
10196

10297
// Empty
@@ -140,6 +135,14 @@ fn from_str() {
140135
assert_eq!(oid_largearc1.arc(6).unwrap(), 1);
141136
assert_eq!(oid_largearc1, EXAMPLE_OID_LARGE_ARC_1);
142137

138+
let oid_largearc2 = EXAMPLE_OID_LARGE_ARC_2_STR
139+
.parse::<ObjectIdentifier>()
140+
.unwrap();
141+
assert_eq!(oid_largearc2.arc(0).unwrap(), 1);
142+
assert_eq!(oid_largearc2.arc(1).unwrap(), 2);
143+
assert_eq!(oid_largearc2.arc(2).unwrap(), 4294967295);
144+
assert_eq!(oid_largearc2, EXAMPLE_OID_LARGE_ARC_2);
145+
143146
// Truncated
144147
assert_eq!(
145148
"1.2.840.10045.2.".parse::<ObjectIdentifier>(),
@@ -164,10 +167,18 @@ fn display() {
164167
assert_eq!(EXAMPLE_OID_0.to_string(), EXAMPLE_OID_0_STR);
165168
assert_eq!(EXAMPLE_OID_1.to_string(), EXAMPLE_OID_1_STR);
166169
assert_eq!(EXAMPLE_OID_2.to_string(), EXAMPLE_OID_2_STR);
170+
assert_eq!(
171+
EXAMPLE_OID_LARGE_ARC_0.to_string(),
172+
EXAMPLE_OID_LARGE_ARC_0_STR
173+
);
167174
assert_eq!(
168175
EXAMPLE_OID_LARGE_ARC_1.to_string(),
169176
EXAMPLE_OID_LARGE_ARC_1_STR
170177
);
178+
assert_eq!(
179+
EXAMPLE_OID_LARGE_ARC_2.to_string(),
180+
EXAMPLE_OID_LARGE_ARC_2_STR
181+
);
171182
}
172183

173184
#[test]

0 commit comments

Comments
 (0)