#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Mode {
Plain,
PerEntry,
Wholesome,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StartKeyAlg {
Sha1,
Sha256,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Cipher {
BlowfishCfb8,
AesCbcW3c,
AesGcmW3c,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Kdf {
Pbkdf2 {
iterations: i32,
salt: Vec<u8>,
},
Argon2id {
t: i32,
m: i32,
p: i32,
salt: Vec<u8>,
},
PgpRsaOaepMgf1p,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Checksum {
None,
Sha1_1K(Vec<u8>),
Sha256_1K(Vec<u8>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EntryEncryption {
pub path: String,
pub cipher: Cipher,
pub kdf: Kdf,
pub start_key: StartKeyAlg,
pub checksum: Checksum,
pub size: i64,
pub iv: Vec<u8>,
pub derived_key_len: i32,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Classification {
pub mode: Mode,
pub package_encrypted: bool,
pub has_non_encrypted_entries: bool,
pub odf_version: Option<String>,
pub zip_has_encrypted_package: bool,
pub media_type: Option<String>,
pub common: Option<EntryEncryption>,
pub encrypted_entries: Vec<EntryEncryption>,
pub has_unexpected_streams: bool,
pub odf12_fatal: bool,
pub pgp_keys: Vec<EncryptedKey>,
}
impl Classification {
#[must_use]
pub fn wholesome_row(&self) -> Option<&EntryEncryption> {
if self.mode != Mode::Wholesome {
return None;
}
self.encrypted_entries
.iter()
.find(|e| e.path == "encrypted-package")
}
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum DetectError {
#[error("not a zip archive")]
NotZip,
#[error("not an ODF package: META-INF/manifest.xml is missing")]
MissingManifest,
#[error("failed to read zip entry: {0}")]
Zip(String),
#[error("inconsistent package: {0}")]
Inconsistent(String),
#[error("reading the package failed: {0}")]
Io(#[source] std::io::Error),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum ChecksumAlg {
Sha1_1K,
Sha256_1K,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum KdfId {
Pbkdf2,
Argon2id,
PgpRsaOaepMgf1p,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct EncryptedKey {
pub key_id: Vec<u8>,
pub key_packet: Vec<u8>,
pub cipher_value: Vec<u8>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct KeyInfo {
pub keys: Vec<EncryptedKey>,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub(crate) struct PropertyBag {
pub full_path: String,
pub media_type: Option<String>,
pub version: Option<String>,
pub size: Option<i64>,
pub salt: Option<Vec<u8>>,
pub iv: Option<Vec<u8>>,
pub iteration_count: Option<i32>,
pub derived_key_size: Option<i32>,
pub digest: Option<Vec<u8>>,
pub digest_alg: Option<ChecksumAlg>,
pub enc_alg: Option<Cipher>,
pub start_key_alg: Option<StartKeyAlg>,
pub kdf: Option<KdfId>,
pub argon2_args: Option<(i32, i32, i32)>,
pub key_info: Option<KeyInfo>,
}