diff options
Diffstat (limited to 'src/private_key/other_prime_info.rs')
-rw-r--r-- | src/private_key/other_prime_info.rs | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/src/private_key/other_prime_info.rs b/src/private_key/other_prime_info.rs index 8980aa1..35194a5 100644 --- a/src/private_key/other_prime_info.rs +++ b/src/private_key/other_prime_info.rs @@ -1,6 +1,8 @@ //! PKCS#1 OtherPrimeInfo support. -use der::{asn1::UIntRef, DecodeValue, Encode, Header, Reader, Sequence}; +use der::{ + asn1::UintRef, DecodeValue, Encode, EncodeValue, Header, Length, Reader, Sequence, Writer, +}; /// PKCS#1 OtherPrimeInfo as defined in [RFC 8017 Appendix 1.2]. /// @@ -16,16 +18,15 @@ use der::{asn1::UIntRef, DecodeValue, Encode, Header, Reader, Sequence}; /// /// [RFC 8017 Appendix 1.2]: https://datatracker.ietf.org/doc/html/rfc8017#appendix-A.1.2 #[derive(Clone)] -#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub struct OtherPrimeInfo<'a> { /// Prime factor `r_i` of `n`, where `i` >= 3. - pub prime: UIntRef<'a>, + pub prime: UintRef<'a>, /// Exponent: `d_i = d mod (r_i - 1)`. - pub exponent: UIntRef<'a>, + pub exponent: UintRef<'a>, /// CRT coefficient: `t_i = (r_1 * r_2 * ... * r_(i-1))^(-1) mod r_i`. - pub coefficient: UIntRef<'a>, + pub coefficient: UintRef<'a>, } impl<'a> DecodeValue<'a> for OtherPrimeInfo<'a> { @@ -40,11 +41,17 @@ impl<'a> DecodeValue<'a> for OtherPrimeInfo<'a> { } } -impl<'a> Sequence<'a> for OtherPrimeInfo<'a> { - fn fields<F, T>(&self, f: F) -> der::Result<T> - where - F: FnOnce(&[&dyn Encode]) -> der::Result<T>, - { - f(&[&self.prime, &self.exponent, &self.coefficient]) +impl EncodeValue for OtherPrimeInfo<'_> { + fn value_len(&self) -> der::Result<Length> { + self.prime.encoded_len()? + self.exponent.encoded_len()? + self.coefficient.encoded_len()? + } + + fn encode_value(&self, writer: &mut impl Writer) -> der::Result<()> { + self.prime.encode(writer)?; + self.exponent.encode(writer)?; + self.coefficient.encode(writer)?; + Ok(()) } } + +impl<'a> Sequence<'a> for OtherPrimeInfo<'a> {} |