use crate::{
checked::CheckedSum, decode::Decode, encode::Encode, reader::Reader, writer::Writer, MPInt,
Result,
};
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub struct DsaPublicKey {
pub p: MPInt,
pub q: MPInt,
pub g: MPInt,
pub y: MPInt,
}
impl Decode for DsaPublicKey {
fn decode(reader: &mut impl Reader) -> Result<Self> {
let p = MPInt::decode(reader)?;
let q = MPInt::decode(reader)?;
let g = MPInt::decode(reader)?;
let y = MPInt::decode(reader)?;
Ok(Self { p, q, g, y })
}
}
impl Encode for DsaPublicKey {
fn encoded_len(&self) -> Result<usize> {
[
self.p.encoded_len()?,
self.q.encoded_len()?,
self.g.encoded_len()?,
self.y.encoded_len()?,
]
.checked_sum()
}
fn encode(&self, writer: &mut impl Writer) -> Result<()> {
self.p.encode(writer)?;
self.q.encode(writer)?;
self.g.encode(writer)?;
self.y.encode(writer)
}
}