Skip to content

Commit

Permalink
dsa+ecdsa: support der custom error types (#809)
Browse files Browse the repository at this point in the history
Goes with this `formats` PR: RustCrypto/formats#1055
  • Loading branch information
turbocool3r authored Mar 3, 2024
1 parent 3bbea81 commit 31838b9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
22 changes: 14 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
2 changes: 2 additions & 0 deletions dsa/src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ impl Components {
}

impl<'a> DecodeValue<'a> for Components {
type Error = der::Error;

fn decode_value<R: Reader<'a>>(reader: &mut R, _header: Header) -> der::Result<Self> {
let p = reader.decode::<UintRef<'_>>()?;
let q = reader.decode::<UintRef<'_>>()?;
Expand Down
2 changes: 2 additions & 0 deletions dsa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ impl Signature {
}

impl<'a> DecodeValue<'a> for Signature {
type Error = der::Error;

fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> der::Result<Self> {
reader.read_nested(header.length, |reader| {
let r = UintRef::decode(reader)?;
Expand Down
4 changes: 3 additions & 1 deletion ecdsa/src/der.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ where
MaxSize<C>: ArraySize,
<FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArraySize,
{
type Error = der::Error;

fn decode<R: Reader<'a>>(reader: &mut R) -> der::Result<Self> {
let header = reader.peek_header()?;
header.tag.assert_eq(Tag::Sequence)?;
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 31838b9

Please sign in to comment.