From 72b4894de144da1d9945db0bdc5580bce2d788d7 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Fri, 1 Nov 2024 19:48:48 -0600 Subject: [PATCH] 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. --- const-oid/src/encoder.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/const-oid/src/encoder.rs b/const-oid/src/encoder.rs index 4c8831cf1..1081dcd88 100644 --- a/const-oid/src/encoder.rs +++ b/const-oid/src/encoder.rs @@ -111,7 +111,7 @@ impl Encoder { } let mask = if remaining_len > 0 { 0b10000000 } else { 0 }; - let (hi, lo) = split_high_bits(n); + let (hi, lo) = split_hi_bits(n); self.bytes[self.cursor] = hi | mask; self.cursor = checked_add!(self.cursor, 1); @@ -137,7 +137,7 @@ const fn base128_len(arc: Arc) -> usize { /// /// Returns: `(hi, lo)` #[inline] -const fn split_high_bits(arc: Arc) -> (u8, Arc) { +const fn split_hi_bits(arc: Arc) -> (u8, Arc) { if arc < 0x80 { return (arc as u8, 0); } @@ -173,6 +173,12 @@ mod tests { /// OID `1.2.840.10045.2.1` encoded as ASN.1 BER/DER const EXAMPLE_OID_BER: &[u8] = &hex!("2A8648CE3D0201"); + #[test] + fn split_hi_bits_with_gaps() { + assert_eq!(super::split_hi_bits(0x3a00002), (0x1d, 0x2)); + assert_eq!(super::split_hi_bits(0x3a08000), (0x1d, 0x8000)); + } + #[test] fn encode() { let encoder = Encoder::<7>::new();