diff --git a/src/cmd_pgpcarddecrypt.rs b/src/cmd_pgpcarddecrypt.rs index c046d9c..bacf4fd 100644 --- a/src/cmd_pgpcarddecrypt.rs +++ b/src/cmd_pgpcarddecrypt.rs @@ -72,10 +72,12 @@ impl Command for CommandImpl { EncryptAlgo::RSA => trans.decipher(Cryptogram::RSA(&cipher_bytes))?, EncryptAlgo::ECDH => trans.decipher(Cryptogram::ECDH(&cipher_bytes))?, }; - // let text = trans.decipher(Cryptogram::RSA(&cipher_bytes))?; success!("Clear text HEX: {}", hex::encode(&text)); success!("Clear text base64: {}", base64_encode(&text)); - success!("Clear text UTF-8: {}", String::from_utf8_lossy(&text)); + let text_opt = String::from_utf8(text.clone()).ok(); + if let Some(text) = &text_opt { + success!("Clear text UTF-8: {}", text); + } if json_output { let mut json = BTreeMap::<&'_ str, String>::new(); @@ -83,7 +85,9 @@ impl Command for CommandImpl { json.insert("cipher_base64", base64_encode(&cipher_bytes)); json.insert("text_hex", hex::encode(&text)); json.insert("text_base64", base64_encode(&text)); - json.insert("text_utf8", String::from_utf8_lossy(&text).to_string()); + if let Some(text) = text_opt { + json.insert("text_utf8", text); + } println!("{}", serde_json::to_string_pretty(&json).unwrap()); }