Skip to content

Commit

Permalink
fix: dependency crates
Browse files Browse the repository at this point in the history
  • Loading branch information
dishmaker committed Oct 8, 2024
1 parent 1d35881 commit 79c4776
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 119 deletions.
2 changes: 1 addition & 1 deletion der/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub(crate) mod pem;
pub(crate) mod slice;

use crate::{
asn1::{AnyCustomClassExplicit, AnyCustomClassImplicit, ContextSpecificExplicit},
asn1::{AnyCustomClassExplicit, AnyCustomClassImplicit},
Class, Decode, DecodeValue, Encode, EncodingRules, Error, ErrorKind, FixedTag, Header, Length,
Tag, TagMode, TagNumber,
};
Expand Down
5 changes: 1 addition & 4 deletions der/src/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ mod mode;
mod number;

pub use self::{class::Class, mode::TagMode, number::TagNumber};
pub use self::{
class::CLASS_APPLICATION, class::CLASS_CONTEXT_SPECIFIC, class::CLASS_PRIVATE,
class::CLASS_UNIVERSAL,
};
pub use self::{class::CLASS_APPLICATION, class::CLASS_CONTEXT_SPECIFIC, class::CLASS_PRIVATE};

use crate::{Decode, DerOrd, Encode, Error, ErrorKind, Length, Reader, Result, Writer};
use core::{cmp::Ordering, fmt};
Expand Down
29 changes: 17 additions & 12 deletions der_derive/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,25 +228,30 @@ impl FieldAttrs {
..
} = class.to_tokens(type_params, self.tag_mode);

