Skip to content

Commit

Permalink
const-oid: basic split_hi_bits smoke tests
Browse files Browse the repository at this point in the history
Adds internal tests which check the basic behavior of `split_hi_bits` in
the OID encoder logic.
  • Loading branch information
tarcieri committed Nov 2, 2024
1 parent 35019bc commit 3ec64cf
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions const-oid/src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<const MAX_SIZE: usize> Encoder<MAX_SIZE> {
}

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);

Expand All @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 3ec64cf

Please sign in to comment.