1#[cfg(feature = "std")]
4use std::borrow::Cow;
5
6#[cfg(not(feature = "std"))]
7use alloc::fmt::Display;
8
9#[cfg(feature = "std")]
10use std::fmt::Display;
11
12#[cfg(not(feature = "std"))]
13use alloc::fmt::Debug;
14use rand_core::{CryptoRng, RngCore};
15
16#[cfg(feature = "std")]
17use std::fmt::Debug;
18
19#[cfg(not(feature = "std"))]
20use alloc::string::String;
21
22use zeroize::Zeroize;
23
24use crate::error::Error;
25
26pub trait PublicKey: Debug + Display + Clone + Copy + PartialEq + Zeroize {
28 fn as_bytes(&self) -> &[u8];
30}
31
32pub trait SecretKey: Clone + Zeroize + Debug {
34 type PK: PublicKey;
35
36 fn to_public(&self) -> Self::PK;
38}
39
40pub trait SharedSecretKey: Clone + Zeroize + Debug {}
42
43pub trait KeyPair: Clone + Zeroize {
45 type SK: SecretKey;
46
47 fn public(&self) -> &<Self::SK as SecretKey>::PK;
49
50 fn to_public(&self) -> <Self::SK as SecretKey>::PK;
52
53 fn secret(&self) -> &Self::SK;
55}
56
57pub trait Generate {
58 fn generate() -> Self;
60
61 fn generate_with<R: CryptoRng + RngCore>(csprng: R) -> Self
64 where
65 Self: Sized;
66}
67
68pub trait WithPhrase {
70 type E: Error;
71
72 fn generate_with_phrase(
76 word_count: usize,
77 password: Option<&str>,
78 ) -> Result<(Self, String), Self::E>
79 where
80 Self: Sized;
81
82 fn from_phrase<'a, S: Into<Cow<'a, str>>>(
84 s: S,
85 password: Option<&str>,
86 ) -> Result<Self, Self::E>
87 where
88 Self: Sized;
89
90 fn generate_in_with<R>(
94 rng: &mut R,
95 word_count: usize,
96 password: Option<&str>,
97 ) -> Result<(Self, String), Self::E>
98 where
99 Self: Sized,
100 R: RngCore + CryptoRng;
101}
102
103pub trait FromEntropy {
105 type E: Error;
106
107 fn from_entropy(entropy: &[u8]) -> Result<Self, Self::E>
111 where
112 Self: Sized;
113}
114
115pub trait Blind {
117 type E: Error;
118
119 fn blind(&mut self, blinding_factor: &[u8]) -> Result<(), Self::E>;
121
122 fn to_blind(&self, blinding_factor: &[u8]) -> Result<Self, Self::E>
124 where
125 Self: Sized;
126}