rust_sike/isogeny/
publickey.rs1use crate::ff::FiniteField;
4
5#[derive(Clone)]
10pub struct PublicKey<K: FiniteField> {
11 pub x1: K,
13
14 pub x2: K,
16
17 pub x3: K,
19}
20
21impl<K: FiniteField + std::fmt::Debug> std::fmt::Debug for PublicKey<K> {
22 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23 write!(f, "{:?}, {:?}, {:?}", self.x1, self.x2, self.x3)
24 }
25}
26
27impl<K: FiniteField> PublicKey<K> {
28 pub fn into_bytes(self) -> (Vec<u8>, Vec<u8>, Vec<u8>) {
30 (
31 self.x1.into_bytes(),
32 self.x2.into_bytes(),
33 self.x3.into_bytes(),
34 )
35 }
36
37 pub fn from_bytes(part1: &[u8], part2: &[u8], part3: &[u8]) -> Result<Self, String> {
39 Ok(Self {
40 x1: K::from_bytes(part1)?,
41 x2: K::from_bytes(part2)?,
42 x3: K::from_bytes(part3)?,
43 })
44 }
45}
46
47impl<K: FiniteField> std::cmp::PartialEq for PublicKey<K> {
48 fn eq(&self, other: &Self) -> bool {
49 self.x1.equals(&other.x1) && self.x2.equals(&other.x2) && self.x3.equals(&other.x3)
50 }
51}