Skip to content

Commit

Permalink
Merge pull request #272 from 0xcregis/271-fix-anychain-kms-eliminate-…
Browse files Browse the repository at this point in the history
…gbk-encoding-for-zh-cn-mnemonic

fix: remove GBK encoding for zh-cn mnemonic
  • Loading branch information
loki-cmu authored Aug 19, 2024
2 parents 34d98eb + 82accdf commit 34c0bda
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion anychain-kms/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "anychain-kms"
description = "A Rust library providing Key Management Schema for AnyChain. Handles general security and signature algorithms."
version = "0.1.9"
version = "0.1.10"
keywords = ["cryptography", "security", "signature", "algorithm"]

# Workspace inherited keys
Expand Down
29 changes: 15 additions & 14 deletions anychain-kms/src/bip39/mnemonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::MnemonicType;
use anyhow::Error;
// use encoding::codec::simpchinese::*;
// use encoding::Encoding;
use encoding_rs::GB18030;
// use encoding_rs::GB18030;
use std::fmt;
use std::mem;
use unicode_normalization::UnicodeNormalization;
Expand Down Expand Up @@ -265,19 +265,20 @@ impl Mnemonic {
}

pub fn as_bytes(&self) -> Vec<u8> {
//use GBK encoding if language is zh-cn
if self.lang == Language::ChineseSimplified {
// let mut d = GB18030_ENCODING.raw_encoder();
// let mut d = encoding_rs::GB18030;
// d.raw_feed(&self.phrase, &mut bytes);
let mut d = GB18030.new_encoder();
let mut bytes = Vec::<u8>::new();
let (_complete, _read, _written, _) =
d.encode_from_utf8(&self.phrase, &mut bytes, true);
bytes
} else {
self.phrase().as_bytes().to_vec()
}
// // use GBK encoding if language is zh-cn
// if self.lang == Language::ChineseSimplified {
// // let mut d = GB18030_ENCODING.raw_encoder();
// // let mut d = encoding_rs::GB18030;
// // d.raw_feed(&self.phrase, &mut bytes);
// let mut d = GB18030.new_encoder();
// let mut bytes = Vec::<u8>::new();
// let (_complete, _read, _written, _) =
// d.encode_from_utf8(&self.phrase, &mut bytes, true);
// bytes
// } else {
// self.phrase().as_bytes().to_vec()
// }
self.phrase().as_bytes().to_vec()
}
}

Expand Down

0 comments on commit 34c0bda

Please sign in to comment.