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
use arrayvec::ArrayVec;
use serde::{Deserialize, Serialize};
use serde_big_array::BigArray;
use crate::{Config, Group};
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub struct PublicKey {
pub(crate) config: Config,
#[serde(with = "BigArray")]
pub(crate) key: [u8; 33],
}
impl PublicKey {
pub(crate) const fn new(config: Config, key: [u8; 33]) -> Self {
Self { config, key }
}
#[must_use]
pub const fn config(self) -> Config {
self.config
}
#[must_use]
pub fn to_bytes(&self) -> ArrayVec<u8, 33> {
let mut bytes = ArrayVec::from(self.key);
match self.config.group() {
Group::Ristretto255 => bytes.truncate(32),
#[cfg(feature = "p256")]
Group::P256 => bytes.truncate(33),
}
bytes
}
}