Compare commits
No commits in common. "bc2078fe2400290aefa36e15dda3cb214e7bd47d" and "431d286fd01c090a64c7f6a8d8777fd45acb54a9" have entirely different histories.
bc2078fe24
...
431d286fd0
1 changed files with 0 additions and 51 deletions
51
src/key.rs
51
src/key.rs
|
@ -15,10 +15,6 @@ pub struct PubKey {
|
|||
data: [u8; 32],
|
||||
}
|
||||
|
||||
pub struct PresharedKey {
|
||||
data: [u8; 32],
|
||||
}
|
||||
|
||||
impl Key for PrivKey {
|
||||
fn get_data(&self) -> [u8; 32] {
|
||||
self.data.to_owned()
|
||||
|
@ -31,12 +27,6 @@ impl Key for PubKey {
|
|||
}
|
||||
}
|
||||
|
||||
impl Key for PresharedKey {
|
||||
fn get_data(&self) -> [u8; 32] {
|
||||
self.data.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for dyn Key {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
|
@ -64,7 +54,6 @@ impl Display for PrivKey {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for PubKey {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
|
@ -79,28 +68,10 @@ impl Display for PubKey {
|
|||
}
|
||||
}
|
||||
|
||||
impl Display for PresharedKey {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
base64::engine::GeneralPurpose::new(
|
||||
&base64::alphabet::STANDARD,
|
||||
base64::engine::general_purpose::GeneralPurposeConfig::new()
|
||||
)
|
||||
.encode(self.get_data())
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl PrivKey {
|
||||
pub fn generate() -> Self {
|
||||
let mut buf: [u8; 32] = [0; 32];
|
||||
StdRng::from_entropy().fill_bytes(&mut buf);
|
||||
//Curve25519 clamping
|
||||
buf[0] &= 248;
|
||||
buf[31] &= 127;
|
||||
buf[31] |= 64;
|
||||
PrivKey { data: buf }
|
||||
}
|
||||
|
||||
|
@ -112,14 +83,6 @@ impl PrivKey {
|
|||
}
|
||||
}
|
||||
|
||||
impl PresharedKey {
|
||||
pub fn generate() -> Self {
|
||||
let mut buf: [u8; 32] = [0; 32];
|
||||
StdRng::from_entropy().fill_bytes(&mut buf);
|
||||
PresharedKey { data: buf }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<[u8; 32]> for PrivKey {
|
||||
fn from(value: [u8; 32]) -> Self {
|
||||
PrivKey { data: value }
|
||||
|
@ -134,20 +97,6 @@ impl From<&[u8; 32]> for PrivKey {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<[u8; 32]> for PresharedKey {
|
||||
fn from(value: [u8; 32]) -> Self {
|
||||
PresharedKey { data: value }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&[u8; 32]> for PresharedKey {
|
||||
fn from(value: &[u8; 32]) -> Self {
|
||||
PresharedKey {
|
||||
data: value.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_key_pair() -> (PrivKey, PubKey) {
|
||||
let privkey = PrivKey::generate();
|
||||
let pubkey = privkey.derive_pubkey();
|
||||
|
|
Loading…
Reference in a new issue