[ethkey] Unify debug/display for Address/Public/Secret (#8076)

* unify debug in ethkey

* fix tests
This commit is contained in:
Niklas Adolfsson 2018-03-09 16:32:20 +01:00 committed by Marek Kotewicz
parent e8106016c8
commit 29d7a0e3c9
2 changed files with 9 additions and 3 deletions

View File

@ -31,7 +31,7 @@ use std::{env, fmt, process, io, sync};
use docopt::Docopt; use docopt::Docopt;
use ethkey::{KeyPair, Random, Brain, BrainPrefix, Prefix, Error as EthkeyError, Generator, sign, verify_public, verify_address, brain_recover}; use ethkey::{KeyPair, Random, Brain, BrainPrefix, Prefix, Error as EthkeyError, Generator, sign, verify_public, verify_address, brain_recover};
use rustc_hex::{ToHex, FromHex, FromHexError}; use rustc_hex::{FromHex, FromHexError};
pub const USAGE: &'static str = r#" pub const USAGE: &'static str = r#"
Ethereum keys generator. Ethereum keys generator.
@ -180,7 +180,7 @@ fn display(result: (KeyPair, Option<String>), mode: DisplayMode) -> String {
Some(extra_data) => format!("{}\n{}", extra_data, keypair), Some(extra_data) => format!("{}\n{}", extra_data, keypair),
None => format!("{}", keypair) None => format!("{}", keypair)
}, },
DisplayMode::Secret => format!("{}", keypair.secret().to_hex()), DisplayMode::Secret => format!("{:?}", keypair.secret()),
DisplayMode::Public => format!("{:?}", keypair.public()), DisplayMode::Public => format!("{:?}", keypair.public()),
DisplayMode::Address => format!("{:?}", keypair.address()), DisplayMode::Address => format!("{:?}", keypair.address()),
} }

View File

@ -34,6 +34,12 @@ impl ToHex for Secret {
} }
impl fmt::Debug for Secret { impl fmt::Debug for Secret {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "{:?}", self.inner)
}
}
impl fmt::Display for Secret {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "Secret: 0x{:x}{:x}..{:x}{:x}", self.inner[0], self.inner[1], self.inner[30], self.inner[31]) write!(fmt, "Secret: 0x{:x}{:x}..{:x}{:x}", self.inner[0], self.inner[1], self.inner[30], self.inner[31])
} }