Skip to content

Commit ccac3ea

Browse files
committed
Implement fmt::LowerHex for SecretKey and PublicKey
1 parent 84345f2 commit ccac3ea

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/key.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct SecretKey([u8; constants::SECRET_KEY_SIZE]);
3131
impl_array_newtype!(SecretKey, u8, constants::SECRET_KEY_SIZE);
3232
impl_pretty_debug!(SecretKey);
3333

34-
impl fmt::Display for SecretKey {
34+
impl fmt::LowerHex for SecretKey {
3535
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3636
for ch in &self.0[..] {
3737
write!(f, "{:02x}", *ch)?;
@@ -40,6 +40,12 @@ impl fmt::Display for SecretKey {
4040
}
4141
}
4242

43+
impl fmt::Display for SecretKey {
44+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
45+
fmt::LowerHex::fmt(self, f)
46+
}
47+
}
48+
4349
impl str::FromStr for SecretKey {
4450
type Err = Error;
4551
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,
6167
#[derive(Copy, Clone, PartialEq, Eq, Debug, PartialOrd, Ord, Hash)]
6268
pub struct PublicKey(ffi::PublicKey);
6369

64-
impl fmt::Display for PublicKey {
70+
impl fmt::LowerHex for PublicKey {
6571
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
6672
let ser = self.serialize();
6773
for ch in &ser[..] {
@@ -71,6 +77,12 @@ impl fmt::Display for PublicKey {
7177
}
7278
}
7379

80+
impl fmt::Display for PublicKey {
81+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
82+
fmt::LowerHex::fmt(self, f)
83+
}
84+
}
85+
7486
impl str::FromStr for PublicKey {
7587
type Err = Error;
7688
fn from_str(s: &str) -> Result<PublicKey, Error> {

0 commit comments

Comments
 (0)