From 8a7e604fbdafc340a3d69525eecb5e84b12aa4fd Mon Sep 17 00:00:00 2001 From: Adam Wick Date: Sat, 13 Apr 2019 21:15:29 -0700 Subject: [PATCH] Make sure RSA and ECDSA have KeyPair instances. --- src/ecdsa/mod.rs | 10 ++++++++++ src/rsa/mod.rs | 10 ++++++++-- src/ssh/frame.rs | 1 - 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/ecdsa/mod.rs b/src/ecdsa/mod.rs index e10c580..f6c21e7 100644 --- a/src/ecdsa/mod.rs +++ b/src/ecdsa/mod.rs @@ -13,6 +13,7 @@ use self::point::{ECCPoint,Point}; pub use self::private::ECCPrivateKey; pub use self::public::{ECDSAPublic,ECCPublicKey}; pub use self::public::{ECDSADecodeErr,ECDSAEncodeErr}; +use super::KeyPair; pub struct ECDSAKeyPair { pub public: ECCPublicKey, @@ -21,6 +22,15 @@ pub struct ECDSAKeyPair { macro_rules! generate_impl { ($curve: ident, $un: ident, $si: ident) => { + impl KeyPair for ECDSAKeyPair<$curve> { + type Public = ECCPublicKey<$curve>; + type Private = ECCPrivateKey<$curve>; + + fn new(public: ECCPublicKey<$curve>, private: ECCPrivateKey<$curve>) -> ECDSAKeyPair<$curve> + { + ECDSAKeyPair{ public, private } + } + } impl ECDSAKeyPair<$curve> { pub fn generate(rng: &mut G) -> ECDSAKeyPair<$curve> { diff --git a/src/rsa/mod.rs b/src/rsa/mod.rs index 0221111..c2bf967 100644 --- a/src/rsa/mod.rs +++ b/src/rsa/mod.rs @@ -41,6 +41,7 @@ use cryptonum::unsigned::{CryptoNum,PrimeGen}; use cryptonum::unsigned::{U256,U512,U1024,U1536,U2048,U3072,U4096,U7680,U8192,U15360}; use rand::RngCore; use std::ops::Sub; +use super::KeyPair; fn diff(a: &T, b: &T) -> T where @@ -62,14 +63,19 @@ pub struct RSAKeyPair { macro_rules! generate_rsa_pair { ($uint: ident, $half: ident, $iterations: expr) => { - impl RSAKeyPair<$uint> { - pub fn new(pu: RSAPublicKey<$uint>, pr: RSAPrivateKey<$uint>) -> RSAKeyPair<$uint> { + impl KeyPair for RSAKeyPair<$uint> { + type Public = RSAPublicKey<$uint>; + type Private = RSAPrivateKey<$uint>; + + fn new(pu: RSAPublicKey<$uint>, pr: RSAPrivateKey<$uint>) -> RSAKeyPair<$uint> { RSAKeyPair { public: pu, private: pr } } + } + impl RSAKeyPair<$uint> { pub fn generate(rng: &mut G) -> RSAKeyPair<$uint> where G: RngCore { diff --git a/src/ssh/frame.rs b/src/ssh/frame.rs index 49ffaea..df566d0 100644 --- a/src/ssh/frame.rs +++ b/src/ssh/frame.rs @@ -94,7 +94,6 @@ pub fn render_openssh_u32(output: &mut O, val: u32) -> Result<(),SSHKe pub fn parse_openssh_string(input: &mut I) -> Result { let length = parse_openssh_u32(input)?; - println!("len: {:X}", length); let mut limited_input = input.take(length as u64); let mut result = String::new(); limited_input.read_to_string(&mut result)?;