Skip to content
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
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 Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "artimonist"
version = "1.8.1"
version = "1.8.2"
edition = "2024"

description = "A tool for generating mnemonics and wallets."
Expand Down
10 changes: 4 additions & 6 deletions src/encrypt/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@ impl<const ENCRYPT: bool> Execute for EncryptCommand<ENCRYPT> {
match &self.source {
EncryptSource::Mnemonic(str) => {
if ENCRYPT {
let mnemonic = str.mnemonic_encrypt(&password)?;
println!("Encrypted mnemonic: \"{mnemonic}\"");
println!("{}", str.mnemonic_encrypt(&password)?);
} else {
let original = str.mnemonic_decrypt(&password)?;
println!("Original mnemonic: \"{original}\"");
println!("{}", str.mnemonic_decrypt(&password)?);
}
}
EncryptSource::Key(key) => {
if ENCRYPT {
println!("Encrypted private key: {}", key.bip38_encrypt(&password)?);
println!("{}", key.bip38_encrypt(&password)?);
} else {
println!("Original private key: {}", key.bip38_decrypt(&password)?);
println!("{}", key.bip38_decrypt(&password)?);
}
}
EncryptSource::File(file) => {
Expand Down
41 changes: 41 additions & 0 deletions tests/encrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,47 @@ macro_rules! cli_execute {
.clone();
String::from_utf8(output.stdout).unwrap()
}};
($args:literal, $key:expr) => {{
let args = $args.split_whitespace().collect::<Vec<_>>();
let mut cmd = Command::cargo_bin("artimonist").unwrap();
let output = cmd
.current_dir("tests/encrypt")
.args(&args)
.args(&["--password", "123456"])
.arg($key)
.assert()
.success()
.get_output()
.clone();
String::from_utf8(output.stdout).unwrap()
}};
}

#[test]
fn test_encrypt_mnemonic() {
let original = "貨 誠 仁 盈 閒 淮 非 秋 突 妹 闢 藥 展 逮 友";
let encrypted = "返 曬 嫩 旱 遲 魏 橋 塔 向 緩 常 系 搬 議 駁; 庫";

assert_eq!(encrypted, cli_execute!("encrypt", original).trim());
assert_eq!(original, cli_execute!("decrypt", encrypted).trim());
}

#[test]
fn test_encrypt_size() {
let original = "館 襲 騰 動 腿 恨 彪 跨 長 圖 休 粘";

let encrypted = cli_execute!("encrypt", format!("{original}; 18"));
let verify_size = format!("{}; 12", encrypted.split_once(';').unwrap().0);
assert_eq!(original, cli_execute!("decrypt", verify_size).trim());
}

#[test]
fn test_encrypt_full() {
let original = "股 珍 職 鋪 截 席 卡 藍 忙 糊 數 繪 伏 充 啦 針 態 高 貝 炸 版 賞 鉛 減";
let encrypted = "辨 搞 斤 木 細 價 上 科 籍 事 懷 月 恩 驗 度 葡 個 返 事 聲 消 俄 擊 考; 用";

assert_eq!(encrypted, cli_execute!("encrypt", original).trim());
assert_eq!(original, cli_execute!("decrypt", encrypted).trim());
}

#[test]
Expand Down