Skip to content

Commit 739d36f

Browse files
committed
Getting rid of SecretKey display methods
1 parent b8f0390 commit 739d36f

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

src/key.rs

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,6 @@ pub struct SecretKey(pub(crate) [u8; constants::SECRET_KEY_SIZE]);
3131
impl_array_newtype!(SecretKey, u8, constants::SECRET_KEY_SIZE);
3232
impl_safe_debug!(SecretKey);
3333

34-
impl fmt::LowerHex for SecretKey {
35-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
36-
for ch in &self.0[..] {
37-
write!(f, "{:02x}", *ch)?;
38-
}
39-
Ok(())
40-
}
41-
}
42-
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-
4934
impl str::FromStr for SecretKey {
5035
type Err = Error;
5136
fn from_str(s: &str) -> Result<SecretKey, Error> {
@@ -218,7 +203,12 @@ impl SecretKey {
218203
impl ::serde::Serialize for SecretKey {
219204
fn serialize<S: ::serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
220205
if s.is_human_readable() {
221-
s.collect_str(self)
206+
#[cfg(any(feature = "std", feature = "alloc"))] {
207+
#[allow(deprecated)]
208+
s.serialize_str(&self.format_secret())
209+
}
210+
#[cfg(not(any(feature = "std", feature = "alloc")))]
211+
s.serialize_bytes(&self[..])
222212
} else {
223213
s.serialize_bytes(&self[..])
224214
}
@@ -705,10 +695,11 @@ mod test {
705695
#[cfg(fuzzing)]
706696
let pk = PublicKey::from_slice(&[0x02, 0x18, 0x84, 0x57, 0x81, 0xf6, 0x31, 0xc4, 0x8f, 0x1c, 0x97, 0x09, 0xe2, 0x30, 0x92, 0x06, 0x7d, 0x06, 0x83, 0x7f, 0x30, 0xaa, 0x0c, 0xd0, 0x54, 0x4a, 0xc8, 0x87, 0xfe, 0x91, 0xdd, 0xd1, 0x66]).expect("pk");
707697

698+
#[allow(deprecated)] {
708699
assert_eq!(
709-
sk.to_string(),
700+
sk.format_secret(),
710701
"01010101010101010001020304050607ffff0000ffff00006363636363636363"
711-
);
702+
) };
712703
assert_eq!(
713704
SecretKey::from_str("01010101010101010001020304050607ffff0000ffff00006363636363636363").unwrap(),
714705
sk

0 commit comments

Comments
 (0)