Lines
100 %
Functions
Branches
0 %
//! See [`PublicKeyExt`].
use curve25519_dalek::{montgomery::MontgomeryPoint, ristretto::RistrettoPoint};
use opaque_ke::keypair::PublicKey;
/// Utility trait to help convert and compare [`opaque_ke::keypair::PublicKey`]
/// to `[u8; 33]`.
pub(crate) trait PublicKeyExt {
/// Convert [`opaque_ke::keypair::PublicKey`] to `[u8; 33]`.
fn into_array(self) -> [u8; 33];
/// Convert [`opaque_ke::keypair::PublicKey`] reference to `[u8; 33]`.
fn to_array(&self) -> [u8; 33];
/// Compare [`opaque_ke::keypair::PublicKey`] to `[u8; 33]`.
fn is_array(&self, key: [u8; 33]) -> bool;
}
impl PublicKeyExt for PublicKey<RistrettoPoint> {
fn into_array(self) -> [u8; 33] {
Self::to_array(&self)
fn to_array(&self) -> [u8; 33] {
let mut key = [0; 33];
key[..32].copy_from_slice(self);
key
fn is_array(&self, key: [u8; 33]) -> bool {
&key[..32] == self.as_slice()
impl PublicKeyExt for PublicKey<MontgomeryPoint> {
#[cfg(feature = "p256")]
impl PublicKeyExt for PublicKey<super::p256::P256> {
(**self).into()
AsRef::<[u8; 33]>::as_ref(&***self).to_owned()
key == self.as_slice()