ssh_key/public/
dsa.rs
1use crate::{
4 checked::CheckedSum, decode::Decode, encode::Encode, reader::Reader, writer::Writer, MPInt,
5 Result,
6};
7
8#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
12#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
13pub struct DsaPublicKey {
14 pub p: MPInt,
16
17 pub q: MPInt,
19
20 pub g: MPInt,
23
24 pub y: MPInt,
26}
27
28impl Decode for DsaPublicKey {
29 fn decode(reader: &mut impl Reader) -> Result<Self> {
30 let p = MPInt::decode(reader)?;
31 let q = MPInt::decode(reader)?;
32 let g = MPInt::decode(reader)?;
33 let y = MPInt::decode(reader)?;
34 Ok(Self { p, q, g, y })
35 }
36}
37
38impl Encode for DsaPublicKey {
39 fn encoded_len(&self) -> Result<usize> {
40 [
41 self.p.encoded_len()?,
42 self.q.encoded_len()?,
43 self.g.encoded_len()?,
44 self.y.encoded_len()?,
45 ]
46 .checked_sum()
47 }
48
49 fn encode(&self, writer: &mut impl Writer) -> Result<()> {
50 self.p.encode(writer)?;
51 self.q.encode(writer)?;
52 self.g.encode(writer)?;
53 self.y.encode(writer)
54 }
55}