From dc3eab7aaa7082be4d598edc5a1e511f5f976a38 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Tue, 31 Oct 2023 14:17:18 +0100 Subject: [PATCH] Implement `Borrow<[u8]>`, `PartialEq<[u8]>`, `Hash` These traits were missing and could be useful if e.g. one wants to store serialized signatures in a set/map and access them using `[u8]`. --- src/ecdsa/serialized_signature.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/ecdsa/serialized_signature.rs b/src/ecdsa/serialized_signature.rs index bf71ecc..1aba65f 100644 --- a/src/ecdsa/serialized_signature.rs +++ b/src/ecdsa/serialized_signature.rs @@ -7,6 +7,7 @@ //! unable to run on platforms without allocator. We implement a special type to encapsulate //! serialized signatures and since it's a bit more complicated it has its own module. +use core::borrow::Borrow; use core::{fmt, ops}; pub use into_iter::IntoIter; @@ -41,11 +42,30 @@ impl PartialEq for SerializedSignature { fn eq(&self, other: &SerializedSignature) -> bool { **self == **other } } +impl PartialEq<[u8]> for SerializedSignature { + #[inline] + fn eq(&self, other: &[u8]) -> bool { **self == *other } +} + +impl PartialEq for [u8] { + #[inline] + fn eq(&self, other: &SerializedSignature) -> bool { *self == **other } +} + +impl core::hash::Hash for SerializedSignature { + fn hash(&self, state: &mut H) { (**self).hash(state) } +} + impl AsRef<[u8]> for SerializedSignature { #[inline] fn as_ref(&self) -> &[u8] { self } } +impl Borrow<[u8]> for SerializedSignature { + #[inline] + fn borrow(&self) -> &[u8] { self } +} + impl ops::Deref for SerializedSignature { type Target = [u8];