From 3b4613e492b86364b9953024d027bc6120a6a0c8 Mon Sep 17 00:00:00 2001 From: dishmaker <141624503+dishmaker@users.noreply.github.com> Date: Tue, 8 Apr 2025 13:07:55 +0200 Subject: [PATCH 1/4] const-oid: add test 1.1.1.270000000 --- const-oid/src/encoder.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/const-oid/src/encoder.rs b/const-oid/src/encoder.rs index 0ce7058cc..07592e4ec 100644 --- a/const-oid/src/encoder.rs +++ b/const-oid/src/encoder.rs @@ -143,7 +143,10 @@ mod tests { use hex_literal::hex; /// OID `1.2.840.10045.2.1` encoded as ASN.1 BER/DER - const EXAMPLE_OID_BER: &[u8] = &hex!("2A8648CE3D0201"); + const EXAMPLE_OID_BER: &[u8] = &hex!("2A 86 48 CE 3D 02 01"); + + /// OID `1.1.1.270000000` encoded as ASN.1 BER/DER + const EXAMPLE_LONG_OID_BER: &[u8] = &hex!("29 01 81 80 DF BF 00"); #[test] fn base128_byte() { @@ -167,4 +170,14 @@ mod tests { let encoder = encoder.arc(1).unwrap(); assert_eq!(&encoder.bytes[..encoder.cursor], EXAMPLE_OID_BER); } + + #[test] + fn encode_large() { + let encoder = Encoder::<7>::new(); + let encoder = encoder.arc(1).unwrap(); + let encoder = encoder.arc(1).unwrap(); + let encoder = encoder.arc(1).unwrap(); + let encoder = encoder.arc(270000000).unwrap(); + assert_eq!(&encoder.bytes[..encoder.cursor], EXAMPLE_LONG_OID_BER); + } } From de986b1412d8f5c039211a73ecddc7278afa3ab9 Mon Sep 17 00:00:00 2001 From: dishmaker <141624503+dishmaker@users.noreply.github.com> Date: Tue, 8 Apr 2025 13:29:36 +0200 Subject: [PATCH 2/4] const-oid: fix encoder --- const-oid/src/encoder.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/const-oid/src/encoder.rs b/const-oid/src/encoder.rs index 07592e4ec..88aece1a1 100644 --- a/const-oid/src/encoder.rs +++ b/const-oid/src/encoder.rs @@ -119,10 +119,10 @@ impl Encoder { /// Compute the length of an arc when encoded in base 128. const fn base128_len(arc: Arc) -> usize { match arc { - 0..=0x7f => 1, - 0x80..=0x3fff => 2, - 0x4000..=0x1fffff => 3, - 0x200000..=0x1fffffff => 4, + 0..=0x7f => 1, // up to 7 bits + 0x80..=0x3fff => 2, // up to 14 bits + 0x4000..=0x1fffff => 3, // up to 21 bits + 0x200000..=0x0fffffff => 4, // up to 28 bits _ => 5, } } From a56c4d67d5228927470a62e00ae9bf0607f9b84c Mon Sep 17 00:00:00 2001 From: dishmaker <141624503+dishmaker@users.noreply.github.com> Date: Tue, 8 Apr 2025 13:31:56 +0200 Subject: [PATCH 3/4] add proptest 1.1.1.270000000 --- const-oid/tests/proptests.proptest-regressions | 1 + 1 file changed, 1 insertion(+) diff --git a/const-oid/tests/proptests.proptest-regressions b/const-oid/tests/proptests.proptest-regressions index 805e18453..c80d61ed8 100644 --- a/const-oid/tests/proptests.proptest-regressions +++ b/const-oid/tests/proptests.proptest-regressions @@ -11,3 +11,4 @@ cc d90305406041ea5e4cf4d9e7849cad03391db1869d0b1329f60ccbf1fabaee91 # shrinks to cc 8ed8dde35d12a2c8e10cdde6d591a8f17f0cd6d6fdf90f1582536401364623bf # shrinks to s = "0.00" cc ba5e3e3dc1a64870477e82054bbf6d8272f8b0d0c9094115bf7e8b5ff59f3c63 # shrinks to s = "00.1.1" cc d211e943da9a0e3d0ee5097899b2435f784ca2b3d2f8d4790aae3744823a268a # shrinks to s = "1.1.1.60817410.1" +cc 61bdeaa6cfc6707a0c4f3e9c6165d99d28042e78acb29b0ca7f747c169e83e74 # shrinks to s = "1.1.1.270000000" From 914338dd4a60d4976fec447c9a331942f9bebd0f Mon Sep 17 00:00:00 2001 From: dishmaker <141624503+dishmaker@users.noreply.github.com> Date: Tue, 8 Apr 2025 13:34:25 +0200 Subject: [PATCH 4/4] Revert "const-oid: add test 1.1.1.270000000" This reverts commit 3b4613e492b86364b9953024d027bc6120a6a0c8. --- const-oid/src/encoder.rs | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/const-oid/src/encoder.rs b/const-oid/src/encoder.rs index 88aece1a1..77c40cc34 100644 --- a/const-oid/src/encoder.rs +++ b/const-oid/src/encoder.rs @@ -143,10 +143,7 @@ mod tests { use hex_literal::hex; /// OID `1.2.840.10045.2.1` encoded as ASN.1 BER/DER - const EXAMPLE_OID_BER: &[u8] = &hex!("2A 86 48 CE 3D 02 01"); - - /// OID `1.1.1.270000000` encoded as ASN.1 BER/DER - const EXAMPLE_LONG_OID_BER: &[u8] = &hex!("29 01 81 80 DF BF 00"); + const EXAMPLE_OID_BER: &[u8] = &hex!("2A8648CE3D0201"); #[test] fn base128_byte() { @@ -170,14 +167,4 @@ mod tests { let encoder = encoder.arc(1).unwrap(); assert_eq!(&encoder.bytes[..encoder.cursor], EXAMPLE_OID_BER); } - - #[test] - fn encode_large() { - let encoder = Encoder::<7>::new(); - let encoder = encoder.arc(1).unwrap(); - let encoder = encoder.arc(1).unwrap(); - let encoder = encoder.arc(1).unwrap(); - let encoder = encoder.arc(270000000).unwrap(); - assert_eq!(&encoder.bytes[..encoder.cursor], EXAMPLE_LONG_OID_BER); - } }