Implement fmt::LowerHex for SecretKey and PublicKey
This commit is contained in:
parent
84345f2923
commit
ccac3ead25
16
src/key.rs
16
src/key.rs
|
@ -31,7 +31,7 @@ pub struct SecretKey([u8; constants::SECRET_KEY_SIZE]);
|
||||||
impl_array_newtype!(SecretKey, u8, constants::SECRET_KEY_SIZE);
|
impl_array_newtype!(SecretKey, u8, constants::SECRET_KEY_SIZE);
|
||||||
impl_pretty_debug!(SecretKey);
|
impl_pretty_debug!(SecretKey);
|
||||||
|
|
||||||
impl fmt::Display for SecretKey {
|
impl fmt::LowerHex for SecretKey {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
for ch in &self.0[..] {
|
for ch in &self.0[..] {
|
||||||
write!(f, "{:02x}", *ch)?;
|
write!(f, "{:02x}", *ch)?;
|
||||||
|
@ -40,6 +40,12 @@ impl fmt::Display for SecretKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for SecretKey {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
fmt::LowerHex::fmt(self, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl str::FromStr for SecretKey {
|
impl str::FromStr for SecretKey {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
fn from_str(s: &str) -> Result<SecretKey, Error> {
|
fn from_str(s: &str) -> Result<SecretKey, Error> {
|
||||||
|
@ -61,7 +67,7 @@ pub const ONE_KEY: SecretKey = SecretKey([0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Debug, PartialOrd, Ord, Hash)]
|
#[derive(Copy, Clone, PartialEq, Eq, Debug, PartialOrd, Ord, Hash)]
|
||||||
pub struct PublicKey(ffi::PublicKey);
|
pub struct PublicKey(ffi::PublicKey);
|
||||||
|
|
||||||
impl fmt::Display for PublicKey {
|
impl fmt::LowerHex for PublicKey {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let ser = self.serialize();
|
let ser = self.serialize();
|
||||||
for ch in &ser[..] {
|
for ch in &ser[..] {
|
||||||
|
@ -71,6 +77,12 @@ impl fmt::Display for PublicKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for PublicKey {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
fmt::LowerHex::fmt(self, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl str::FromStr for PublicKey {
|
impl str::FromStr for PublicKey {
|
||||||
type Err = Error;
|
type Err = Error;
|
||||||
fn from_str(s: &str) -> Result<PublicKey, Error> {
|
fn from_str(s: &str) -> Result<PublicKey, Error> {
|
||||||
|
|
Loading…
Reference in New Issue