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

fix some important std unit tests that were not running due to typo #59

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 1 addition & 1 deletion src/internal_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ macro_rules! serde_string_impl {
where
D: $crate::serde::de::Deserializer<'de>,
{
use alloc::string::String;
use core::fmt::{self, Formatter};
use core::str::FromStr;
use alloc::string::String;

struct Visitor;
impl<'de> $crate::serde::de::Visitor<'de> for Visitor {
Expand Down
1 change: 1 addition & 0 deletions src/language/chinese_simplified.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[rustfmt::skip]
pub const WORDS: [&str; 2048] = [
"的",
"一",
Expand Down
1 change: 1 addition & 0 deletions src/language/chinese_traditional.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[rustfmt::skip]
pub const WORDS: [&str; 2048] = [
"的",
"一",
Expand Down
1 change: 1 addition & 0 deletions src/language/czech.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[rustfmt::skip]
pub const WORDS: [&str; 2048] = [
"abdikace",
"abeceda",
Expand Down
1 change: 1 addition & 0 deletions src/language/english.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[rustfmt::skip]
pub const WORDS: [&str; 2048] = [
"abandon",
"ability",
Expand Down
1 change: 1 addition & 0 deletions src/language/french.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[rustfmt::skip]
pub const WORDS: [&str; 2048] = [
"abaisser",
"abandon",
Expand Down
1 change: 1 addition & 0 deletions src/language/italian.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[rustfmt::skip]
pub const WORDS: [&str; 2048] = [
"abaco",
"abbaglio",
Expand Down
1 change: 1 addition & 0 deletions src/language/japanese.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[rustfmt::skip]
pub const WORDS: [&str; 2048] = [
"あいこくしん",
"あいさつ",
Expand Down
1 change: 1 addition & 0 deletions src/language/korean.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[rustfmt::skip]
pub const WORDS: [&str; 2048] = [
"가격",
"가끔",
Expand Down
1 change: 1 addition & 0 deletions src/language/portuguese.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[rustfmt::skip]
pub const WORDS: [&str; 2048] = [
"abacate",
"abaixo",
Expand Down
1 change: 1 addition & 0 deletions src/language/spanish.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[rustfmt::skip]
pub const WORDS: [&str; 2048] = [
"ábaco",
"abdomen",
Expand Down
13 changes: 4 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ extern crate bitcoin_hashes;
#[cfg(feature = "std")]
extern crate unicode_normalization;

#[cfg(feature = "rand_core")]
pub extern crate rand_core;
#[cfg(feature = "rand")]
pub extern crate crate_rand as rand;
#[cfg(feature = "rand_core")]
pub extern crate rand_core;
#[cfg(feature = "serde")]
pub extern crate serde;

Expand Down Expand Up @@ -542,12 +542,7 @@ impl Mnemonic {
const PBKDF2_BYTES: usize = 64;

let mut seed = [0u8; PBKDF2_BYTES];
pbkdf2::pbkdf2(
self.words(),
normalized_passphrase.as_bytes(),
PBKDF2_ROUNDS,
&mut seed,
);
pbkdf2::pbkdf2(self.words(), normalized_passphrase.as_bytes(), PBKDF2_ROUNDS, &mut seed);
seed
}

Expand Down Expand Up @@ -847,7 +842,7 @@ mod tests {
mnemonic_str
);

#[cfg(features = "std")]
#[cfg(feature = "std")]
{
assert_eq!(&mnemonic.to_string(), mnemonic_str, "failed vector: {}", mnemonic_str);
assert_eq!(
Expand Down
12 changes: 8 additions & 4 deletions src/pbkdf2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const SALT_PREFIX: &'static str = "mnemonic";

/// Calculate the binary size of the mnemonic.
fn mnemonic_byte_len<M>(mnemonic: M) -> usize
where M: Iterator<Item = &'static str> + Clone,
where
M: Iterator<Item = &'static str> + Clone,
{
let mut len = 0;
for (i, word) in mnemonic.enumerate() {
Expand All @@ -18,7 +19,8 @@ fn mnemonic_byte_len<M>(mnemonic: M) -> usize

/// Wrote the mnemonic in binary form into the hash engine.
fn mnemonic_write_into<M>(mnemonic: M, engine: &mut sha512::HashEngine)
where M: Iterator<Item = &'static str> + Clone,
where
M: Iterator<Item = &'static str> + Clone,
{
for (i, word) in mnemonic.enumerate() {
if i > 0 {
Expand All @@ -32,7 +34,8 @@ fn mnemonic_write_into<M>(mnemonic: M, engine: &mut sha512::HashEngine)
/// We need a special method because we can't allocate a new byte
/// vector for the entire serialized mnemonic.
fn create_hmac_engine<M>(mnemonic: M) -> hmac::HmacEngine<sha512::Hash>
where M: Iterator<Item = &'static str> + Clone,
where
M: Iterator<Item = &'static str> + Clone,
{
// Inner code is borrowed from the bitcoin_hashes::hmac::HmacEngine::new method.
let mut ipad = [0x36u8; 128];
Expand Down Expand Up @@ -97,7 +100,8 @@ fn xor(res: &mut [u8], salt: &[u8]) {

/// PBKDF2-HMAC-SHA512 implementation using bitcoin_hashes.
pub(crate) fn pbkdf2<M>(mnemonic: M, unprefixed_salt: &[u8], c: usize, res: &mut [u8])
where M: Iterator<Item = &'static str> + Clone,
where
M: Iterator<Item = &'static str> + Clone,
{
let prf = create_hmac_engine(mnemonic);

Expand Down