Merge pull request #51 from ebfe/deprecated

Fix deprecation warnings
This commit is contained in:
Steven Fackler 2014-09-23 11:40:25 -07:00
commit f3786e3e00
2 changed files with 34 additions and 29 deletions

View File

@ -91,10 +91,10 @@ mod tests {
fn test_hmac_md5() { fn test_hmac_md5() {
// test vectors from RFC 2202 // test vectors from RFC 2202
let tests: [(Vec<u8>, Vec<u8>, Vec<u8>), ..7] = [ let tests: [(Vec<u8>, Vec<u8>, Vec<u8>), ..7] = [
(Vec::from_elem(16, 0x0b_u8), Vec::from_slice(b"Hi There"), (Vec::from_elem(16, 0x0b_u8), b"Hi There".to_vec(),
"9294727a3638bb1c13f48ef8158bfc9d".from_hex().unwrap()), "9294727a3638bb1c13f48ef8158bfc9d".from_hex().unwrap()),
(Vec::from_slice(b"Jefe"), (b"Jefe".to_vec(),
Vec::from_slice(b"what do ya want for nothing?"), b"what do ya want for nothing?".to_vec(),
"750c783e6ab0b503eaa86e310a5db738".from_hex().unwrap()), "750c783e6ab0b503eaa86e310a5db738".from_hex().unwrap()),
(Vec::from_elem(16, 0xaa_u8), Vec::from_elem(50, 0xdd_u8), (Vec::from_elem(16, 0xaa_u8), Vec::from_elem(50, 0xdd_u8),
"56be34521d144c88dbb8c733f0e8b3f6".from_hex().unwrap()), "56be34521d144c88dbb8c733f0e8b3f6".from_hex().unwrap()),
@ -102,14 +102,14 @@ mod tests {
Vec::from_elem(50, 0xcd_u8), Vec::from_elem(50, 0xcd_u8),
"697eaf0aca3a3aea3a75164746ffaa79".from_hex().unwrap()), "697eaf0aca3a3aea3a75164746ffaa79".from_hex().unwrap()),
(Vec::from_elem(16, 0x0c_u8), (Vec::from_elem(16, 0x0c_u8),
Vec::from_slice(b"Test With Truncation"), b"Test With Truncation".to_vec(),
"56461ef2342edc00f9bab995690efd4c".from_hex().unwrap()), "56461ef2342edc00f9bab995690efd4c".from_hex().unwrap()),
(Vec::from_elem(80, 0xaa_u8), (Vec::from_elem(80, 0xaa_u8),
Vec::from_slice(b"Test Using Larger Than Block-Size Key - Hash Key First"), b"Test Using Larger Than Block-Size Key - Hash Key First".to_vec(),
"6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd".from_hex().unwrap()), "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd".from_hex().unwrap()),
(Vec::from_elem(80, 0xaa_u8), (Vec::from_elem(80, 0xaa_u8),
Vec::from_slice(b"Test Using Larger Than Block-Size Key \ b"Test Using Larger Than Block-Size Key \
and Larger Than One Block-Size Data"), and Larger Than One Block-Size Data".to_vec(),
"6f630fad67cda0ee1fb1f562db3aa53e".from_hex().unwrap()) "6f630fad67cda0ee1fb1f562db3aa53e".from_hex().unwrap())
]; ];
@ -124,10 +124,10 @@ mod tests {
fn test_hmac_sha1() { fn test_hmac_sha1() {
// test vectors from RFC 2202 // test vectors from RFC 2202
let tests: [(Vec<u8>, Vec<u8>, Vec<u8>), ..7] = [ let tests: [(Vec<u8>, Vec<u8>, Vec<u8>), ..7] = [
(Vec::from_elem(20, 0x0b_u8), Vec::from_slice(b"Hi There"), (Vec::from_elem(20, 0x0b_u8), b"Hi There".to_vec(),
"b617318655057264e28bc0b6fb378c8ef146be00".from_hex().unwrap()), "b617318655057264e28bc0b6fb378c8ef146be00".from_hex().unwrap()),
(Vec::from_slice(b"Jefe"), (b"Jefe".to_vec(),
Vec::from_slice(b"what do ya want for nothing?"), b"what do ya want for nothing?".to_vec(),
"effcdf6ae5eb2fa2d27416d5f184df9c259a7c79".from_hex().unwrap()), "effcdf6ae5eb2fa2d27416d5f184df9c259a7c79".from_hex().unwrap()),
(Vec::from_elem(20, 0xaa_u8), Vec::from_elem(50, 0xdd_u8), (Vec::from_elem(20, 0xaa_u8), Vec::from_elem(50, 0xdd_u8),
"125d7342b9ac11cd91a39af48aa17b4f63f175d3".from_hex().unwrap()), "125d7342b9ac11cd91a39af48aa17b4f63f175d3".from_hex().unwrap()),
@ -135,14 +135,14 @@ mod tests {
Vec::from_elem(50, 0xcd_u8), Vec::from_elem(50, 0xcd_u8),
"4c9007f4026250c6bc8414f9bf50c86c2d7235da".from_hex().unwrap()), "4c9007f4026250c6bc8414f9bf50c86c2d7235da".from_hex().unwrap()),
(Vec::from_elem(20, 0x0c_u8), (Vec::from_elem(20, 0x0c_u8),
Vec::from_slice(b"Test With Truncation"), b"Test With Truncation".to_vec(),
"4c1a03424b55e07fe7f27be1d58bb9324a9a5a04".from_hex().unwrap()), "4c1a03424b55e07fe7f27be1d58bb9324a9a5a04".from_hex().unwrap()),
(Vec::from_elem(80, 0xaa_u8), (Vec::from_elem(80, 0xaa_u8),
Vec::from_slice(b"Test Using Larger Than Block-Size Key - Hash Key First"), b"Test Using Larger Than Block-Size Key - Hash Key First".to_vec(),
"aa4ae5e15272d00e95705637ce8a3b55ed402112".from_hex().unwrap()), "aa4ae5e15272d00e95705637ce8a3b55ed402112".from_hex().unwrap()),
(Vec::from_elem(80, 0xaa_u8), (Vec::from_elem(80, 0xaa_u8),
Vec::from_slice(b"Test Using Larger Than Block-Size Key \ b"Test Using Larger Than Block-Size Key \
and Larger Than One Block-Size Data"), and Larger Than One Block-Size Data".to_vec(),
"e8e99d0f45237d786d6bbaa7965c7808bbff1a91".from_hex().unwrap()) "e8e99d0f45237d786d6bbaa7965c7808bbff1a91".from_hex().unwrap())
]; ];
@ -156,18 +156,18 @@ mod tests {
fn test_sha2(ty: HashType, results: &[Vec<u8>]) { fn test_sha2(ty: HashType, results: &[Vec<u8>]) {
// test vectors from RFC 4231 // test vectors from RFC 4231
let tests: [(Vec<u8>, Vec<u8>), ..6] = [ let tests: [(Vec<u8>, Vec<u8>), ..6] = [
(Vec::from_elem(20, 0x0b_u8), Vec::from_slice(b"Hi There")), (Vec::from_elem(20, 0x0b_u8), b"Hi There".to_vec()),
(Vec::from_slice(b"Jefe"), (b"Jefe".to_vec(),
Vec::from_slice(b"what do ya want for nothing?")), b"what do ya want for nothing?".to_vec()),
(Vec::from_elem(20, 0xaa_u8), Vec::from_elem(50, 0xdd_u8)), (Vec::from_elem(20, 0xaa_u8), Vec::from_elem(50, 0xdd_u8)),
("0102030405060708090a0b0c0d0e0f10111213141516171819".from_hex().unwrap(), ("0102030405060708090a0b0c0d0e0f10111213141516171819".from_hex().unwrap(),
Vec::from_elem(50, 0xcd_u8)), Vec::from_elem(50, 0xcd_u8)),
(Vec::from_elem(131, 0xaa_u8), (Vec::from_elem(131, 0xaa_u8),
Vec::from_slice(b"Test Using Larger Than Block-Size Key - Hash Key First")), b"Test Using Larger Than Block-Size Key - Hash Key First".to_vec()),
(Vec::from_elem(131, 0xaa_u8), (Vec::from_elem(131, 0xaa_u8),
Vec::from_slice(b"This is a test using a larger than block-size key and a \ b"This is a test using a larger than block-size key and a \
larger than block-size data. The key needs to be hashed \ larger than block-size data. The key needs to be hashed \
before being used by the HMAC algorithm.")) before being used by the HMAC algorithm.".to_vec())
]; ];
for (&(ref key, ref data), res) in tests.iter().zip(results.iter()) { for (&(ref key, ref data), res) in tests.iter().zip(results.iter()) {

View File

@ -174,9 +174,10 @@ impl Drop for Crypter {
pub fn encrypt(t: Type, key: &[u8], iv: Vec<u8>, data: &[u8]) -> Vec<u8> { pub fn encrypt(t: Type, key: &[u8], iv: Vec<u8>, data: &[u8]) -> Vec<u8> {
let c = Crypter::new(t); let c = Crypter::new(t);
c.init(Encrypt, key, iv); c.init(Encrypt, key, iv);
let r = c.update(data); let mut r = c.update(data);
let rest = c.final(); let rest = c.final();
r.append(rest.as_slice()) r.extend(rest.into_iter());
r
} }
/** /**
@ -186,9 +187,10 @@ pub fn encrypt(t: Type, key: &[u8], iv: Vec<u8>, data: &[u8]) -> Vec<u8> {
pub fn decrypt(t: Type, key: &[u8], iv: Vec<u8>, data: &[u8]) -> Vec<u8> { pub fn decrypt(t: Type, key: &[u8], iv: Vec<u8>, data: &[u8]) -> Vec<u8> {
let c = Crypter::new(t); let c = Crypter::new(t);
c.init(Decrypt, key, iv); c.init(Decrypt, key, iv);
let r = c.update(data); let mut r = c.update(data);
let rest = c.final(); let rest = c.final();
r.append(rest.as_slice()) r.extend(rest.into_iter());
r
} }
#[cfg(test)] #[cfg(test)]
@ -213,11 +215,13 @@ mod tests {
let c = super::Crypter::new(super::AES_256_ECB); let c = super::Crypter::new(super::AES_256_ECB);
c.init(super::Encrypt, k0.as_slice(), vec![]); c.init(super::Encrypt, k0.as_slice(), vec![]);
c.pad(false); c.pad(false);
let r0 = c.update(p0.as_slice()).append(c.final().as_slice()); let mut r0 = c.update(p0.as_slice());
r0.extend(c.final().into_iter());
assert!(r0 == c0); assert!(r0 == c0);
c.init(super::Decrypt, k0.as_slice(), vec![]); c.init(super::Decrypt, k0.as_slice(), vec![]);
c.pad(false); c.pad(false);
let p1 = c.update(r0.as_slice()).append(c.final().as_slice()); let mut p1 = c.update(r0.as_slice());
p1.extend(c.final().into_iter());
assert!(p1 == p0); assert!(p1 == p0);
} }
@ -227,8 +231,9 @@ mod tests {
let cipher = super::Crypter::new(ciphertype); let cipher = super::Crypter::new(ciphertype);
cipher.init(super::Encrypt, key.from_hex().unwrap().as_slice(), iv.from_hex().unwrap()); cipher.init(super::Encrypt, key.from_hex().unwrap().as_slice(), iv.from_hex().unwrap());
let expected = Vec::from_slice(ct.from_hex().unwrap().as_slice()); let expected = ct.from_hex().unwrap().as_slice().to_vec();
let computed = cipher.update(pt.from_hex().unwrap().as_slice()).append(cipher.final().as_slice()); let mut computed = cipher.update(pt.from_hex().unwrap().as_slice());
computed.extend(cipher.final().into_iter());
if computed != expected { if computed != expected {
println!("Computed: {}", computed.as_slice().to_hex()); println!("Computed: {}", computed.as_slice().to_hex());