Skip to content

Commit

Permalink
Merge pull request #274 from 0xcregis/273-fix-anychain-kms-use-gbk-en…
Browse files Browse the repository at this point in the history
…coding-for-chinese-character

fix: anychain kms use gbk encoding for chinese character
  • Loading branch information
loki-cmu authored Aug 22, 2024
2 parents 34c0bda + e041fcd commit 4ee1d1c
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 25 deletions.
67 changes: 61 additions & 6 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions 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.10"
version = "0.1.11"
keywords = ["cryptography", "security", "signature", "algorithm"]

# Workspace inherited keys
Expand Down Expand Up @@ -29,8 +29,8 @@ hex = { workspace = true }
libsecp256k1 = { workspace = true }
ed25519-dalek = { workspace = true }
curve25519-dalek = { workspace = true }
encoding_rs = { version = "0.8.33" }
group = "0.13.0"
encoding = "0.2.33"

[dev-dependencies]
hex-literal = "0.4"
Expand Down
24 changes: 7 additions & 17 deletions anychain-kms/src/bip39/mnemonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use super::ErrorKind;
use super::Language;
use super::MnemonicType;
use anyhow::Error;
// use encoding::codec::simpchinese::*;
// use encoding::Encoding;
// use encoding_rs::GB18030;
use encoding::{all::GB18030, EncoderTrap, Encoding};
use std::fmt;
use std::mem;
use unicode_normalization::UnicodeNormalization;
Expand Down Expand Up @@ -265,20 +263,12 @@ 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()
// }
self.phrase().as_bytes().to_vec()
match self.lang {
Language::ChineseSimplified => {
GB18030.encode(self.phrase(), EncoderTrap::Strict).unwrap()
}
_ => self.phrase().as_bytes().to_vec(),
}
}
}

Expand Down

0 comments on commit 4ee1d1c

Please sign in to comment.