let context_specific =
if self.tag_mode == TagMode::Implicit || self.extensible || self.is_optional() {
quote! {
#class_type::decode_skipping(
reader
)?
}
} else {
quote! {
#class_type::decode(reader)?
}
};
// let context_specific =
// if self.tag_mode == TagMode::Implicit || self.extensible || self.is_optional() {
// quote! {
// #class_type::decode_skipping(
// reader
// )?
// }
// } else {
// quote! {
// #class_type::decode_skipping(reader)?
// }
// };
let context_specific = quote! { #class_type::decode_skipping(reader)? };

if self.is_optional() {
if let Some(default) = &self.default {
quote!(#context_specific.map(|cs| cs.value).unwrap_or_else(#default))
} else {
quote!(#context_specific.map(|cs| cs.value))
}
// }else{
// quote!(#context_specific.map(|cs| cs.value))
// }
//}
} else {
// TODO(tarcieri): better error handling?
let constructed = self.constructed;
Expand Down
6 changes: 3 additions & 3 deletions der_derive/src/sequence/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ mod tests {
quote! {
let implicit_field = ::der::asn1::ContextSpecific::<>::decode_implicit(
reader,
::der::TagNumber::N0
::der::TagNumber(0)
)?
.ok_or_else(|| {
der::Tag::ContextSpecific {
number: ::der::TagNumber::N0,
number: ::der::TagNumber(0),
constructed: false
}
.value_error()
Expand All @@ -342,7 +342,7 @@ mod tests {
field.to_encode_tokens().to_string(),
quote! {
::der::asn1::ContextSpecificRef {
tag_number: ::der::TagNumber::N0,
tag_number: ::der::TagNumber(0),
tag_mode: ::der::TagMode::Implicit,
value: &self.implicit_field,
}
Expand Down
4 changes: 2 additions & 2 deletions gss-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ mod tests {
AnyRef::new(
Tag::ContextSpecific {
constructed: true,
number: TagNumber::N0
number: TagNumber(0)
},
&inner_bytes
)
Expand All @@ -153,7 +153,7 @@ mod tests {
inner_context_token: AnyRef::new(
Tag::ContextSpecific {
constructed: true,
number: TagNumber::N0,
number: TagNumber(0),
},
&inner_bytes,
)
Expand Down
70 changes: 30 additions & 40 deletions pkcs1/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::{Error, Result};
use der::{
asn1::{AnyRef, ContextSpecificRef, ObjectIdentifier},
asn1::{AnyRef, ContextSpecificExplicitRef, ObjectIdentifier},
oid::AssociatedOid,
Decode, DecodeValue, Encode, EncodeValue, FixedTag, Length, Reader, Sequence, Tag, TagMode,
TagNumber, Writer,
Expand Down Expand Up @@ -117,51 +117,46 @@ impl<'a> RsaPssParams<'a> {
}
}

fn context_specific_hash(&self) -> Option<ContextSpecificRef<'_, AlgorithmIdentifierRef<'a>>> {
fn context_specific_hash(
&self,
) -> Option<ContextSpecificExplicitRef<'_, 0, AlgorithmIdentifierRef<'a>>> {
if self.hash == SHA_1_AI {
None
} else {
Some(ContextSpecificRef {
tag_number: TagNumber::N0,
tag_mode: TagMode::Explicit,
value: &self.hash,
})
Some(ContextSpecificExplicitRef { value: &self.hash })
}
}

fn context_specific_mask_gen(
&self,
) -> Option<ContextSpecificRef<'_, AlgorithmIdentifier<AlgorithmIdentifierRef<'a>>>> {
) -> Option<ContextSpecificExplicitRef<'_, 1, AlgorithmIdentifier<AlgorithmIdentifierRef<'a>>>>
{
if self.mask_gen == default_mgf1_sha1() {
None
} else {
Some(ContextSpecificRef {
tag_number: TagNumber::N1,
tag_mode: TagMode::Explicit,
Some(ContextSpecificExplicitRef {
value: &self.mask_gen,
})
}
}

fn context_specific_salt_len(&self) -> Option<ContextSpecificRef<'_, u8>> {
fn context_specific_salt_len(&self) -> Option<ContextSpecificExplicitRef<'_, 2, u8>> {
if self.salt_len == RsaPssParams::SALT_LEN_DEFAULT {
None
} else {
Some(ContextSpecificRef {
tag_number: TagNumber::N2,
tag_mode: TagMode::Explicit,
Some(ContextSpecificExplicitRef {
value: &self.salt_len,
})
}
}

fn context_specific_trailer_field(&self) -> Option<ContextSpecificRef<'_, TrailerField>> {
fn context_specific_trailer_field(
&self,
) -> Option<ContextSpecificExplicitRef<'_, 3, TrailerField>> {
if self.trailer_field == TrailerField::default() {
None
} else {
Some(ContextSpecificRef {
tag_number: TagNumber::N3,
tag_mode: TagMode::Explicit,
Some(ContextSpecificExplicitRef {
value: &self.trailer_field,
})
}
Expand All @@ -186,16 +181,16 @@ impl<'a> DecodeValue<'a> for RsaPssParams<'a> {
reader.read_nested(header.length, |reader| {
Ok(Self {
hash: reader
.context_specific(TagNumber::N0, TagMode::Explicit)?
.context_specific(TagNumber(0), TagMode::Explicit)?
.unwrap_or(SHA_1_AI),
mask_gen: reader
.context_specific(TagNumber::N1, TagMode::Explicit)?
.context_specific(TagNumber(1), TagMode::Explicit)?
.unwrap_or_else(default_mgf1_sha1),
salt_len: reader
.context_specific(TagNumber::N2, TagMode::Explicit)?
.context_specific(TagNumber(2), TagMode::Explicit)?
.unwrap_or(RsaPssParams::SALT_LEN_DEFAULT),
trailer_field: reader
.context_specific(TagNumber::N3, TagMode::Explicit)?
.context_specific(TagNumber(3), TagMode::Explicit)?
.unwrap_or_default(),
})
})
Expand Down Expand Up @@ -294,41 +289,36 @@ impl<'a> RsaOaepParams<'a> {
}
}

fn context_specific_hash(&self) -> Option<ContextSpecificRef<'_, AlgorithmIdentifierRef<'a>>> {
fn context_specific_hash(
&self,
) -> Option<ContextSpecificExplicitRef<'_, 0, AlgorithmIdentifierRef<'a>>> {
if self.hash == SHA_1_AI {
None
} else {
Some(ContextSpecificRef {
tag_number: TagNumber::N0,
tag_mode: TagMode::Explicit,
value: &self.hash,
})
Some(ContextSpecificExplicitRef { value: &self.hash })
}
}

fn context_specific_mask_gen(
&self,
) -> Option<ContextSpecificRef<'_, AlgorithmIdentifier<AlgorithmIdentifierRef<'a>>>> {
) -> Option<ContextSpecificExplicitRef<'_, 1, AlgorithmIdentifier<AlgorithmIdentifierRef<'a>>>>
{
if self.mask_gen == default_mgf1_sha1() {
None
} else {
Some(ContextSpecificRef {
tag_number: TagNumber::N1,
tag_mode: TagMode::Explicit,
Some(ContextSpecificExplicitRef {
value: &self.mask_gen,
})
}
}

fn context_specific_p_source(
&self,
) -> Option<ContextSpecificRef<'_, AlgorithmIdentifierRef<'a>>> {
) -> Option<ContextSpecificExplicitRef<'_, 2, AlgorithmIdentifierRef<'a>>> {
if self.p_source == default_pempty_string() {
None
} else {
Some(ContextSpecificRef {
tag_number: TagNumber::N2,
tag_mode: TagMode::Explicit,
Some(ContextSpecificExplicitRef {
value: &self.p_source,
})
}
Expand All @@ -351,13 +341,13 @@ impl<'a> DecodeValue<'a> for RsaOaepParams<'a> {
reader.read_nested(header.length, |reader| {
Ok(Self {
hash: reader
.context_specific(TagNumber::N0, TagMode::Explicit)?
.context_specific(TagNumber(0), TagMode::Explicit)?
.unwrap_or(SHA_1_AI),
mask_gen: reader
.context_specific(TagNumber::N1, TagMode::Explicit)?
.context_specific(TagNumber(1), TagMode::Explicit)?
.unwrap_or_else(default_mgf1_sha1),
p_source: reader
.context_specific(TagNumber::N2, TagMode::Explicit)?
.context_specific(TagNumber(2), TagMode::Explicit)?
.unwrap_or_else(default_pempty_string),
})
})
Expand Down
14 changes: 2 additions & 12 deletions pkcs12/src/safe_bag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,7 @@ impl ::der::EncodeValue for SafeBag {
use ::der::Encode as _;
[
self.bag_id.encoded_len()?,
::der::asn1::ContextSpecificRef {
tag_number: ::der::TagNumber::N0,
tag_mode: ::der::TagMode::Explicit,
value: &content,
}
.encoded_len()?,
::der::asn1::ContextSpecificExplicitRef::<0, _> { value: &content }.encoded_len()?,
self.bag_attributes.encoded_len()?,
]
.into_iter()
Expand All @@ -79,12 +74,7 @@ impl ::der::EncodeValue for SafeBag {
use ::der::Encode as _;
self.bag_id.encode(writer)?;
let content = AnyRef::from_der(&self.bag_value)?;
::der::asn1::ContextSpecificRef {
tag_number: ::der::TagNumber::N0,
tag_mode: ::der::TagMode::Explicit,
value: &content,
}
.encode(writer)?;
::der::asn1::ContextSpecificExplicitRef::<0, _> { value: &content }.encode(writer)?;
self.bag_attributes.encode(writer)?;
Ok(())
}
Expand Down
18 changes: 9 additions & 9 deletions pkcs12/tests/cert_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use const_oid::db::{
rfc5912::ID_SHA_256,
};
use der::{
asn1::{ContextSpecific, OctetString},
asn1::{ContextSpecificExplicit, OctetString},
Decode, Encode,
};
use hex_literal::hex;
Expand Down Expand Up @@ -199,8 +199,8 @@ fn decode_sample_pfx() {
for cert_bag in cert_bags {
match cert_bag.bag_id {
pkcs12::PKCS_12_CERT_BAG_OID => {
let cs: der::asn1::ContextSpecific<CertBag> =
ContextSpecific::from_der(&cert_bag.bag_value).unwrap();
let cs: der::asn1::ContextSpecificExplicit<CertBag> =
ContextSpecificExplicit::from_der(&cert_bag.bag_value).unwrap();
let cb = cs.value;
assert_eq!(
include_bytes!("examples/cert.der"),
Expand Down Expand Up @@ -242,8 +242,8 @@ fn decode_sample_pfx() {
for safe_bag in safe_bags {
match safe_bag.bag_id {
pkcs12::PKCS_12_PKCS8_KEY_BAG_OID => {
let cs: ContextSpecific<EncryptedPrivateKeyInfoRef<'_>> =
ContextSpecific::from_der(&safe_bag.bag_value).unwrap();
let cs: ContextSpecificExplicit<EncryptedPrivateKeyInfoRef<'_>> =
ContextSpecificExplicit::from_der(&safe_bag.bag_value).unwrap();
let mut ciphertext = cs.value.encrypted_data.as_bytes().to_vec();
let plaintext = cs
.value
Expand Down Expand Up @@ -606,8 +606,8 @@ fn decode_sample_pfx2() {
for safe_bag in safe_bags {
match safe_bag.bag_id {
pkcs12::PKCS_12_CERT_BAG_OID => {
let cs: ContextSpecific<CertBag> =
ContextSpecific::from_der(&safe_bag.bag_value).unwrap();
let cs: ContextSpecificExplicit<CertBag> =
ContextSpecificExplicit::from_der(&safe_bag.bag_value).unwrap();
assert_eq!(
include_bytes!("examples/cert.der"),
cs.value.cert_value.as_bytes()
Expand All @@ -628,8 +628,8 @@ fn decode_sample_pfx2() {
for safe_bag in safe_bags {
match safe_bag.bag_id {
pkcs12::PKCS_12_PKCS8_KEY_BAG_OID => {
let cs: ContextSpecific<EncryptedPrivateKeyInfoRef<'_>> =
ContextSpecific::from_der(&safe_bag.bag_value).unwrap();
let cs: ContextSpecificExplicit<EncryptedPrivateKeyInfoRef<'_>> =
ContextSpecificExplicit::from_der(&safe_bag.bag_value).unwrap();
let mut ciphertext = cs.value.encrypted_data.as_bytes().to_vec();
let plaintext = cs
.value
Expand Down
Loading

0 comments on commit 79c4776

Please sign in to comment.