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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#[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 {}
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 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;
}