1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use super::*;
use crate::HoloHash;
use crate::{error::HoloHashResult, HashType};
#[derive(
Debug,
Clone,
Hash,
PartialEq,
Eq,
PartialOrd,
Ord,
serde::Deserialize,
derive_more::Constructor,
derive_more::Display,
derive_more::From,
derive_more::Into,
derive_more::AsRef,
)]
#[serde(transparent)]
pub struct HoloHashB64<T: HashType>(HoloHash<T>);
impl<T: HashType> HoloHashB64<T> {
pub fn from_b64_str(str: &str) -> HoloHashResult<Self> {
let bytes = holo_hash_decode_unchecked(str)?;
HoloHash::from_raw_39(bytes).map(Into::into)
}
}
impl<T: HashType> serde::Serialize for HoloHashB64<T> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(&holo_hash_encode(self.0.get_raw_39()))
}
}
#[cfg(feature = "arbitrary")]
impl<'a, P: PrimitiveHashType> arbitrary::Arbitrary<'a> for HoloHashB64<P> {
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
Ok(HoloHash::arbitrary(u)?.into())
}
}
pub type AgentPubKeyB64 = HoloHashB64<hash_type::Agent>;
pub type DnaHashB64 = HoloHashB64<hash_type::Dna>;
pub type DhtOpHashB64 = HoloHashB64<hash_type::DhtOp>;
pub type EntryHashB64 = HoloHashB64<hash_type::Entry>;
pub type HeaderHashB64 = HoloHashB64<hash_type::Header>;
pub type NetIdHashB64 = HoloHashB64<hash_type::NetId>;
pub type WasmHashB64 = HoloHashB64<hash_type::Wasm>;
pub type AnyDhtHashB64 = HoloHashB64<hash_type::AnyDht>;