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: anychain kms use gbk encoding for chinese character #274

Merged
Merged
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
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
Loading