aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/src/crypto/key_pair.rs2
-rw-r--r--p2p/src/tls_config.rs17
2 files changed, 19 insertions, 0 deletions
diff --git a/core/src/crypto/key_pair.rs b/core/src/crypto/key_pair.rs
index 899cb6a..efaae47 100644
--- a/core/src/crypto/key_pair.rs
+++ b/core/src/crypto/key_pair.rs
@@ -81,6 +81,7 @@ impl KeyPairExt for Ed25519KeyPair {
}
}
+#[derive(Debug)]
pub enum PublicKey {
Ed25519(Ed25519PublicKey),
}
@@ -114,6 +115,7 @@ trait PublicKeyExt {
fn verify(&self, msg: &[u8], signature: &[u8]) -> Result<()>;
}
+#[derive(Debug)]
pub struct Ed25519PublicKey(ed25519_dalek::VerifyingKey);
impl Ed25519PublicKey {
diff --git a/p2p/src/tls_config.rs b/p2p/src/tls_config.rs
index 2994bcf..5d5e90e 100644
--- a/p2p/src/tls_config.rs
+++ b/p2p/src/tls_config.rs
@@ -212,3 +212,20 @@ impl ClientCertVerifier for CliCertVerifier {
&[]
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn verify_generated_certificate() {
+ let key_pair = KeyPair::generate(&KeyPairType::Ed25519);
+ let (cert, _) = generate_cert(&key_pair).unwrap();
+
+ let result = verify_cert(&cert);
+ assert!(result.is_ok());
+ let peer_id = result.unwrap();
+ assert_eq!(peer_id, PeerID::try_from(key_pair.public()).unwrap());
+ assert_eq!(peer_id.0, key_pair.public().as_bytes());
+ }
+}