1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
//! PKCS#1 OtherPrimeInfo support.
use der::{asn1::UIntBytes, Decodable, Decoder, Encodable, Sequence};
/// PKCS#1 OtherPrimeInfo as defined in [RFC 8017 Appendix 1.2].
///
/// ASN.1 structure containing an additional prime in a multi-prime RSA key.
///
/// ```text
/// OtherPrimeInfo ::= SEQUENCE {
/// prime INTEGER, -- ri
/// exponent INTEGER, -- di
/// coefficient INTEGER -- ti
/// }
/// ```
///
/// [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: UIntBytes<'a>,
/// Exponent: `d_i = d mod (r_i - 1)`.
pub exponent: UIntBytes<'a>,
/// CRT coefficient: `t_i = (r_1 * r_2 * ... * r_(i-1))^(-1) mod r_i`.
pub coefficient: UIntBytes<'a>,
}
impl<'a> Decodable<'a> for OtherPrimeInfo<'a> {
fn decode(decoder: &mut Decoder<'a>) -> der::Result<Self> {
decoder.sequence(|decoder| {
Ok(Self {
prime: decoder.decode()?,
exponent: decoder.decode()?,
coefficient: decoder.decode()?,
})
})
}
}
impl<'a> Sequence<'a> for OtherPrimeInfo<'a> {
fn fields<F, T>(&self, f: F) -> der::Result<T>
where
F: FnOnce(&[&dyn Encodable]) -> der::Result<T>,
{
f(&[&self.prime, &self.exponent, &self.coefficient])
}
}