Skip to content

Commit 72b4894

Browse files
authored
const-oid: basic split_hi_bits smoke tests (#1599)
Adds internal tests which check the basic behavior of `split_hi_bits` in the OID encoder logic.
1 parent 35019bc commit 72b4894

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

const-oid/src/encoder.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl<const MAX_SIZE: usize> Encoder<MAX_SIZE> {
111111
}
112112

113113
let mask = if remaining_len > 0 { 0b10000000 } else { 0 };
114-
let (hi, lo) = split_high_bits(n);
114+
let (hi, lo) = split_hi_bits(n);
115115
self.bytes[self.cursor] = hi | mask;
116116
self.cursor = checked_add!(self.cursor, 1);
117117

@@ -137,7 +137,7 @@ const fn base128_len(arc: Arc) -> usize {
137137
///
138138
/// Returns: `(hi, lo)`
139139
#[inline]
140-
const fn split_high_bits(arc: Arc) -> (u8, Arc) {
140+
const fn split_hi_bits(arc: Arc) -> (u8, Arc) {
141141
if arc < 0x80 {
142142
return (arc as u8, 0);
143143
}
@@ -173,6 +173,12 @@ mod tests {
173173
/// OID `1.2.840.10045.2.1` encoded as ASN.1 BER/DER
174174
const EXAMPLE_OID_BER: &[u8] = &hex!("2A8648CE3D0201");
175175

176+
#[test]
177+
fn split_hi_bits_with_gaps() {
178+
assert_eq!(super::split_hi_bits(0x3a00002), (0x1d, 0x2));
179+
assert_eq!(super::split_hi_bits(0x3a08000), (0x1d, 0x8000));
180+
}
181+
176182
#[test]
177183
fn encode() {
178184
let encoder = Encoder::<7>::new();

0 commit comments

Comments
 (0)