add std support, wording changes, code improvements

This commit is contained in:
satvrn 2023-07-19 21:50:47 +00:00
commit 2b559b79f9
7 changed files with 65 additions and 36 deletions

View file

@ -24,7 +24,7 @@ impl PartialEq for DhKeyPair {
impl Debug for DhKeyPair {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
f.debug_struct("DhKeyPair")
.field("private_key", &self.private_key.to_bytes())
.field("private_key", self.private_key.as_bytes())
.field("public_key", self.public_key.as_bytes())
.finish()
}
@ -38,7 +38,7 @@ impl Default for DhKeyPair {
impl DhKeyPair {
pub fn new() -> Self {
let secret = StaticSecret::random_from_rng(&mut OsRng);
let secret = StaticSecret::random_from_rng(OsRng);
let public = PublicKey::from(&secret);
DhKeyPair {
private_key: secret,
@ -58,11 +58,6 @@ pub fn gen_shared_secret() -> SharedSecret {
alice_pair.key_agreement(&bob_pair.public_key)
}
#[cfg(test)]
pub fn gen_key_pair() -> DhKeyPair {
DhKeyPair::new()
}
#[cfg(test)]
mod tests {
use crate::dh::DhKeyPair;