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
use crate::{
decoder::{Decode, Decoder},
encoder::{Encode, Encoder},
MPInt, Result,
};
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub struct RsaPublicKey {
pub e: MPInt,
pub n: MPInt,
}
impl RsaPublicKey {
pub(super) fn checkint_bytes(&self) -> &[u8] {
self.n.as_bytes()
}
}
impl Decode for RsaPublicKey {
fn decode(decoder: &mut impl Decoder) -> Result<Self> {
let e = MPInt::decode(decoder)?;
let n = MPInt::decode(decoder)?;
Ok(Self { e, n })
}
}
impl Encode for RsaPublicKey {
fn encoded_len(&self) -> Result<usize> {
Ok(self.e.encoded_len()? + self.n.encoded_len()?)
}
fn encode(&self, encoder: &mut impl Encoder) -> Result<()> {
self.e.encode(encoder)?;
self.n.encode(encoder)
}
}