Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove rustc_serialize. #453

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ with-bench = []
gcc = "^0.3"

[dependencies]
base64 = "0.10"
libc = "^0.2"
hex = "0.3"
time = "^0.1"
rand = "^0.3"
rustc-serialize = "^0.3"
4 changes: 1 addition & 3 deletions src/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ pub trait Digest {
* String in hexadecimal format.
*/
fn result_str(&mut self) -> String {
use serialize::hex::ToHex;

let mut buf: Vec<u8> = repeat(0).take((self.output_bits()+7)/8).collect();
self.result(&mut buf);
buf[..].to_hex()
hex::encode(&buf)
}
}
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

#![cfg_attr(feature = "with-bench", feature(test))]

extern crate base64;
extern crate hex;
extern crate rand;
extern crate rustc_serialize as serialize;
extern crate time;
extern crate libc;

Expand Down
14 changes: 6 additions & 8 deletions src/pbkdf2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ use std::io;
use cryptoutil::copy_memory;

use rand::{OsRng, Rng};
use serialize::base64;
use serialize::base64::{FromBase64, ToBase64};

use cryptoutil::{read_u32_be, write_u32_be};
use hmac::Hmac;
Expand Down Expand Up @@ -145,11 +143,11 @@ pub fn pbkdf2_simple(password: &str, c: u32) -> io::Result<String> {
let mut result = "$rpbkdf2$0$".to_string();
let mut tmp = [0u8; 4];
write_u32_be(&mut tmp, c);
result.push_str(&tmp.to_base64(base64::STANDARD)[..]);
result.push_str(&base64::encode(&tmp));
result.push('$');
result.push_str(&salt.to_base64(base64::STANDARD)[..]);
result.push_str(&base64::encode(&salt));
result.push('$');
result.push_str(&dk.to_base64(base64::STANDARD)[..]);
result.push_str(&base64::encode(&dk));
result.push('$');

Ok(result)
Expand Down Expand Up @@ -195,7 +193,7 @@ pub fn pbkdf2_check(password: &str, hashed_value: &str) -> Result<bool, &'static

// Parse the iteration count
let c = match iter.next() {
Some(pstr) => match pstr.from_base64() {
Some(pstr) => match base64::decode(pstr) {
Ok(pvec) => {
if pvec.len() != 4 { return Err(ERR_STR); }
read_u32_be(&pvec[..])
Expand All @@ -207,7 +205,7 @@ pub fn pbkdf2_check(password: &str, hashed_value: &str) -> Result<bool, &'static

// Salt
let salt = match iter.next() {
Some(sstr) => match sstr.from_base64() {
Some(sstr) => match base64::decode(sstr) {
Ok(salt) => salt,
Err(_) => return Err(ERR_STR)
},
Expand All @@ -216,7 +214,7 @@ pub fn pbkdf2_check(password: &str, hashed_value: &str) -> Result<bool, &'static

// Hashed value
let hash = match iter.next() {
Some(hstr) => match hstr.from_base64() {
Some(hstr) => match base64::decode(hstr) {
Ok(hash) => hash,
Err(_) => return Err(ERR_STR)
},
Expand Down
16 changes: 7 additions & 9 deletions src/scrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ use std::mem::size_of;
use cryptoutil::copy_memory;

use rand::{OsRng, Rng};
use serialize::base64;
use serialize::base64::{FromBase64, ToBase64};

use cryptoutil::{read_u32_le, read_u32v_le, write_u32_le};
use hmac::Hmac;
Expand Down Expand Up @@ -287,19 +285,19 @@ pub fn scrypt_simple(password: &str, params: &ScryptParams) -> io::Result<String
tmp[0] = params.log_n;
tmp[1] = params.r as u8;
tmp[2] = params.p as u8;
result.push_str(&*tmp.to_base64(base64::STANDARD));
result.push_str(&base64::encode(&tmp));
} else {
result.push_str("1$");
let mut tmp = [0u8; 9];
tmp[0] = params.log_n;
write_u32_le(&mut tmp[1..5], params.r);
write_u32_le(&mut tmp[5..9], params.p);
result.push_str(&*tmp.to_base64(base64::STANDARD));
result.push_str(&base64::encode(&tmp));
}
result.push('$');
result.push_str(&*salt.to_base64(base64::STANDARD));
result.push_str(&base64::encode(&salt));
result.push('$');
result.push_str(&*dk.to_base64(base64::STANDARD));
result.push_str(&base64::encode(&dk));
result.push('$');

Ok(result)
Expand Down Expand Up @@ -339,7 +337,7 @@ pub fn scrypt_check(password: &str, hashed_value: &str) -> Result<bool, &'static
// Parse the parameters - the size of them depends on the if we are using the compact or
// expanded format
let pvec = match iter.next() {
Some(pstr) => match pstr.from_base64() {
Some(pstr) => match base64::decode(pstr) {
Ok(x) => x,
Err(_) => return Err(ERR_STR)
},
Expand Down Expand Up @@ -368,7 +366,7 @@ pub fn scrypt_check(password: &str, hashed_value: &str) -> Result<bool, &'static

// Salt
let salt = match iter.next() {
Some(sstr) => match sstr.from_base64() {
Some(sstr) => match base64::decode(sstr) {
Ok(salt) => salt,
Err(_) => return Err(ERR_STR)
},
Expand All @@ -377,7 +375,7 @@ pub fn scrypt_check(password: &str, hashed_value: &str) -> Result<bool, &'static

// Hashed value
let hash = match iter.next() {
Some(hstr) => match hstr.from_base64() {
Some(hstr) => match base64::decode(hstr) {
Ok(hash) => hash,
Err(_) => return Err(ERR_STR)
},
Expand Down