Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

const-oid: basic split_hi_bits smoke tests #1599

Merged
merged 1 commit into from
Nov 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading