tests work!

This commit is contained in:
DieMyst 2021-01-18 20:27:47 +03:00
parent 256cf96436
commit e8c109df99
3 changed files with 29 additions and 17 deletions

View File

@ -237,6 +237,7 @@ mod tests {
use super::*;
use crate::misc::current_time;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use crate::key_pair::KeyPair;
pub fn one_second() -> Duration {
Duration::from_secs(1)
@ -260,7 +261,7 @@ mod tests {
let new_cert = Certificate::issue(
&second_kp,
third_kp.key_pair.public(),
third_kp.key_pair.public,
&cert,
cur_time.checked_add(one_second()).unwrap(),
cur_time,
@ -287,7 +288,7 @@ mod tests {
let new_cert = Certificate::issue(
&second_kp,
third_kp.key_pair.public(),
third_kp.key_pair.public,
&cert,
cur_time.checked_add(one_second()).unwrap(),
cur_time,
@ -347,7 +348,7 @@ mod tests {
let new_cert = Certificate::issue(
&second_kp,
third_kp.key_pair.public(),
third_kp.key_pair.public,
&cert,
cur_time.checked_add(one_year()).unwrap(),
cur_time,
@ -358,18 +359,18 @@ mod tests {
println!(
"root_kp:\n\tprivate: {}\n\tpublic: {}",
bs58::encode(root_kp.key_pair.secret()).into_string(),
bs58::encode(&root_kp.key_pair.public().encode().to_vec()).into_string()
bs58::encode(root_kp.clone().key_pair.secret).into_string(),
bs58::encode(&root_kp.key_pair.public.to_bytes().to_vec()).into_string()
);
println!(
"second_kp:\n\tprivate: {}\n\tpublic: {}",
bs58::encode(second_kp.key_pair.secret()).into_string(),
bs58::encode(&second_kp.key_pair.public().encode().to_vec()).into_string()
bs58::encode(second_kp.clone().key_pair.secret).into_string(),
bs58::encode(&second_kp.key_pair.public.to_bytes().to_vec()).into_string()
);
println!(
"third_kp:\n\tprivate: {}\n\tpublic: {}",
bs58::encode(third_kp.key_pair.secret()).into_string(),
bs58::encode(&third_kp.key_pair.public().encode().to_vec()).into_string()
bs58::encode(third_kp.clone().key_pair.secret).into_string(),
bs58::encode(&third_kp.key_pair.public.to_bytes().to_vec()).into_string()
);
println!("cert is\n{}", new_cert.to_string());
@ -390,7 +391,7 @@ mod tests {
let new_cert = Certificate::issue(
&second_kp,
third_kp.key_pair.public(),
third_kp.key_pair.public,
&cert,
cur_time.checked_sub(one_second()).unwrap(),
cur_time.checked_sub(one_minute()).unwrap(),
@ -412,7 +413,7 @@ mod tests {
let new_cert = Certificate::issue(
&second_kp,
third_kp.key_pair.public(),
third_kp.key_pair.public,
&cert,
cur_time.checked_add(one_second()).unwrap(),
cur_time,
@ -421,7 +422,7 @@ mod tests {
.unwrap();
let new_cert = Certificate::issue(
&third_kp,
fourth_kp.key_pair.public(),
fourth_kp.key_pair.public,
&new_cert,
cur_time.checked_add(one_second()).unwrap(),
cur_time,
@ -450,7 +451,7 @@ mod tests {
let new_cert = Certificate::issue(
&second_kp,
third_kp.key_pair.public(),
third_kp.key_pair.public,
&cert,
cur_time.checked_add(one_second()).unwrap(),
cur_time,
@ -459,7 +460,7 @@ mod tests {
.unwrap();
let new_cert = Certificate::issue(
&second_kp,
fourth_kp.key_pair.public(),
fourth_kp.key_pair.public,
&new_cert,
cur_time.checked_add(one_second()).unwrap(),
cur_time,
@ -484,7 +485,7 @@ mod tests {
let bad_kp = KeyPair::generate();
let new_cert_bad = Certificate::issue(
&bad_kp,
bad_kp.key_pair.public(),
bad_kp.key_pair.public,
&cert,
cur_time.checked_add(one_second()).unwrap(),
cur_time,

View File

@ -16,7 +16,7 @@
use crate::ed25519::{Keypair as Libp2pKeyPair};
use ed25519_dalek::SignatureError;
use ed25519_dalek::{PublicKey, Signer};
use ed25519_dalek::{PublicKey, Signer, SecretKey};
use core::fmt::{Debug};
use std::fmt;
@ -134,3 +134,14 @@ impl<'de> serde::Deserialize<'de> for KeyPair {
deserializer.deserialize_str(KeyPairVisitor)
}
}
impl Clone for KeyPair {
fn clone(&self) -> KeyPair {
let mut sk_bytes = self.key_pair.secret.to_bytes();
let secret = SecretKey::from_bytes(&mut sk_bytes)
.expect("ed25519::SecretKey::from_bytes(to_bytes(k)) != k");
let public = PublicKey::from_bytes(&self.key_pair.public.to_bytes())
.expect("ed25519::PublicKey::from_bytes(to_bytes(k)) != k");
KeyPair { key_pair: ed25519_dalek::Keypair { secret, public } }
}
}

View File

@ -371,7 +371,7 @@ mod tests {
let st = Box::new(InMemoryStorage::new());
let mut graph = TrustGraph::new(st);
graph.add_root_weight(root.key_pair.public().into(), 0);
graph.add_root_weight(root.key_pair.public.into(), 0);
let addition = graph.add(cert, current_time());
assert_eq!(addition.is_ok(), true);