[ethkey] Unify debug/display for Address/Public/Secret (#8076)
* unify debug in ethkey * fix tests
This commit is contained in:
parent
e8106016c8
commit
29d7a0e3c9
@ -31,7 +31,7 @@ use std::{env, fmt, process, io, sync};
|
||||
|
||||
use docopt::Docopt;
|
||||
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#"
|
||||
Ethereum keys generator.
|
||||
@ -180,7 +180,7 @@ fn display(result: (KeyPair, Option<String>), mode: DisplayMode) -> String {
|
||||
Some(extra_data) => format!("{}\n{}", extra_data, keypair),
|
||||
None => format!("{}", keypair)
|
||||
},
|
||||
DisplayMode::Secret => format!("{}", keypair.secret().to_hex()),
|
||||
DisplayMode::Secret => format!("{:?}", keypair.secret()),
|
||||
DisplayMode::Public => format!("{:?}", keypair.public()),
|
||||
DisplayMode::Address => format!("{:?}", keypair.address()),
|
||||
}
|
||||
|
@ -34,6 +34,12 @@ impl ToHex 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 {
|
||||
write!(fmt, "Secret: 0x{:x}{:x}..{:x}{:x}", self.inner[0], self.inner[1], self.inner[30], self.inner[31])
|
||||
}
|
||||
@ -168,7 +174,7 @@ impl Secret {
|
||||
if self.is_zero() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
||||
match pow {
|
||||
0 => *self = key::ONE_KEY.into(),
|
||||
1 => (),
|
||||
|
Loading…
Reference in New Issue
Block a user