diff --git a/src/dsa/mod.rs b/src/dsa/mod.rs index 3b00a38..24d1c48 100644 --- a/src/dsa/mod.rs +++ b/src/dsa/mod.rs @@ -14,10 +14,10 @@ use cryptonum::unsigned::*; use rand::Rng; use rand::distributions::Standard; -pub struct DSAKeyPair +pub struct DSAKeyPair { - pub private: DSAPrivKey, - pub public: DSAPubKey + pub private: DSAPrivKey

, + pub public: DSAPubKey

} pub trait DSAKeyGeneration @@ -29,7 +29,7 @@ pub trait DSAKeyGeneration macro_rules! generate_dsa_pair { ($ptype: ident, $ltype: ident, $ntype: ident, $nbig: ident) => { - impl DSAKeyGeneration for DSAKeyPair<$ptype,$ltype,$ntype> + impl DSAKeyGeneration for DSAKeyPair<$ptype> { type Params = $ptype; diff --git a/src/dsa/private.rs b/src/dsa/private.rs index 326333b..84ec652 100644 --- a/src/dsa/private.rs +++ b/src/dsa/private.rs @@ -21,28 +21,28 @@ pub trait DSAPrivateKey { Hmac: Mac; } -pub struct DSAPrivKey +pub struct DSAPrivKey { pub(crate) params: Params, - pub(crate) x: N + pub(crate) x: Params::N } pub enum DSAPrivate { - DSA1024Private(DSAPrivKey), - DSA2048SmallPrivate(DSAPrivKey), - DSA2048Private(DSAPrivKey), - DSA3072Private(DSAPrivKey) + DSA1024Private(DSAPrivKey), + DSA2048SmallPrivate(DSAPrivKey), + DSA2048Private(DSAPrivKey), + DSA3072Private(DSAPrivKey) } macro_rules! privkey_impls { ($ptype: ident, $ltype: ident, $ntype: ident, $big: ident, $bigger: ident, $biggest: ident) => { - impl DSAPrivateKey for DSAPrivKey<$ptype,$ntype> + impl DSAPrivateKey for DSAPrivKey<$ptype> { type Params = $ptype; type L = $ltype; type N = $ntype; - fn new(params: $ptype, x: $ntype) -> DSAPrivKey<$ptype,$ntype> + fn new(params: $ptype, x: $ntype) -> DSAPrivKey<$ptype> { DSAPrivKey{ params, x } } @@ -155,7 +155,7 @@ macro_rules! generate_tests { let s = $nt::from_bytes(sbytes); let params = $params::new(p,g,q); - let private = DSAPrivKey::<$params,$nt>::new(params, x); + let private = DSAPrivKey::<$params>::new(params, x); let sig = match h { 224 => private.sign::(mbytes), 256 => private.sign::(mbytes), diff --git a/src/dsa/public.rs b/src/dsa/public.rs index 16916e7..8538d96 100644 --- a/src/dsa/public.rs +++ b/src/dsa/public.rs @@ -20,27 +20,27 @@ pub trait DSAPublicKey { where Hash: Digest; } -pub struct DSAPubKey { +pub struct DSAPubKey { pub(crate) params: Params, - pub(crate) y: L + pub(crate) y: Params::L } pub enum DSAPublic { - DSAPublicL1024N160(DSAPubKey), - DSAPublicL2048N224(DSAPubKey), - DSAPublicL2048N256(DSAPubKey), - DSAPublicL3072N256(DSAPubKey) + DSAPublicL1024N160(DSAPubKey), + DSAPublicL2048N224(DSAPubKey), + DSAPublicL2048N256(DSAPubKey), + DSAPublicL3072N256(DSAPubKey) } macro_rules! pubkey_impls { ($ptype: ident, $ltype: ident, $ntype: ident, $dbl: ident, $bdbl: ident) => { - impl DSAPublicKey for DSAPubKey<$ptype,$ltype> + impl DSAPublicKey for DSAPubKey<$ptype> { type Params = $ptype; type L = $ltype; type N = $ntype; - fn new(params: $ptype, y: $ltype) -> DSAPubKey<$ptype,$ltype> + fn new(params: $ptype, y: $ltype) -> DSAPubKey<$ptype> { DSAPubKey{ params, y } } @@ -80,7 +80,7 @@ macro_rules! pubkey_impls { } } - impl ToASN1 for DSAPubKey<$ptype,$ltype> { + impl ToASN1 for DSAPubKey<$ptype> { type Error = ASN1EncodeErr; fn to_asn1_class(&self, c: ASN1Class) @@ -136,7 +136,7 @@ macro_rules! generate_tests { let s = $nt::from_bytes(sbytes); let params = $params::new(p,g,q); - let public = DSAPubKey::<$params,$lt>::new(params, y); + let public = DSAPubKey::<$params>::new(params, y); let sig = DSASignature::<$nt>::new(r, s); match h { 224 => assert!(public.verify::(mbytes, &sig)), diff --git a/src/dsa/tests.rs b/src/dsa/tests.rs index 46d7770..f45fdb3 100644 --- a/src/dsa/tests.rs +++ b/src/dsa/tests.rs @@ -99,8 +99,8 @@ fn appendix_a21() { let params = L1024N160::new(p, g, q); let x = U192::from_bytes(&xbytes); let y = U1024::from_bytes(&ybytes); - let private = DSAPrivKey::new(params.clone(), x); - let public = DSAPubKey::::new(params.clone(), y); + let private = DSAPrivKey::::new(params.clone(), x); + let public = DSAPubKey::::new(params.clone(), y); // let sample: [u8; 6] = [115, 97, 109, 112, 108, 101]; // "sample", ASCII let test: [u8; 4] = [116, 101, 115, 116]; // "test", ASCII @@ -359,8 +359,8 @@ fn appendix_a22() { let params = L2048N256::new(p, g, q); let x = U256::from_bytes(&xbytes); let y = U2048::from_bytes(&ybytes); - let private = DSAPrivKey::::new(params.clone(), x); - let public = DSAPubKey::::new(params.clone(), y); + let private = DSAPrivKey::::new(params.clone(), x); + let public = DSAPubKey::::new(params.clone(), y); // let sample: [u8; 6] = [115, 97, 109, 112, 108, 101]; // "sample", ASCII let test: [u8; 4] = [116, 101, 115, 116]; // "test", ASCII diff --git a/src/ssh/mod.rs b/src/ssh/mod.rs index 740e4db..af445e2 100644 --- a/src/ssh/mod.rs +++ b/src/ssh/mod.rs @@ -31,7 +31,7 @@ pub trait SSHKey: Sized { } -impl SSHKey for DSAKeyPair { +impl SSHKey for DSAKeyPair { fn decode_ssh_private_key(x: &str) -> Result<(Self,String),SSHKeyParseError> { let bytes = parse_ssh_private_key_data(x)?; @@ -74,7 +74,7 @@ impl SSHKey for DSAKeyPair { let pubg = parse_openssh_number(&mut pubkey_cursor)?; let pubparams = L1024N160::new(pubp, pubg, pubq); let puby: U1024 = parse_openssh_number(&mut pubkey_cursor)?; - let pubkey = DSAPubKey::::new(pubparams.clone(), puby.clone()); + let pubkey = DSAPubKey::::new(pubparams.clone(), puby.clone()); // And now we can look at the private key! let mut privkey_cursor = Cursor::new(privkeys); @@ -99,7 +99,7 @@ impl SSHKey for DSAKeyPair { return Err(SSHKeyParseError::InconsistentPublicKeyValue); } - let privkey = DSAPrivKey::::new(pubparams, privx); + let privkey = DSAPrivKey::::new(pubparams, privx); let comment = parse_openssh_string(&mut privkey_cursor)?; for (idx,byte) in privkey_cursor.bytes().enumerate() { if ((idx+1) as u8) != byte? { @@ -161,7 +161,7 @@ fn read_dsa_examples() { for file in test_files.iter() { let path = format!("testdata/ssh/{}",file); - let mkeypair = DSAKeyPair::::read_ssh_private_key_file(path); + let mkeypair = DSAKeyPair::::read_ssh_private_key_file(path); match mkeypair { Err(e) => assert!(false, format!("reading error: {:?}", e)), Ok((keypair,comment)) => { @@ -173,7 +173,7 @@ fn read_dsa_examples() { match keypair.encode_ssh_private_key(&comment) { Err(e2) => assert!(false, format!("render error: {:?}", e2)), Ok(encodedstr) => { - match DSAKeyPair::::decode_ssh_private_key(&encodedstr) { + match DSAKeyPair::::decode_ssh_private_key(&encodedstr) { Err(e3) => assert!(false, format!("reparse error: {:?}", e3)), Ok((keypair2,comment2)) => { assert_eq!(keypair.public.params.p,keypair2.public.params.p,"failed to reparse key pair (p)"); diff --git a/src/x509/publickey.rs b/src/x509/publickey.rs index 358fa5b..e821111 100644 --- a/src/x509/publickey.rs +++ b/src/x509/publickey.rs @@ -174,7 +174,7 @@ fn decode_dsa_key(info: ASN1Block, key: &ASN1Block) -> Result::new(params, y); + let key = DSAPubKey::::new(params, y); let reskey = DSAPublic::DSAPublicL3072N256(key); return Ok(reskey); } @@ -195,7 +195,7 @@ fn decode_dsa_key(info: ASN1Block, key: &ASN1Block) -> Result::new(params, y); + let key = DSAPubKey::::new(params, y); let reskey = DSAPublic::DSAPublicL2048N256(key); return Ok(reskey); } @@ -213,7 +213,7 @@ fn decode_dsa_key(info: ASN1Block, key: &ASN1Block) -> Result::new(params, y); + let key = DSAPubKey::::new(params, y); let reskey = DSAPublic::DSAPublicL2048N224(key); return Ok(reskey); } @@ -233,7 +233,7 @@ fn decode_dsa_key(info: ASN1Block, key: &ASN1Block) -> Result::new(params, y); + let key = DSAPubKey::::new(params, y); let reskey = DSAPublic::DSAPublicL1024N160(key); return Ok(reskey); }