use std::fmt::Debug;
use std::fmt::Display;
use std::fmt::Formatter;
use serde::Deserialize;
use serde::Serialize;
use zeroize::Zeroize;
mod always_panic_impl;
use always_panic_impl as crypto_impl;
pub use crypto_impl::*;
#[derive(Clone, Default, Serialize, Deserialize)]
#[repr(transparent)]
pub struct CryptKey {
pub(crate) key_bytes: SecureByteVec,
}
#[derive(Clone, Default, Serialize, Deserialize)]
#[repr(transparent)]
pub struct SecureByteVec {
data: Vec<u8>,
}
impl Display for SecureByteVec {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_str("SecureByteVec")
}
}
impl Debug for SecureByteVec {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.write_str("debug: SecureByteVec")
}
}
impl From<Vec<u8>> for SecureByteVec {
fn from(value: Vec<u8>) -> Self {
Self { data: value }
}
}
impl From<&[u8]> for SecureByteVec {
fn from(value: &[u8]) -> Self {
value.to_vec().into()
}
}
impl SecureByteVec {
pub fn as_slice(&self) -> &[u8] {
self.data.as_slice()
}
pub fn as_mut_slice(&mut self) -> &mut [u8] {
self.data.as_mut_slice()
}
}
impl Drop for SecureByteVec {
fn drop(&mut self) {
self.data.zeroize();
}
}