#[cfg(feature = "std")]
use std::borrow::Cow;
#[cfg(not(feature = "std"))]
use alloc::fmt::Display;
#[cfg(feature = "std")]
use std::fmt::Display;
#[cfg(not(feature = "std"))]
use alloc::fmt::Debug;
use rand_core::{CryptoRng, RngCore};
#[cfg(feature = "std")]
use std::fmt::Debug;
#[cfg(not(feature = "std"))]
use alloc::string::String;
use zeroize::Zeroize;
use crate::error::Error;
pub trait PublicKey: Debug + Display + Clone + Copy + PartialEq + Zeroize {
fn as_bytes(&self) -> &[u8];
}
pub trait SecretKey: Clone + Zeroize + Debug {
type PK: PublicKey;
fn to_public(&self) -> Self::PK;
}
pub trait SharedSecretKey: Clone + Zeroize + Debug {}
pub trait KeyPair: Clone + Zeroize {
type SK: SecretKey;
fn public(&self) -> &<Self::SK as SecretKey>::PK;
fn to_public(&self) -> <Self::SK as SecretKey>::PK;
fn secret(&self) -> &Self::SK;
}
pub trait Generate {
fn generate() -> Self;
fn generate_with<R: CryptoRng + RngCore>(csprng: R) -> Self
where
Self: Sized;
}
pub trait WithPhrase {
type E: Error;
fn generate_with_phrase(
word_count: usize,
password: Option<&str>,
) -> Result<(Self, String), Self::E>
where
Self: Sized;
fn from_phrase<'a, S: Into<Cow<'a, str>>>(
s: S,
password: Option<&str>,
) -> Result<Self, Self::E>
where
Self: Sized;
fn generate_in_with<R>(
rng: &mut R,
word_count: usize,
password: Option<&str>,
) -> Result<(Self, String), Self::E>
where
Self: Sized,
R: RngCore + CryptoRng;
}
pub trait FromEntropy {
type E: Error;
fn from_entropy(entropy: &[u8]) -> Result<Self, Self::E>
where
Self: Sized;
}
pub trait Blind {
type E: Error;
fn blind(&mut self, blinding_factor: &[u8]) -> Result<(), Self::E>;
fn to_blind(&self, blinding_factor: &[u8]) -> Result<Self, Self::E>
where
Self: Sized;
}