use std::fmt;
#[derive(Clone, PartialEq, Eq)]
pub struct WebApiTicket(Vec<u8>);
impl WebApiTicket {
pub fn new(bytes: Vec<u8>) -> Self {
Self(bytes)
}
pub fn bytes(&self) -> &[u8] {
&self.0
}
pub fn to_hex(&self) -> String {
const HEX: &[u8; 16] = b"0123456789abcdef";
let mut s = String::with_capacity(self.0.len() * 2);
for b in &self.0 {
s.push(HEX[usize::from(b >> 4)] as char);
s.push(HEX[usize::from(b & 0x0f)] as char);
}
s
}
pub fn len(&self) -> usize {
self.0.len()
}
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
}
impl fmt::Debug for WebApiTicket {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "WebApiTicket({} bytes)", self.0.len())
}
}
impl Drop for WebApiTicket {
fn drop(&mut self) {
for b in self.0.iter_mut() {
unsafe { std::ptr::write_volatile(b, 0) };
}
}
}
pub trait AuthBackend {
fn request_web_api_ticket(&self, op: u64, identity: &str) -> bool;
fn cancel_auth_ticket(&self, op: u64);
}