From f945665c1056622debd08c122ca6bb70f1bb5a84 Mon Sep 17 00:00:00 2001 From: Dimitri Sabadie Date: Fri, 23 Aug 2019 21:24:48 +0200 Subject: [PATCH] Remove rustc_serialize. The crate has been deprecated for quite a while now. Time to move on. :) --- Cargo.toml | 3 ++- src/digest.rs | 4 +--- src/lib.rs | 3 ++- src/pbkdf2.rs | 14 ++++++-------- src/scrypt.rs | 16 +++++++--------- 5 files changed, 18 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8ea941a7..e1b90720 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/digest.rs b/src/digest.rs index f31dd9b6..e6405181 100644 --- a/src/digest.rs +++ b/src/digest.rs @@ -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 = repeat(0).take((self.output_bits()+7)/8).collect(); self.result(&mut buf); - buf[..].to_hex() + hex::encode(&buf) } } diff --git a/src/lib.rs b/src/lib.rs index 59ad3afb..135ba4ff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/pbkdf2.rs b/src/pbkdf2.rs index f21de48f..243f39b2 100644 --- a/src/pbkdf2.rs +++ b/src/pbkdf2.rs @@ -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; @@ -145,11 +143,11 @@ pub fn pbkdf2_simple(password: &str, c: u32) -> io::Result { 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) @@ -195,7 +193,7 @@ pub fn pbkdf2_check(password: &str, hashed_value: &str) -> Result match pstr.from_base64() { + Some(pstr) => match base64::decode(pstr) { Ok(pvec) => { if pvec.len() != 4 { return Err(ERR_STR); } read_u32_be(&pvec[..]) @@ -207,7 +205,7 @@ pub fn pbkdf2_check(password: &str, hashed_value: &str) -> Result match sstr.from_base64() { + Some(sstr) => match base64::decode(sstr) { Ok(salt) => salt, Err(_) => return Err(ERR_STR) }, @@ -216,7 +214,7 @@ pub fn pbkdf2_check(password: &str, hashed_value: &str) -> Result match hstr.from_base64() { + Some(hstr) => match base64::decode(hstr) { Ok(hash) => hash, Err(_) => return Err(ERR_STR) }, diff --git a/src/scrypt.rs b/src/scrypt.rs index 44920643..11372fda 100644 --- a/src/scrypt.rs +++ b/src/scrypt.rs @@ -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; @@ -287,19 +285,19 @@ pub fn scrypt_simple(password: &str, params: &ScryptParams) -> io::Result Result match pstr.from_base64() { + Some(pstr) => match base64::decode(pstr) { Ok(x) => x, Err(_) => return Err(ERR_STR) }, @@ -368,7 +366,7 @@ pub fn scrypt_check(password: &str, hashed_value: &str) -> Result match sstr.from_base64() { + Some(sstr) => match base64::decode(sstr) { Ok(salt) => salt, Err(_) => return Err(ERR_STR) }, @@ -377,7 +375,7 @@ pub fn scrypt_check(password: &str, hashed_value: &str) -> Result match hstr.from_base64() { + Some(hstr) => match base64::decode(hstr) { Ok(hash) => hash, Err(_) => return Err(ERR_STR) },