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>,
}Expand description
Result of crate::classify.
Fields§
§mode: ModeWhich zip shape the package is in.
package_encrypted: boolLibreOffice HasEncryptedEntries — the latch, not “any encryption-data”.
has_non_encrypted_entries: boolLibreOffice HasNonEncryptedEntries: some manifest row resolves to a
stream without a complete encryption-data tuple
(ZipPackage.cxx:446, the else of the test that admits a row to
Classification::encrypted_entries).
It is the other half of a predicate LibreOffice acts on.
SfxObjectShell::CheckEncryption_Impl (sfx2/source/doc/objmisc.cxx:1028-1063)
reads both flags, and on a package whose root version is ODF 1.2 or later
with HasEncryptedEntries && HasNonEncryptedEntries it raises
ERRCODE_SFX_INCOMPLETE_ENCRYPTION – “this is an encrypted document with
nonencrypted streams inside, show the warning” – and disables macro
execution. So a consumer reproduces LibreOffice’s behavior with:
package_encrypted && has_non_encrypted_entries && odf_version >= "1.2"the version compared byte-lexicographically, as
Classification::odf_version describes.
Only manifest-listed streams count. A zip member the manifest never
names – mimetype, META-INF/manifest.xml – is not a row upstream
and sets nothing.
odf_version: Option<String>The package’s ODF version, from the root folder — the first non-empty
manifest:version in the manifest, falling back to the one implied by
the mimetype member.
None when no row declares one, which is normal for older packages.
Compared byte-lexicographically, not numerically, when deciding
Classification::odf12_fatal — so "1.10" sorts below "1.2", as it
does in LibreOffice.
zip_has_encrypted_package: boolRoot entry named encrypted-package in the zip’s folder tree, not an
XML-only path — a member path such as encrypted-package/x synthesizes
that entry as a folder and also sets this. Feeds the unexpected-streams
test and root media-type selection, so it is not inert.
media_type: Option<String>Root-folder manifest:media-type, the document’s MIME type.
common: Option<EntryEncryption>The row that decided the package is encrypted, and the one to read when
you want the package’s encryption parameters without walking
Classification::encrypted_entries.
It is the first accepted row resolving to content.xml or
encrypted-package — the same row that sets
Classification::package_encrypted, so the two are Some/true
together. A clone, not a borrow: the same entry also appears in
encrypted_entries.
For a Mode::Wholesome package this is not necessarily the row
decrypt acts on — use Classification::wholesome_row if what you
want is the payload’s cipher or KDF. The latch is first-wins, so a
manifest carrying a complete content.xml row and a complete
encrypted-package row takes common from the first and its
Wholesome verdict from the second. That doc has the worked case.
None for a Mode::Plain package, and also for one whose only
complete rows sit on other members — encrypted entries can exist with no
latch row, which is why package_encrypted is not
!encrypted_entries.is_empty(). That shape – !package_encrypted && !encrypted_entries.is_empty() – is the one
EncryptError::PartiallyEncrypted names: LibreOffice opens it without
asking for a password.
encrypted_entries: Vec<EntryEncryption>Every member that resolved to a complete encryption-data row, in
manifest order.
has_unexpected_streams: boolLookForUnexpectedODF12Streams. Always computed.
odf12_fatal: boolhas_unexpected_streams && root version >= "1.2" (byte-lexicographic).
LibreOffice throws rather than opening; decrypt and encrypt refuse
the same packages so they do not unwrap or wrap something LO would reject.
pgp_keys: Vec<EncryptedKey>PGP encrypted-key material from the first file-entry’s key info, if any.
Present so a caller can hand it to an OpenPGP implementation; this crate
refuses such packages.
Implementations§
Source§impl Classification
impl Classification
Sourcepub fn wholesome_row(&self) -> Option<&EntryEncryption>
pub fn wholesome_row(&self) -> Option<&EntryEncryption>
The row decrypt acts on for a Mode::Wholesome
package — the one resolving to encrypted-package.
None for Mode::Plain, and None for Mode::PerEntry, where
there is no single payload row: decrypt acts on every entry in
Classification::encrypted_entries.
§Why this is not Classification::common
They can be different rows, and the difference is constructible.
common is the latch row — the first accepted row resolving to
content.xml or encrypted-package, reproducing LibreOffice’s
HasEncryptedEntries (ZipPackage.cxx), which is first-wins. Whether
the package is Wholesome is decided separately, by whether a complete
encrypted-package row exists at all.
So a manifest carrying a complete content.xml row and a complete
encrypted-package row is Wholesome because of the second while
common came from the first:
| row | cipher | kdf |
|---|---|---|
content.xml (first, so it is common) | AES-256-GCM | Argon2id |
encrypted-package (what decrypt uses) | AES-256-CBC | PBKDF2 |
Reading common there reports the modern profile for a package whose
payload is neither. LibreOffice does not write such a file; an attacker
can. If you are asking what cipher or KDF the payload actually uses,
this method is the question you meant.
decrypt calls this, so the two cannot drift.
§Examples
use odf_crypto::{classify, Cipher, Mode};
let class = classify(bytes)?;
if class.mode == Mode::Wholesome {
// Right: the row the payload is actually sealed with.
let row = class.wholesome_row().expect("Wholesome implies this row");
let modern = row.cipher == Cipher::AesGcmW3c;
let _ = modern;
}Trait Implementations§
Source§impl Clone for Classification
impl Clone for Classification
Source§impl Debug for Classification
impl Debug for Classification
impl Eq for Classification
Source§impl PartialEq for Classification
impl PartialEq for Classification
impl StructuralPartialEq for Classification
Auto Trait Implementations§
impl Forget for Classification
impl Freeze for Classification
impl Move for Classification
impl RefUnwindSafe for Classification
impl Send for Classification
impl Sync for Classification
impl Unpin for Classification
impl UnsafeUnpin for Classification
impl UnwindSafe for Classification
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more