p2panda_rs/entry/
signature.rs1use std::fmt;
4use std::hash::Hash as StdHash;
5
6use bamboo_rs_core_ed25519_yasmf::Signature as BambooSignature;
7use ed25519_dalek::Signature as Ed25519Signature;
8
9#[derive(Copy, Clone, Debug)]
11pub struct Signature(Ed25519Signature);
12
13impl Signature {
14 pub fn into_bytes(&self) -> Vec<u8> {
16 self.0.to_bytes().to_vec()
17 }
18}
19
20impl From<BambooSignature<&[u8]>> for Signature {
21 fn from(signature: BambooSignature<&[u8]>) -> Self {
22 Signature(Ed25519Signature::from_bytes(signature.0).unwrap())
24 }
25}
26
27impl From<Ed25519Signature> for Signature {
28 fn from(signature: Ed25519Signature) -> Self {
29 Self(signature)
30 }
31}
32
33impl From<&Signature> for Ed25519Signature {
34 fn from(signature: &Signature) -> Self {
35 signature.0.to_owned()
36 }
37}
38
39impl StdHash for Signature {
40 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
41 self.into_bytes().hash(state)
42 }
43}
44
45impl PartialEq for Signature {
46 fn eq(&self, other: &Self) -> bool {
47 self.0 == other.0
48 }
49}
50
51impl Eq for Signature {}
52
53impl fmt::Display for Signature {
54 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
55 write!(f, "{}", hex::encode(self.into_bytes()))
56 }
57}
58
59#[cfg(test)]
60impl Signature {
61 pub fn from_bytes(bytes: &[u8]) -> Self {
62 Self(Ed25519Signature::from_bytes(bytes).unwrap())
63 }
64}