Render byte slices as hex more often in `Debug` impls
This is more generally useful for debugging purposes than the default
`Debug` impl for `&[u8]`.
We also provide an alternate `Debug` impl for `legacy::Script` that
parses and renders known opcodes. Note that we only parse a subset of
the full opcode set.
Extracted from: c8e2d81f58
This commit is contained in:
parent
b459f710c2
commit
9c76d5789f
23
src/lib.rs
23
src/lib.rs
|
@ -19,6 +19,8 @@
|
||||||
#![deny(unsafe_code)]
|
#![deny(unsafe_code)]
|
||||||
// TODO: #![deny(missing_docs)]
|
// TODO: #![deny(missing_docs)]
|
||||||
|
|
||||||
|
use core::fmt::{self, Write};
|
||||||
|
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
#[cfg(feature = "alloc")]
|
#[cfg(feature = "alloc")]
|
||||||
|
@ -72,9 +74,28 @@ impl AsRef<[u8]> for OutgoingCipherKey {
|
||||||
/// Newtype representing the byte encoding of an [`EphemeralPublicKey`].
|
/// Newtype representing the byte encoding of an [`EphemeralPublicKey`].
|
||||||
///
|
///
|
||||||
/// [`EphemeralPublicKey`]: Domain::EphemeralPublicKey
|
/// [`EphemeralPublicKey`]: Domain::EphemeralPublicKey
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone)]
|
||||||
pub struct EphemeralKeyBytes(pub [u8; 32]);
|
pub struct EphemeralKeyBytes(pub [u8; 32]);
|
||||||
|
|
||||||
|
impl fmt::Debug for EphemeralKeyBytes {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
struct HexFmt<'b>(&'b [u8]);
|
||||||
|
impl<'b> fmt::Debug for HexFmt<'b> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
f.write_char('"')?;
|
||||||
|
for b in self.0 {
|
||||||
|
f.write_fmt(format_args!("{:02x}", b))?;
|
||||||
|
}
|
||||||
|
f.write_char('"')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
f.debug_tuple("EphemeralKeyBytes")
|
||||||
|
.field(&HexFmt(&self.0))
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl AsRef<[u8]> for EphemeralKeyBytes {
|
impl AsRef<[u8]> for EphemeralKeyBytes {
|
||||||
fn as_ref(&self) -> &[u8] {
|
fn as_ref(&self) -> &[u8] {
|
||||||
&self.0
|
&self.0
|
||||||
|
|
Loading…
Reference in New Issue