Skip to content

Commit 19b57e4

Browse files
committed
fix: crates depending on context-specific and long TagNumber
1 parent fb96288 commit 19b57e4

File tree

4 files changed

+17
-24
lines changed

4 files changed

+17
-24
lines changed

pkcs12/tests/cert_tests.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use const_oid::db::{
44
rfc5912::ID_SHA_256,
55
};
66
use der::{
7-
asn1::{ContextSpecificExplicit, OctetString},
7+
asn1::{AnyCustomClassExplicit, OctetString},
88
Decode, Encode,
99
};
1010
use hex_literal::hex;
@@ -199,8 +199,7 @@ fn decode_sample_pfx() {
199199
for cert_bag in cert_bags {
200200
match cert_bag.bag_id {
201201
pkcs12::PKCS_12_CERT_BAG_OID => {
202-
let cs: der::asn1::ContextSpecificExplicit<CertBag> =
203-
ContextSpecificExplicit::from_der(&cert_bag.bag_value).unwrap();
202+
let cs = AnyCustomClassExplicit::<CertBag>::from_der(&cert_bag.bag_value).unwrap();
204203
let cb = cs.value;
205204
assert_eq!(
206205
include_bytes!("examples/cert.der"),
@@ -242,8 +241,10 @@ fn decode_sample_pfx() {
242241
for safe_bag in safe_bags {
243242
match safe_bag.bag_id {
244243
pkcs12::PKCS_12_PKCS8_KEY_BAG_OID => {
245-
let cs: ContextSpecificExplicit<EncryptedPrivateKeyInfoRef<'_>> =
246-
ContextSpecificExplicit::from_der(&safe_bag.bag_value).unwrap();
244+
let cs = AnyCustomClassExplicit::<EncryptedPrivateKeyInfoRef<'_>>::from_der(
245+
&safe_bag.bag_value,
246+
)
247+
.unwrap();
247248
let mut ciphertext = cs.value.encrypted_data.as_bytes().to_vec();
248249
let plaintext = cs
249250
.value
@@ -606,8 +607,7 @@ fn decode_sample_pfx2() {
606607
for safe_bag in safe_bags {
607608
match safe_bag.bag_id {
608609
pkcs12::PKCS_12_CERT_BAG_OID => {
609-
let cs: ContextSpecificExplicit<CertBag> =
610-
ContextSpecificExplicit::from_der(&safe_bag.bag_value).unwrap();
610+
let cs = AnyCustomClassExplicit::<CertBag>::from_der(&safe_bag.bag_value).unwrap();
611611
assert_eq!(
612612
include_bytes!("examples/cert.der"),
613613
cs.value.cert_value.as_bytes()
@@ -628,8 +628,10 @@ fn decode_sample_pfx2() {
628628
for safe_bag in safe_bags {
629629
match safe_bag.bag_id {
630630
pkcs12::PKCS_12_PKCS8_KEY_BAG_OID => {
631-
let cs: ContextSpecificExplicit<EncryptedPrivateKeyInfoRef<'_>> =
632-
ContextSpecificExplicit::from_der(&safe_bag.bag_value).unwrap();
631+
let cs = AnyCustomClassExplicit::<EncryptedPrivateKeyInfoRef<'_>>::from_der(
632+
&safe_bag.bag_value,
633+
)
634+
.unwrap();
633635
let mut ciphertext = cs.value.encrypted_data.as_bytes().to_vec();
634636
let plaintext = cs
635637
.value

pkcs8/src/private_key_info.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
use crate::{Error, Result, Version};
44
use core::fmt;
55
use der::{
6-
asn1::{
7-
AnyRef, BitStringRef, ContextSpecificExplicit, ContextSpecificImplicit, OctetStringRef,
8-
},
6+
asn1::{AnyRef, BitStringRef, ContextSpecificImplicit, OctetStringRef},
97
Class, Decode, DecodeValue, Encode, EncodeValue, FixedTag, Header, Length, Reader, Sequence,
10-
TagMode, TagNumber, Tagged, Writer,
8+
TagNumber, Tagged, Writer,
119
};
1210
use spki::AlgorithmIdentifier;
1311

sec1/src/private_key.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
//!
66
//! <https://www.secg.org/sec1-v2.pdf>
77
8-
use crate::{parameters, EcParameters, Error, Result};
8+
use crate::{EcParameters, Error, Result};
99
use core::fmt;
1010
use der::{
1111
asn1::{BitStringRef, ContextSpecificExplicit, ContextSpecificExplicitRef, OctetStringRef},
12-
Decode, DecodeValue, Encode, EncodeValue, Header, Length, Reader, Sequence, Tag, TagMode,
13-
TagNumber, Writer,
12+
Decode, DecodeValue, Encode, EncodeValue, Header, Length, Reader, Sequence, Tag, Writer,
1413
};
1514

1615
#[cfg(all(feature = "alloc", feature = "zeroize"))]
@@ -33,15 +32,9 @@ const VERSION: u8 = 1;
3332
/// Context-specific tag number for the elliptic curve parameters.
3433
const EC_PARAMETERS_TAG: u16 = 0;
3534

36-
/// Context-specific tag number for the elliptic curve parameters.
37-
const EC_PARAMETERS_TAG_NUMBER: TagNumber = TagNumber::new(EC_PARAMETERS_TAG);
38-
3935
/// Context-specific tag number for the public key.
4036
const PUBLIC_KEY_TAG: u16 = 1;
4137

42-
/// Context-specific tag number for the public key.
43-
const PUBLIC_KEY_TAG_NUMBER: TagNumber = TagNumber::new(PUBLIC_KEY_TAG);
44-
4538
/// SEC1 elliptic curve private key.
4639
///
4740
/// Described in [SEC1: Elliptic Curve Cryptography (Version 2.0)]

x509-cert/tests/pkix_extensions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1160,9 +1160,9 @@ fn decode_idp() {
11601160
);
11611161

11621162
// Nonsensical tag where BIT STRING tag should be
1163-
let reason_flags = ReasonFlags::from_der(&hex!("FF03079F80"));
1163+
let reason_flags = ReasonFlags::from_der(&hex!("2503079F80"));
11641164
let err = reason_flags.err().unwrap();
1165-
assert_eq!(ErrorKind::TagNumberInvalid, err.kind());
1165+
assert_eq!(ErrorKind::TagUnknown { byte: 0x25 }, err.kind());
11661166

11671167
// INTEGER tag where BIT STRING expected
11681168
let reason_flags = ReasonFlags::from_der(&hex!("0203079F80"));

0 commit comments

Comments
 (0)