Skip to content

Commit

Permalink
ecdsa/pkcs8: Remove more as conversoins for ASN.1 tags.
Browse files Browse the repository at this point in the history
  • Loading branch information
briansmith committed Feb 18, 2024
1 parent fa98b49 commit 0562a36
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/ec/suite_b/ecdsa/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ fn format_rs_asn1(ops: &'static ScalarOps, r: &Scalar, s: &Scalar, out: &mut [u8
};
let value = &fixed[first_index..];

out[0] = der::Tag::Integer as u8;
out[0] = der::Tag::Integer.into();

// Lengths less than 128 are encoded in one byte.
assert!(value.len() < 128);
Expand All @@ -425,7 +425,7 @@ fn format_rs_asn1(ops: &'static ScalarOps, r: &Scalar, s: &Scalar, out: &mut [u8
2 + value.len()
}

out[0] = der::Tag::Sequence as u8;
out[0] = der::Tag::Sequence.into();
let r_tlv_len = format_integer_tlv(ops, r, &mut out[2..]);
let s_tlv_len = format_integer_tlv(ops, s, &mut out[2..][r_tlv_len..]);

Expand Down
25 changes: 13 additions & 12 deletions src/pkcs8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ fn unwrap_key__<'a>(
.map_err(|error::Unspecified| error::KeyRejected::invalid_encoding())?;

// Ignore any attributes that are present.
if input.peek(der::Tag::ContextSpecificConstructed0 as u8) {
if input.peek(der::Tag::ContextSpecificConstructed0.into()) {
let _ = der::expect_tag_and_get_value(input, der::Tag::ContextSpecificConstructed0)
.map_err(|error::Unspecified| error::KeyRejected::invalid_encoding())?;
}
Expand All @@ -153,17 +153,18 @@ fn unwrap_key__<'a>(
}

const INCORRECT_LEGACY: der::Tag = der::Tag::ContextSpecificConstructed1;
let result =
if options.accept_legacy_ed25519_public_key_tag && input.peek(INCORRECT_LEGACY as u8) {
der::nested(
input,
INCORRECT_LEGACY,
error::Unspecified,
der::bit_string_with_no_unused_bits,
)
} else {
der::bit_string_tagged_with_no_unused_bits(der::Tag::ContextSpecific1, input)
};
let result = if options.accept_legacy_ed25519_public_key_tag
&& input.peek(INCORRECT_LEGACY.into())
{
der::nested(
input,
INCORRECT_LEGACY,
error::Unspecified,
der::bit_string_with_no_unused_bits,
)
} else {
der::bit_string_tagged_with_no_unused_bits(der::Tag::ContextSpecific1, input)
};
let public_key =
result.map_err(|error::Unspecified| error::KeyRejected::invalid_encoding())?;
Some(public_key)
Expand Down

0 comments on commit 0562a36

Please sign in to comment.