use std::time::SystemTime;
use crate::memory::{SecureBytes, SecureString};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ContentKind {
File,
Archive,
}
#[derive(Debug, Clone)]
pub struct FileMetadata {
filename: SecureString,
mtime: Option<SystemTime>,
mode: Option<u32>, kind: ContentKind,
}
impl FileMetadata {
pub fn new(filename: SecureString, mtime: Option<SystemTime>, mode: Option<u32>) -> Self {
Self {
filename,
mtime,
mode,
kind: ContentKind::File,
}
}
pub fn into_archive(mut self) -> Self {
self.kind = ContentKind::Archive;
self
}
pub fn filename(&self) -> &SecureString {
&self.filename
}
pub fn mtime(&self) -> Option<SystemTime> {
self.mtime
}
pub fn mode(&self) -> Option<u32> {
self.mode
}
pub fn kind(&self) -> ContentKind {
self.kind
}
}
#[derive(Debug)]
pub struct PlaintextFile {
filename: SecureString, content: SecureBytes, }
impl PlaintextFile {
pub fn new(filename: SecureString, content: SecureBytes) -> Self {
Self { filename, content }
}
pub fn filename(&self) -> &SecureString {
&self.filename
}
pub fn content(&self) -> &SecureBytes {
&self.content
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn plaintext_file_accessors() {
let file = PlaintextFile::new(
SecureString::new("a.txt".to_string()),
SecureBytes::new(vec![1, 2, 3]),
);
assert_eq!(file.filename().as_str(), "a.txt");
assert_eq!(file.content().as_slice(), &[1, 2, 3]);
}
}