Skip to content

Commit dc3eab7

Browse files
committed
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]`.
1 parent 7dac91d commit dc3eab7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/ecdsa/serialized_signature.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! unable to run on platforms without allocator. We implement a special type to encapsulate
88
//! serialized signatures and since it's a bit more complicated it has its own module.
99
10+
use core::borrow::Borrow;
1011
use core::{fmt, ops};
1112

1213
pub use into_iter::IntoIter;
@@ -41,11 +42,30 @@ impl PartialEq for SerializedSignature {
4142
fn eq(&self, other: &SerializedSignature) -> bool { **self == **other }
4243
}
4344

45+
impl PartialEq<[u8]> for SerializedSignature {
46+
#[inline]
47+
fn eq(&self, other: &[u8]) -> bool { **self == *other }
48+
}
49+
50+
impl PartialEq<SerializedSignature> for [u8] {
51+
#[inline]
52+
fn eq(&self, other: &SerializedSignature) -> bool { *self == **other }
53+
}
54+
55+
impl core::hash::Hash for SerializedSignature {
56+
fn hash<H: core::hash::Hasher>(&self, state: &mut H) { (**self).hash(state) }
57+
}
58+
4459
impl AsRef<[u8]> for SerializedSignature {
4560
#[inline]
4661
fn as_ref(&self) -> &[u8] { self }
4762
}
4863

64+
impl Borrow<[u8]> for SerializedSignature {
65+
#[inline]
66+
fn borrow(&self) -> &[u8] { self }
67+
}
68+
4969
impl ops::Deref for SerializedSignature {
5070
type Target = [u8];
5171

0 commit comments

Comments
 (0)