use std::fmt::{Debug, Formatter, Result};
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, Clone)]
#[serde(tag = "kind", content = "value")]
pub enum SecretValue {
String(String),
Bytes(Vec<u8>),
}
impl SecretValue {
#[must_use]
pub fn as_string(&self) -> Option<&str> {
match self {
SecretValue::String(s) => Some(s),
SecretValue::Bytes(_) => None,
}
}
#[must_use]
pub fn as_bytes(&self) -> Option<&[u8]> {
match self {
SecretValue::String(_) => None,
SecretValue::Bytes(b) => Some(b),
}
}
}
impl Debug for SecretValue {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
match self {
SecretValue::String(_) => write!(f, "string(redacted)"),
SecretValue::Bytes(_) => write!(f, "bytes(redacted)"),
}
}
}