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
use bcder::{
decode::{Constructed, Source},
encode::{self, PrimitiveContent, Values},
Unsigned,
};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct RsaPublicKey {
pub modulus: Unsigned,
pub public_exponent: Unsigned,
}
impl RsaPublicKey {
pub fn take_from<S: Source>(cons: &mut Constructed<S>) -> Result<Self, S::Err> {
cons.take_sequence(|cons| {
let modulus = Unsigned::take_from(cons)?;
let public_exponent = Unsigned::take_from(cons)?;
Ok(Self {
modulus,
public_exponent,
})
})
}
pub fn encode_ref(&self) -> impl Values + '_ {
encode::sequence((self.modulus.encode(), self.public_exponent.encode()))
}
}