#[non_exhaustive]pub struct Classification {
pub container: Container,
pub document: Document,
pub version: Option<(u16, u16)>,
pub family: Family,
pub key_data: Option<AlgorithmParams>,
pub password_key: Option<AlgorithmParams>,
pub data_integrity: IntegrityDeclaration,
pub container_read: ContainerRead,
}Expand description
What classify() found. Never an error: an unreadable file is Unknown, not a
failure.
§Examples
use msoffice_crypto::{classify, Container, Family, IntegrityDeclaration};
let class = classify(b"not an office file at all");
assert_eq!(class.container, Container::Unknown);
assert_eq!(class.family, Family::Unknown);
assert_eq!(class.data_integrity, IntegrityDeclaration::Unknown);
assert!(!class.is_encrypted());Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.container: ContainerThe container shape.
document: DocumentThe application format inside the container.
version: Option<(u16, u16)>EncryptionVersionInfo as (vMajor, vMinor): from the EncryptionInfo stream
when one is present and at least 8 bytes long, and from the binary formats’ own
CryptoAPI EncryptionHeader for a .doc / .xls / .ppt, which carry no such
stream. None when neither could be read, and for the schemes that predate the
header — XOR obfuscation names no version.
family: FamilyThe encryption family the version pair — and, for vMinor = 2, the fAES flag —
names.
key_data: Option<AlgorithmParams>Parameters governing the payload: agile <keyData>, standard encryption’s
EncryptionHeader plus EncryptionVerifier.SaltSize, or — for a 97-2003 binary
document — the keyBits its CryptoAPI EncryptionHeader exposes, which is the
only member of the tuple those formats give up without decrypting. The rest stay
None rather than being invented.
password_key: Option<AlgorithmParams>Parameters governing the password key encryptor: agile <p:encryptedKey>.
None for standard encryption, which has a single parameter set.
data_integrity: IntegrityDeclarationWhether a dataIntegrity element is declared (D1).
container_read: ContainerReadWhether the container’s directory could be read from the bytes supplied.
Read this before trusting a Unknown in any field above it:
ContainerRead::Unreadable means the bytes were too few or too damaged to look
inside, which is a different fact from having looked and found nothing.
Implementations§
Source§impl Classification
impl Classification
Sourcepub fn is_encrypted(&self) -> bool
pub fn is_encrypted(&self) -> bool
true when the file declares a password-to-open — an EncryptionInfo stream, or
a 97-2003 binary document’s own encryption marker — including a family this crate
cannot decrypt.
false also covers “nothing could be determined”: an EncryptionInfo too short to
hold a version pair leaves Family::Unknown, which is not a claim that the file
is plain.
Deliberately not “can I decrypt this”: see Classification::is_supported.
§Examples
use msoffice_crypto::classify;
assert!(classify(include_bytes!("../tests/fixtures/agile_encrypted.docx")).is_encrypted());
assert!(!classify(include_bytes!("../tests/fixtures/plain.docx")).is_encrypted());Sourcepub fn is_supported(&self) -> bool
pub fn is_supported(&self) -> bool
true when a decrypt path of this crate implements the (document, family) pair —
decrypt_ooxml for an OOXML package under crypto-ops, decrypt_binary_office
for a .doc, .xls or .ppt under legacy-binary. In a build without the
feature this still answers, and describes what enabling it would open.
Says nothing about whether the parameters are ones this crate accepts:
a legal agile file with a spinCount over the ceiling classifies as
Family::Agile, reports true here, and is refused at decrypt. Family-level,
not tuple-level, by design — the tuple is in Classification::key_data. The
document matters because the same family means different things in different
containers: an EncryptionInfo stream naming RC4 CryptoAPI is refused, a .doc
carrying it is read, and XOR obfuscation is read in a .xls and refused in a
.doc.
§Examples
use msoffice_crypto::classify;
assert!(classify(include_bytes!("../tests/fixtures/agile_encrypted.docx")).is_supported());
assert!(!classify(include_bytes!("../tests/fixtures/plain.docx")).is_supported());