use zeroize::{Zeroize, ZeroizeOnDrop};
#[derive(PartialEq)]
#[non_exhaustive]
pub enum CborValue {
Null,
Bool(bool),
Int(i64),
String(String),
Bytes(Vec<u8>),
Array(Vec<CborValue>),
Map(Vec<(String, CborValue)>),
}
impl core::fmt::Debug for CborValue {
fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let kind = match self {
Self::Null => "Null",
Self::Bool(_) => "Bool",
Self::Int(_) => "Int",
Self::String(_) => "String",
Self::Bytes(_) => "Bytes",
Self::Array(_) => "Array",
Self::Map(_) => "Map",
};
formatter.debug_tuple("CborValue").field(&kind).finish()
}
}
impl Zeroize for CborValue {
fn zeroize(&mut self) {
match self {
Self::Null => {}
Self::Bool(value) => value.zeroize(),
Self::Int(value) => value.zeroize(),
Self::String(value) => value.zeroize(),
Self::Bytes(value) => value.zeroize(),
Self::Array(values) => values.zeroize(),
Self::Map(entries) => entries.zeroize(),
}
}
}
impl Drop for CborValue {
fn drop(&mut self) {
self.zeroize();
}
}
impl ZeroizeOnDrop for CborValue {}