Skip to main content

Classification

Struct Classification 

Source
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: Mode

Which zip shape the package is in.

§package_encrypted: bool

LibreOffice HasEncryptedEntries — the latch, not “any encryption-data”.

§has_non_encrypted_entries: bool

LibreOffice 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: bool

Root 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: bool

LookForUnexpectedODF12Streams. Always computed.

§odf12_fatal: bool

has_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

Source

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:

rowcipherkdf
content.xml (first, so it is common)AES-256-GCMArgon2id
encrypted-package (what decrypt uses)AES-256-CBCPBKDF2

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Classification

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Classification

Source§

impl PartialEq for Classification

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Classification

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.