use super::*;
use crate::AiHash;
use crate::{error::AiHashResult, 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,
)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[serde(transparent)]
pub struct AiHashB64<T: HashType>(AiHash<T>);
impl<T: HashType> AiHashB64<T> {
pub fn from_b64_str(str: &str) -> AiHashResult<Self> {
let bytes = ai_hash_decode_unchecked(str)?;
AiHash::from_raw_39(bytes).map(Into::into)
}
}
impl<T: HashType> serde::Serialize for AiHashB64<T> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(&ai_hash_encode(self.0.get_raw_39()))
}
}
pub type AgentPubKeyB64 = AiHashB64<hash_type::Agent>;
pub type SafHashB64 = AiHashB64<hash_type::Saf>;
pub type SgdOpHashB64 = AiHashB64<hash_type::SgdOp>;
pub type EntryHashB64 = AiHashB64<hash_type::Entry>;
pub type HeaderHashB64 = AiHashB64<hash_type::Header>;
pub type NetIdHashB64 = AiHashB64<hash_type::NetId>;
pub type WasmHashB64 = AiHashB64<hash_type::Wasm>;
pub type AnySgdHashB64 = AiHashB64<hash_type::AnySgd>;