use core::fmt;
use zeroize::{Zeroize, ZeroizeOnDrop};
#[derive(Clone, PartialEq, Eq, Zeroize, ZeroizeOnDrop)]
pub struct Seed([u8; 32]);
impl Seed {
#[inline]
pub const fn new(bytes: [u8; 32]) -> Self {
Self(bytes)
}
#[inline]
pub const fn as_bytes(&self) -> &[u8; 32] {
&self.0
}
#[inline]
pub fn into_bytes(self) -> [u8; 32] {
let bytes = self.0;
core::mem::forget(self);
bytes
}
}
impl From<[u8; 32]> for Seed {
#[inline]
fn from(bytes: [u8; 32]) -> Self {
Self(bytes)
}
}
impl AsRef<[u8; 32]> for Seed {
#[inline]
fn as_ref(&self) -> &[u8; 32] {
&self.0
}
}
impl fmt::Debug for Seed {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Seed([REDACTED])")
}
}
#[derive(Clone, PartialEq, Eq, Zeroize, ZeroizeOnDrop)]
pub struct PrivateKey([u8; 32]);
impl PrivateKey {
#[inline]
pub const fn new(bytes: [u8; 32]) -> Self {
Self(bytes)
}
#[inline]
pub const fn as_bytes(&self) -> &[u8; 32] {
&self.0
}
#[inline]
pub fn into_bytes(self) -> [u8; 32] {
let bytes = self.0;
core::mem::forget(self);
bytes
}
}
impl AsRef<[u8; 32]> for PrivateKey {
#[inline]
fn as_ref(&self) -> &[u8; 32] {
&self.0
}
}
impl fmt::Debug for PrivateKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "PrivateKey([REDACTED])")
}
}
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct PublicKey([u8; 32]);
impl PublicKey {
#[inline]
pub const fn new(bytes: [u8; 32]) -> Self {
Self(bytes)
}
#[inline]
pub const fn as_bytes(&self) -> &[u8; 32] {
&self.0
}
#[inline]
pub const fn into_bytes(self) -> [u8; 32] {
self.0
}
}
impl From<[u8; 32]> for PublicKey {
#[inline]
fn from(bytes: [u8; 32]) -> Self {
Self(bytes)
}
}
impl AsRef<[u8; 32]> for PublicKey {
#[inline]
fn as_ref(&self) -> &[u8; 32] {
&self.0
}
}
impl fmt::Debug for PublicKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"PublicKey({:02x}{:02x}{:02x}{:02x}...)",
self.0[0], self.0[1], self.0[2], self.0[3]
)
}
}
impl fmt::Display for PublicKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
for byte in &self.0 {
write!(f, "{:02x}", byte)?;
}
Ok(())
}
}