From 31838b9dcdc910045eae6912930e5b2aef4caa52 Mon Sep 17 00:00:00 2001 From: turbocool3r <60693357+turbocool3r@users.noreply.github.com> Date: Sun, 3 Mar 2024 22:26:29 +0400 Subject: [PATCH] dsa+ecdsa: support `der` custom error types (#809) Goes with this `formats` PR: RustCrypto/formats#1055 --- Cargo.lock | 22 ++++++++++++++-------- Cargo.toml | 7 +++++++ dsa/src/components.rs | 2 ++ dsa/src/lib.rs | 2 ++ ecdsa/src/der.rs | 4 +++- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3a406e08..2780b794 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -109,8 +109,7 @@ dependencies = [ [[package]] name = "der" version = "0.8.0-pre.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b489fd2221710c1dd46637d66b984161fb66134f81437a8489800306bcc2ecea" +source = "git+https://github.com/RustCrypto/formats.git?branch=master#270dbcb01ff75791d6527ff7759d335a39585420" dependencies = [ "const-oid 0.10.0-pre.2", "pem-rfc7468 1.0.0-pre.0", @@ -352,6 +351,15 @@ dependencies = [ "base64ct", ] +[[package]] +name = "pkcs5" +version = "0.8.0-pre.0" +source = "git+https://github.com/RustCrypto/formats.git?branch=master#270dbcb01ff75791d6527ff7759d335a39585420" +dependencies = [ + "der 0.8.0-pre.0", + "spki 0.8.0-pre.0", +] + [[package]] name = "pkcs8" version = "0.10.2" @@ -365,10 +373,10 @@ dependencies = [ [[package]] name = "pkcs8" version = "0.11.0-pre.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "935c09e0aecb0cb8f8907b57438b19a068cb74a25189b06724f061170b2465ff" +source = "git+https://github.com/RustCrypto/formats.git?branch=master#270dbcb01ff75791d6527ff7759d335a39585420" dependencies = [ "der 0.8.0-pre.0", + "pkcs5", "spki 0.8.0-pre.0", ] @@ -439,8 +447,7 @@ dependencies = [ [[package]] name = "sec1" version = "0.8.0-pre.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02dc081ed777a3bab68583b52ffb8221677b6e90d483b320963a247e2c07f328" +source = "git+https://github.com/RustCrypto/formats.git?branch=master#270dbcb01ff75791d6527ff7759d335a39585420" dependencies = [ "base16ct", "der 0.8.0-pre.0", @@ -557,8 +564,7 @@ dependencies = [ [[package]] name = "spki" version = "0.8.0-pre.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb2b56670f5ef52934c97efad30bf42585de0c33ec3e2a886e38b80d2db67243" +source = "git+https://github.com/RustCrypto/formats.git?branch=master#270dbcb01ff75791d6527ff7759d335a39585420" dependencies = [ "base64ct", "der 0.8.0-pre.0", diff --git a/Cargo.toml b/Cargo.toml index 267ffaee..763ddd65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,3 +10,10 @@ members = [ [profile.dev] opt-level = 2 + +[patch.crates-io] +der = { git = 'https://github.com/RustCrypto/formats.git', branch = 'master' } +spki = { git = 'https://github.com/RustCrypto/formats.git', branch = 'master' } +pkcs8 = { git = 'https://github.com/RustCrypto/formats.git', branch = 'master' } +pkcs5 = { git = 'https://github.com/RustCrypto/formats.git', branch = 'master' } +sec1 = { git = 'https://github.com/RustCrypto/formats.git', branch = 'master' } diff --git a/dsa/src/components.rs b/dsa/src/components.rs index b2450e2f..dbc708e9 100644 --- a/dsa/src/components.rs +++ b/dsa/src/components.rs @@ -63,6 +63,8 @@ impl Components { } impl<'a> DecodeValue<'a> for Components { + type Error = der::Error; + fn decode_value>(reader: &mut R, _header: Header) -> der::Result { let p = reader.decode::>()?; let q = reader.decode::>()?; diff --git a/dsa/src/lib.rs b/dsa/src/lib.rs index 3a0fa78b..89805fd3 100644 --- a/dsa/src/lib.rs +++ b/dsa/src/lib.rs @@ -110,6 +110,8 @@ impl Signature { } impl<'a> DecodeValue<'a> for Signature { + type Error = der::Error; + fn decode_value>(reader: &mut R, header: Header) -> der::Result { reader.read_nested(header.length, |reader| { let r = UintRef::decode(reader)?; diff --git a/ecdsa/src/der.rs b/ecdsa/src/der.rs index 085accc4..fea97642 100644 --- a/ecdsa/src/der.rs +++ b/ecdsa/src/der.rs @@ -203,6 +203,8 @@ where MaxSize: ArraySize, as Add>::Output: Add + ArraySize, { + type Error = der::Error; + fn decode>(reader: &mut R) -> der::Result { let header = reader.peek_header()?; header.tag.assert_eq(Tag::Sequence)?; @@ -360,7 +362,7 @@ fn decode_der(der_bytes: &[u8]) -> der::Result<(UintRef<'_>, UintRef<'_>)> { let header = der::Header::decode(&mut reader)?; header.tag.assert_eq(der::Tag::Sequence)?; - let ret = reader.read_nested(header.length, |reader| { + let ret = reader.read_nested::<_, _, der::Error>(header.length, |reader| { let r = UintRef::decode(reader)?; let s = UintRef::decode(reader)?; Ok((r, s))