Skip to content

Commit 71f8420

Browse files
committed
Rename crypto::hash::HashType -> Type
s/HashType/Type/ to follow the current Rust style. Import Type as HashType in modules where the name might be ambiguous. [breaking change]
1 parent eb7b7bf commit 71f8420

File tree

6 files changed

+49
-47
lines changed

6 files changed

+49
-47
lines changed

src/crypto/hash.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use ffi;
66

77
/// Message digest (hash) type.
88
#[derive(Copy)]
9-
pub enum HashType {
9+
pub enum Type {
1010
MD5,
1111
SHA1,
1212
SHA224,
@@ -16,11 +16,11 @@ pub enum HashType {
1616
RIPEMD160
1717
}
1818

19-
impl HashType {
19+
impl Type {
2020
/// Returns the length of the message digest.
2121
#[inline]
2222
pub fn md_len(&self) -> usize {
23-
use self::HashType::*;
23+
use self::Type::*;
2424
match *self {
2525
MD5 => 16,
2626
SHA1 => 20,
@@ -36,7 +36,7 @@ impl HashType {
3636
#[inline]
3737
pub fn evp_md(&self) -> *const ffi::EVP_MD {
3838
unsafe {
39-
use self::HashType::*;
39+
use self::Type::*;
4040
match *self {
4141
MD5 => ffi::EVP_md5(),
4242
SHA1 => ffi::EVP_sha1(),
@@ -66,21 +66,21 @@ use self::State::*;
6666
/// Calculate a hash in one go.
6767
///
6868
/// ```
69-
/// use openssl::crypto::hash::{hash, HashType};
69+
/// use openssl::crypto::hash::{hash, Type};
7070
/// let data = b"\x42\xF4\x97\xE0";
7171
/// let spec = b"\x7c\x43\x0f\x17\x8a\xef\xdf\x14\x87\xfe\xe7\x14\x4e\x96\x41\xe2";
72-
/// let res = hash(HashType::MD5, data);
72+
/// let res = hash(Type::MD5, data);
7373
/// assert_eq!(res, spec);
7474
/// ```
7575
///
7676
/// Use the `Writer` trait to supply the input in chunks.
7777
///
7878
/// ```
7979
/// use std::old_io::Writer;
80-
/// use openssl::crypto::hash::{Hasher, HashType};
80+
/// use openssl::crypto::hash::{Hasher, Type};
8181
/// let data = [b"\x42\xF4", b"\x97\xE0"];
8282
/// let spec = b"\x7c\x43\x0f\x17\x8a\xef\xdf\x14\x87\xfe\xe7\x14\x4e\x96\x41\xe2";
83-
/// let mut h = Hasher::new(HashType::MD5);
83+
/// let mut h = Hasher::new(Type::MD5);
8484
/// h.write_all(data[0]);
8585
/// h.write_all(data[1]);
8686
/// let res = h.finish();
@@ -95,13 +95,13 @@ use self::State::*;
9595
pub struct Hasher {
9696
ctx: *mut ffi::EVP_MD_CTX,
9797
md: *const ffi::EVP_MD,
98-
type_: HashType,
98+
type_: Type,
9999
state: State,
100100
}
101101

102102
impl Hasher {
103103
/// Creates a new `Hasher` with the specified hash type.
104-
pub fn new(ty: HashType) -> Hasher {
104+
pub fn new(ty: Type) -> Hasher {
105105
ffi::init();
106106

107107
let ctx = unsafe {
@@ -203,7 +203,7 @@ impl Drop for Hasher {
203203
}
204204

205205
/// Computes the hash of the `data` with the hash `t`.
206-
pub fn hash(t: HashType, data: &[u8]) -> Vec<u8> {
206+
pub fn hash(t: Type, data: &[u8]) -> Vec<u8> {
207207
let mut h = Hasher::new(t);
208208
let _ = h.write_all(data);
209209
h.finish()
@@ -212,10 +212,10 @@ pub fn hash(t: HashType, data: &[u8]) -> Vec<u8> {
212212
#[cfg(test)]
213213
mod tests {
214214
use serialize::hex::{FromHex, ToHex};
215-
use super::{hash, Hasher, HashType};
215+
use super::{hash, Hasher, Type};
216216
use std::old_io::Writer;
217217

218-
fn hash_test(hashtype: HashType, hashtest: &(&str, &str)) {
218+
fn hash_test(hashtype: Type, hashtest: &(&str, &str)) {
219219
let res = hash(hashtype, &*hashtest.0.from_hex().unwrap());
220220
assert_eq!(res.to_hex(), hashtest.1);
221221
}
@@ -247,25 +247,25 @@ mod tests {
247247
#[test]
248248
fn test_md5() {
249249
for test in md5_tests.iter() {
250-
hash_test(HashType::MD5, test);
250+
hash_test(Type::MD5, test);
251251
}
252252
}
253253

254254
#[test]
255255
fn test_md5_recycle() {
256-
let mut h = Hasher::new(HashType::MD5);
256+
let mut h = Hasher::new(Type::MD5);
257257
for test in md5_tests.iter() {
258258
hash_recycle_test(&mut h, test);
259259
}
260260
}
261261

262262
#[test]
263263
fn test_finish_twice() {
264-
let mut h = Hasher::new(HashType::MD5);
264+
let mut h = Hasher::new(Type::MD5);
265265
let _ = h.write_all(&*md5_tests[6].0.from_hex().unwrap());
266266
let _ = h.finish();
267267
let res = h.finish();
268-
let null = hash(HashType::MD5, &[]);
268+
let null = hash(Type::MD5, &[]);
269269
assert_eq!(res, null);
270270
}
271271

@@ -275,7 +275,7 @@ mod tests {
275275
let inp = md5_tests[i].0.from_hex().unwrap();
276276
assert!(inp.len() > 2);
277277
let p = inp.len() / 2;
278-
let h0 = Hasher::new(HashType::MD5);
278+
let h0 = Hasher::new(Type::MD5);
279279

280280
println!("Clone a new hasher");
281281
let mut h1 = h0.clone();
@@ -305,7 +305,7 @@ mod tests {
305305
];
306306

307307
for test in tests.iter() {
308-
hash_test(HashType::SHA1, test);
308+
hash_test(Type::SHA1, test);
309309
}
310310
}
311311

@@ -316,7 +316,7 @@ mod tests {
316316
];
317317

318318
for test in tests.iter() {
319-
hash_test(HashType::SHA256, test);
319+
hash_test(Type::SHA256, test);
320320
}
321321
}
322322

@@ -327,7 +327,7 @@ mod tests {
327327
];
328328

329329
for test in tests.iter() {
330-
hash_test(HashType::RIPEMD160, test);
330+
hash_test(Type::RIPEMD160, test);
331331
}
332332
}
333333
}

src/crypto/hmac.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use libc::{c_int, c_uint};
1818
use std::iter::repeat;
1919
use std::old_io::{IoError, Writer};
2020

21-
use crypto::hash::HashType;
21+
use crypto::hash::Type;
2222
use ffi;
2323

2424
#[derive(PartialEq, Copy)]
@@ -37,39 +37,39 @@ use self::State::*;
3737
/// Calculate a HMAC in one go.
3838
///
3939
/// ```
40-
/// use openssl::crypto::hash::HashType;
40+
/// use openssl::crypto::hash::Type;
4141
/// use openssl::crypto::hmac::hmac;
4242
/// let key = b"Jefe";
4343
/// let data = b"what do ya want for nothing?";
4444
/// let spec = b"\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7\x38";
45-
/// let res = hmac(HashType::MD5, key, data);
45+
/// let res = hmac(Type::MD5, key, data);
4646
/// assert_eq!(spec, res);
4747
/// ```
4848
///
4949
/// Use the `Writer` trait to supply the input in chunks.
5050
///
5151
/// ```
52-
/// use openssl::crypto::hash::HashType;
5352
/// use std::old_io::Writer;
53+
/// use openssl::crypto::hash::Type;
5454
/// use openssl::crypto::hmac::HMAC;
5555
/// let key = b"Jefe";
5656
/// let data = [b"what do ya ", b"want for nothing?"];
5757
/// let spec = b"\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7\x38";
58-
/// let mut h = HMAC::new(HashType::MD5, &*key);
58+
/// let mut h = HMAC::new(Type::MD5, &*key);
5959
/// h.write_all(data[0]);
6060
/// h.write_all(data[1]);
6161
/// let res = h.finish();
6262
/// assert_eq!(spec, res);
6363
/// ```
6464
pub struct HMAC {
6565
ctx: ffi::HMAC_CTX,
66-
type_: HashType,
66+
type_: Type,
6767
state: State,
6868
}
6969

7070
impl HMAC {
7171
/// Creates a new `HMAC` with the specified hash type using the `key`.
72-
pub fn new(ty: HashType, key: &[u8]) -> HMAC {
72+
pub fn new(ty: Type, key: &[u8]) -> HMAC {
7373
ffi::init();
7474

7575
let ctx = unsafe {
@@ -185,7 +185,7 @@ impl Drop for HMAC {
185185
}
186186

187187
/// Computes the HMAC of the `data` with the hash `t` and `key`.
188-
pub fn hmac(t: HashType, key: &[u8], data: &[u8]) -> Vec<u8> {
188+
pub fn hmac(t: Type, key: &[u8], data: &[u8]) -> Vec<u8> {
189189
let mut h = HMAC::new(t, key);
190190
let _ = h.write_all(data);
191191
h.finish()
@@ -195,12 +195,12 @@ pub fn hmac(t: HashType, key: &[u8], data: &[u8]) -> Vec<u8> {
195195
mod tests {
196196
use std::iter::repeat;
197197
use serialize::hex::FromHex;
198-
use crypto::hash::HashType;
199-
use crypto::hash::HashType::*;
198+
use crypto::hash::Type;
199+
use crypto::hash::Type::*;
200200
use super::{hmac, HMAC};
201201
use std::old_io::Writer;
202202

203-
fn test_hmac(ty: HashType, tests: &[(Vec<u8>, Vec<u8>, Vec<u8>)]) {
203+
fn test_hmac(ty: Type, tests: &[(Vec<u8>, Vec<u8>, Vec<u8>)]) {
204204
for &(ref key, ref data, ref res) in tests.iter() {
205205
assert_eq!(hmac(ty, &**key, &**data), *res);
206206
}
@@ -267,11 +267,11 @@ mod tests {
267267
b"Test Using Larger Than Block-Size Key - Hash Key First".to_vec(),
268268
"6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd".from_hex().unwrap());
269269

270-
let mut h = HMAC::new(HashType::MD5, &*test.0);
270+
let mut h = HMAC::new(Type::MD5, &*test.0);
271271
let _ = h.write_all(&*test.1);
272272
let _ = h.finish();
273273
let res = h.finish();
274-
let null = hmac(HashType::MD5, &*test.0, &[]);
274+
let null = hmac(Type::MD5, &*test.0, &[]);
275275
assert_eq!(res, null);
276276
}
277277

@@ -287,7 +287,7 @@ mod tests {
287287
"6f630fad67cda0ee1fb1f562db3aa53e".from_hex().unwrap()),
288288
];
289289
let p = tests[0].0.len() / 2;
290-
let h0 = HMAC::new(HashType::MD5, &*tests[0].0);
290+
let h0 = HMAC::new(Type::MD5, &*tests[0].0);
291291

292292
println!("Clone a new hmac");
293293
let mut h1 = h0.clone();
@@ -360,7 +360,7 @@ mod tests {
360360

361361

362362

363-
fn test_sha2(ty: HashType, results: &[Vec<u8>]) {
363+
fn test_sha2(ty: Type, results: &[Vec<u8>]) {
364364
// test vectors from RFC 4231
365365
let tests: [(Vec<u8>, Vec<u8>); 6] = [
366366
(repeat(0xb_u8).take(20).collect(), b"Hi There".to_vec()),

src/crypto/pkey.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use std::iter::repeat;
33
use std::mem;
44
use std::ptr;
55
use bio::{MemBio};
6-
use crypto::hash::HashType;
6+
use crypto::hash;
7+
use crypto::hash::Type as HashType;
78
use ffi;
89
use ssl::error::{SslError, StreamError};
910

@@ -276,7 +277,7 @@ impl PKey {
276277
*/
277278
pub fn verify(&self, m: &[u8], s: &[u8]) -> bool { self.verify_with_hash(m, s, HashType::SHA256) }
278279

279-
pub fn sign_with_hash(&self, s: &[u8], hash: HashType) -> Vec<u8> {
280+
pub fn sign_with_hash(&self, s: &[u8], hash: hash::Type) -> Vec<u8> {
280281
unsafe {
281282
let rsa = ffi::EVP_PKEY_get1_RSA(self.evp);
282283
let len = ffi::RSA_size(rsa);
@@ -300,7 +301,7 @@ impl PKey {
300301
}
301302
}
302303

303-
pub fn verify_with_hash(&self, m: &[u8], s: &[u8], hash: HashType) -> bool {
304+
pub fn verify_with_hash(&self, m: &[u8], s: &[u8], hash: hash::Type) -> bool {
304305
unsafe {
305306
let rsa = ffi::EVP_PKEY_get1_RSA(self.evp);
306307

@@ -332,7 +333,7 @@ impl Drop for PKey {
332333

333334
#[cfg(test)]
334335
mod tests {
335-
use crypto::hash::HashType::{MD5, SHA1};
336+
use crypto::hash::Type::{MD5, SHA1};
336337

337338
#[test]
338339
fn test_gen_pub() {

src/ssl/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::old_io::net::tcp::TcpStream;
33
use std::old_io::{Writer};
44
use std::thread::Thread;
55

6-
use crypto::hash::HashType::{SHA256};
6+
use crypto::hash::Type::{SHA256};
77
use ssl::SslMethod::Sslv23;
88
use ssl::{SslContext, SslStream, VerifyCallback};
99
use ssl::SslVerifyMode::SslVerifyPeer;

src/x509/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use std::ptr;
88

99
use asn1::{Asn1Time};
1010
use bio::{MemBio};
11-
use crypto::hash::{HashType};
11+
use crypto::hash;
12+
use crypto::hash::Type as HashType;
1213
use crypto::pkey::{PKey};
1314
use crypto::rand::rand_bytes;
1415
use ffi;
@@ -152,14 +153,14 @@ impl<'a, T: AsStr<'a>> ToStr for Vec<T> {
152153
/// use std::old_io::{File, Open, Write};
153154
/// # use std::old_io::fs;
154155
///
155-
/// use openssl::crypto::hash::HashType;
156+
/// use openssl::crypto::hash::Type;
156157
/// use openssl::x509::{KeyUsage, X509Generator};
157158
///
158159
/// let gen = X509Generator::new()
159160
/// .set_bitlength(2048)
160161
/// .set_valid_period(365*2)
161162
/// .set_CN("SuperMegaCorp Inc.")
162-
/// .set_sign_hash(HashType::SHA256)
163+
/// .set_sign_hash(Type::SHA256)
163164
/// .set_usage(&[KeyUsage::DigitalSignature]);
164165
///
165166
/// let (cert, pkey) = gen.generate().unwrap();
@@ -236,7 +237,7 @@ impl X509Generator {
236237
self
237238
}
238239

239-
pub fn set_sign_hash(mut self, hash_type: HashType) -> X509Generator {
240+
pub fn set_sign_hash(mut self, hash_type: hash::Type) -> X509Generator {
240241
self.hash_type = hash_type;
241242
self
242243
}
@@ -387,7 +388,7 @@ impl<'ctx> X509<'ctx> {
387388
}
388389

389390
/// Returns certificate fingerprint calculated using provided hash
390-
pub fn fingerprint(&self, hash_type: HashType) -> Option<Vec<u8>> {
391+
pub fn fingerprint(&self, hash_type: hash::Type) -> Option<Vec<u8>> {
391392
let evp = hash_type.evp_md();
392393
let len = hash_type.md_len();
393394
let v: Vec<u8> = repeat(0).take(len as usize).collect();

src/x509/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use serialize::hex::FromHex;
22
use std::old_io::{File, Open, Read};
33
use std::old_io::util::NullWriter;
44

5-
use crypto::hash::HashType::{SHA256};
5+
use crypto::hash::Type::{SHA256};
66
use x509::{X509, X509Generator};
77
use x509::KeyUsage::{DigitalSignature, KeyEncipherment};
88
use x509::ExtKeyUsage::{ClientAuth, ServerAuth};

0 commit comments

Comments
 (0)