Guest User

Untitled

a guest
Nov 25th, 2022
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.17 KB | None | 0 0
  1. diff --git a/pkcs1/src/params.rs b/pkcs1/src/params.rs
  2. index b2080893f307..237c6fe5d504 100644
  3. --- a/pkcs1/src/params.rs
  4. +++ b/pkcs1/src/params.rs
  5. @@ -6,15 +6,12 @@ use der::{
  6.      asn1::ContextSpecificRef, Decode, DecodeValue, Encode, EncodeValue, FixedTag, Reader, Sequence,
  7.      Tag, TagMode, TagNumber, Writer,
  8.  };
  9. -use spki::AlgorithmIdentifierRef;
  10. +use spki::{AlgorithmIdentifier, AlgorithmIdentifierRef};
  11.  
  12.  const OID_SHA_1: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.3.14.3.2.26");
  13.  const OID_MGF_1: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.840.113549.1.1.8");
  14.  const OID_PSPECIFIED: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.840.113549.1.1.9");
  15.  
  16. -// TODO(tarcieri): make `AlgorithmIdentifier` generic around params; use `OID_SHA_1`
  17. -const SEQ_OID_SHA_1_DER: &[u8] = &[0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a];
  18. -
  19.  const SHA_1_AI: AlgorithmIdentifierRef<'_> = AlgorithmIdentifierRef {
  20.      oid: OID_SHA_1,
  21.      parameters: None,
  22. @@ -84,7 +81,7 @@ pub struct RsaPssParams<'a> {
  23.      pub hash: AlgorithmIdentifierRef<'a>,
  24.  
  25.      /// Mask Generation Function (MGF)
  26. -    pub mask_gen: AlgorithmIdentifierRef<'a>,
  27. +    pub mask_gen: AlgorithmIdentifier<AlgorithmIdentifierRef<'a>>,
  28.  
  29.      /// Salt length
  30.      pub salt_len: u8,
  31. @@ -180,13 +177,10 @@ impl<'a> TryFrom<&'a [u8]> for RsaPssParams<'a> {
  32.  }
  33.  
  34.  /// Default Mask Generation Function (MGF): SHA-1.
  35. -fn default_mgf1_sha1<'a>() -> AlgorithmIdentifierRef<'a> {
  36. -    AlgorithmIdentifierRef {
  37. +fn default_mgf1_sha1<'a>() -> AlgorithmIdentifier<AlgorithmIdentifierRef<'a>> {
  38. +    AlgorithmIdentifier::<AlgorithmIdentifierRef<'a>> {
  39.          oid: OID_MGF_1,
  40. -        parameters: Some(
  41. -            AnyRef::new(Tag::Sequence, SEQ_OID_SHA_1_DER)
  42. -                .expect("error creating default MGF1 params"),
  43. -        ),
  44. +        parameters: Some(SHA_1_AI),
  45.      }
  46.  }
  47.  
  48. @@ -211,7 +205,7 @@ pub struct RsaOaepParams<'a> {
  49.      pub hash: AlgorithmIdentifierRef<'a>,
  50.  
  51.      /// Mask Generation Function (MGF)
  52. -    pub mask_gen: AlgorithmIdentifierRef<'a>,
  53. +    pub mask_gen: AlgorithmIdentifier<AlgorithmIdentifierRef<'a>>,
  54.  
  55.      /// The source (and possibly the value) of the label L
  56.      pub p_source: AlgorithmIdentifierRef<'a>,
  57. diff --git a/pkcs1/tests/params.rs b/pkcs1/tests/params.rs
  58. index 6954934a8af0..597e263f079c 100644
  59. --- a/pkcs1/tests/params.rs
  60. +++ b/pkcs1/tests/params.rs
  61. @@ -1,10 +1,7 @@
  62.  //! PKCS#1 algorithm params tests
  63.  
  64.  use const_oid::db;
  65. -use der::{
  66. -    asn1::{ObjectIdentifier, OctetStringRef},
  67. -    Decode, Encode,
  68. -};
  69. +use der::{asn1::OctetStringRef, Encode};
  70.  use hex_literal::hex;
  71.  use pkcs1::{RsaOaepParams, RsaPssParams, TrailerField};
  72.  
  73. @@ -31,15 +28,12 @@ fn decode_pss_param() {
  74.          .mask_gen
  75.          .assert_algorithm_oid(db::rfc5912::ID_MGF_1)
  76.          .is_ok());
  77. -    assert_eq!(
  78. -        param
  79. -            .mask_gen
  80. -            .parameters_any()
  81. -            .unwrap()
  82. -            .sequence(|reader| Ok(ObjectIdentifier::decode(reader)?))
  83. -            .unwrap(),
  84. -        db::rfc5912::ID_SHA_256
  85. -    );
  86. +    assert!(param
  87. +        .mask_gen
  88. +        .parameters
  89. +        .unwrap()
  90. +        .assert_algorithm_oid(db::rfc5912::ID_SHA_256)
  91. +        .is_ok());
  92.      assert_eq!(param.salt_len, 32);
  93.      assert_eq!(param.trailer_field, TrailerField::BC);
  94.  }
  95. @@ -67,15 +61,12 @@ fn decode_pss_param_default() {
  96.          .mask_gen
  97.          .assert_algorithm_oid(db::rfc5912::ID_MGF_1)
  98.          .is_ok());
  99. -    assert_eq!(
  100. -        param
  101. -            .mask_gen
  102. -            .parameters_any()
  103. -            .unwrap()
  104. -            .sequence(|reader| Ok(ObjectIdentifier::decode(reader)?))
  105. -            .unwrap(),
  106. -        db::rfc5912::ID_SHA_1
  107. -    );
  108. +    assert!(param
  109. +        .mask_gen
  110. +        .parameters
  111. +        .unwrap()
  112. +        .assert_algorithm_oid(db::rfc5912::ID_SHA_1)
  113. +        .is_ok());
  114.      assert_eq!(param.salt_len, 20);
  115.      assert_eq!(param.trailer_field, TrailerField::BC);
  116.      assert_eq!(param, Default::default())
  117. @@ -103,15 +94,12 @@ fn decode_oaep_param() {
  118.          .mask_gen
  119.          .assert_algorithm_oid(db::rfc5912::ID_MGF_1)
  120.          .is_ok());
  121. -    assert_eq!(
  122. -        param
  123. -            .mask_gen
  124. -            .parameters_any()
  125. -            .unwrap()
  126. -            .sequence(|reader| Ok(ObjectIdentifier::decode(reader)?))
  127. -            .unwrap(),
  128. -        db::rfc5912::ID_SHA_256
  129. -    );
  130. +    assert!(param
  131. +        .mask_gen
  132. +        .parameters
  133. +        .unwrap()
  134. +        .assert_algorithm_oid(db::rfc5912::ID_SHA_256)
  135. +        .is_ok());
  136.      assert!(param
  137.          .p_source
  138.          .assert_algorithm_oid(db::rfc5912::ID_P_SPECIFIED)
  139. @@ -145,15 +133,12 @@ fn decode_oaep_param_default() {
  140.          .mask_gen
  141.          .assert_algorithm_oid(db::rfc5912::ID_MGF_1)
  142.          .is_ok());
  143. -    assert_eq!(
  144. -        param
  145. -            .mask_gen
  146. -            .parameters_any()
  147. -            .unwrap()
  148. -            .sequence(|reader| Ok(ObjectIdentifier::decode(reader)?))
  149. -            .unwrap(),
  150. -        db::rfc5912::ID_SHA_1
  151. -    );
  152. +    assert!(param
  153. +        .mask_gen
  154. +        .parameters
  155. +        .unwrap()
  156. +        .assert_algorithm_oid(db::rfc5912::ID_SHA_1)
  157. +        .is_ok());
  158.      assert!(param
  159.          .p_source
  160.          .assert_algorithm_oid(db::rfc5912::ID_P_SPECIFIED)
  161. diff --git a/spki/src/algorithm.rs b/spki/src/algorithm.rs
  162. index 6f76d6d35e76..5107ca58c3c2 100644
  163. --- a/spki/src/algorithm.rs
  164. +++ b/spki/src/algorithm.rs
  165. @@ -78,7 +78,7 @@ where
  166.  /// `AlgorithmIdentifier` reference which has `AnyRef` parameters.
  167.  pub type AlgorithmIdentifierRef<'a> = AlgorithmIdentifier<AnyRef<'a>>;
  168.  
  169. -impl<'a> AlgorithmIdentifierRef<'a> {
  170. +impl<Params> AlgorithmIdentifier<Params> {
  171.      /// Assert the `algorithm` OID is an expected value.
  172.      pub fn assert_algorithm_oid(&self, expected_oid: ObjectIdentifier) -> Result<ObjectIdentifier> {
  173.          if self.oid == expected_oid {
  174. @@ -87,7 +87,9 @@ impl<'a> AlgorithmIdentifierRef<'a> {
  175.              Err(Error::OidUnknown { oid: expected_oid })
  176.          }
  177.      }
  178. +}
  179.  
  180. +impl<'a> AlgorithmIdentifierRef<'a> {
  181.      /// Assert `parameters` is an OID and has the expected value.
  182.      pub fn assert_parameters_oid(
  183.          &self,
  184.  
Advertisement
Add Comment
Please, Sign In to add comment