use hex::ToHex;
use serde::Deserialize;
use serde::Serialize;
use hex::FromHex;
pub type GlobalNonceInner = [u8; 32];
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
#[serde(transparent)]
#[repr(transparent)]
pub struct GlobalNonce(GlobalNonceInner);
impl GlobalNonce {
pub fn new(inner: GlobalNonceInner) -> Self {
Self(inner)
}
}
impl AsRef<GlobalNonceInner> for GlobalNonce {
fn as_ref(&self) -> &GlobalNonceInner {
&self.0
}
}
impl FromHex for GlobalNonce {
type Error = <[u8; 32] as FromHex>::Error;
fn from_hex<T: AsRef<[u8]>>(hex: T) -> Result<Self, Self::Error> {
GlobalNonceInner::from_hex(hex).map(Self)
}
}
impl ToHex for GlobalNonce {
fn encode_hex<T: std::iter::FromIterator<char>>(&self) -> T {
ToHex::encode_hex(&self.0)
}
fn encode_hex_upper<T: std::iter::FromIterator<char>>(&self) -> T {
ToHex::encode_hex_upper(&self.0)
}
}
impl std::fmt::Display for GlobalNonce {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.encode_hex::<String>())
}
}