From 7e9d4a4316d0b3cbf49a756b276393422cd24f11 Mon Sep 17 00:00:00 2001 From: Bobbin Threadbare Date: Wed, 17 Jan 2024 17:21:49 -0800 Subject: [PATCH] feat: add to_hex() to RpoDigest and RpxDigest --- src/hash/rescue/rpo/digest.rs | 7 ++++++- src/hash/rescue/rpx/digest.rs | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/hash/rescue/rpo/digest.rs b/src/hash/rescue/rpo/digest.rs index a4cfa17..0645458 100644 --- a/src/hash/rescue/rpo/digest.rs +++ b/src/hash/rescue/rpo/digest.rs @@ -33,6 +33,11 @@ impl RpoDigest { { digests.flat_map(|d| d.0.iter()) } + + /// Returns hexadecimal representation of this digest prefixed with `0x`. + pub fn to_hex(&self) -> String { + bytes_to_hex_string(self.as_bytes()) + } } impl Digest for RpoDigest { @@ -158,7 +163,7 @@ impl From for [u8; DIGEST_BYTES] { impl From for String { /// The returned string starts with `0x`. fn from(value: RpoDigest) -> Self { - bytes_to_hex_string(value.as_bytes()) + value.to_hex() } } diff --git a/src/hash/rescue/rpx/digest.rs b/src/hash/rescue/rpx/digest.rs index a9a236a..80057ca 100644 --- a/src/hash/rescue/rpx/digest.rs +++ b/src/hash/rescue/rpx/digest.rs @@ -33,6 +33,11 @@ impl RpxDigest { { digests.flat_map(|d| d.0.iter()) } + + /// Returns hexadecimal representation of this digest prefixed with `0x`. + pub fn to_hex(&self) -> String { + bytes_to_hex_string(self.as_bytes()) + } } impl Digest for RpxDigest { @@ -158,7 +163,7 @@ impl From for [u8; DIGEST_BYTES] { impl From for String { /// The returned string starts with `0x`. fn from(value: RpxDigest) -> Self { - bytes_to_hex_string(value.as_bytes()) + value.to_hex() } }