Skip to main content

EncryptError

Enum EncryptError 

Source
#[non_exhaustive]
pub enum EncryptError {
Show 13 variants Classify(DetectError), AlreadyEncrypted, PartiallyEncrypted, Odf12Fatal, EmptyPassword, Random(String), Params(ParamsReason), HostCannotAllocate { requested_bytes: usize, }, Deflate(String), Mimetype(String), Zip(String), Internal(String), Io(Error),
}
Available on crate feature crypto-ops only.
Expand description

Failures from encrypt.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Classify(DetectError)

classify() itself rejected the input (not a zip, no manifest, …).

§

AlreadyEncrypted

The package is encrypted and LibreOffice would prompt for a password: classify set crate::Classification::package_encrypted, the latch LibreOffice calls HasEncryptedEntries. Covers Wholesome, PerEntry with a latch row, and PGP rows alike.

Split from EncryptError::PartiallyEncrypted in 0.1.0-rc.5, because one variant was making a claim about the file that LibreOffice does not make – see that variant.

§

PartiallyEncrypted

The package holds complete encryption-data rows but no latch row, so classify reports crate::Mode::PerEntry with package_encrypted == false.

LibreOffice never asks for this file’s password. The latch is set only by a row resolving to content.xml or encrypted-package (ZipPackage.cxx:435-446), and the password prompt is gated on the latch, so a package whose only complete rows sit on other members is not, to LibreOffice, an encrypted document.

What happens instead was measured in rc.9 (tools/probe_unlatched.py, both orders): with styles.xml, settings.xml, meta.xml and manifest.rdf encrypted and content.xml plain, LibreOffice raises ERRCODE_SFX_WRONGPASSWORD without ever having asked, and refuses to open. Supplied the password programmatically it opens normally. Writer’s import (sw/source/filter/xml/swxml.cxx) maps an encrypted stream it cannot read to that error, so a package whose encrypted members are ones the load never reads may open; that variant was not measured.

Before rc.9 this doc said LibreOffice opens the file without prompting. That was inferred from the latch alone and is wrong for the measured shape; the “no prompt” half was right.

Reporting this as “package is already encrypted” would still tell a caller something the specifying implementation contradicts: to LibreOffice this is not an encrypted document.

Still refused, and the refusal is the same one: wrapping a package whose members are already ciphertext produces a file whose inner members nothing can open. What changed is the name of what was detected, not the decision. Both map to CLI exit 5.

LibreOffice’s own answer to this shape is worth knowing, because this crate cannot give it: on ODF >= 1.2 with the latch also set, it raises ERRCODE_SFX_INCOMPLETE_ENCRYPTION and disables macro execution (sfx2/source/doc/objmisc.cxx:1028-1063).

§

Odf12Fatal

LibreOffice would not open this plaintext package (odf12_fatal): unexpected streams and a root version >= 1.2. Refuse before Argon2id rather than wrapping a document LO rejects.

§

EmptyPassword

Mirrors crate::DecryptError::EmptyPassword / CreatePackageEncryptionData’s empty sequence.

§

Random(String)

CSPRNG failure – vanishingly rare, but a library must not panic for it.

§

Params(ParamsReason)

An Argon2Params tuple that cannot be used, carrying whose rule it broke — see ParamsReason.

Never returned for a tuple that is merely weak. Cost is the caller’s decision and this crate does not overrule it; see Argon2Params.

Deliberately distinct from EncryptError::Internal: this reports a value that came from the caller, which they can correct, where Internal reports an invariant of ours. It quotes only the caller’s own numbers and this crate’s bounds, never anything read out of a package.

§Do not render this as a problem with the document

It is a usage error: the tuple was wrong, the input package was never examined. It is raised by Argon2Params::new before encrypt_with_params is even called, so it says nothing about the bytes a caller passed. A consumer that renders it as “this file is damaged” tells the user the one thing it does not mean, and sends them looking at the wrong thing. The odf-crypto binary maps it to exit 1 (usage), not 6 (malformed), for the same reason.

§

HostCannotAllocate

This host could not allocate the working memory Argon2id needs.

Not an invalid tuple. params was validated when it was constructed; this is the machine declining, and the same call may succeed on a machine with more free memory. Lowering Argon2Params::m_kib is a legitimate response, but read Argon2Params first: the cost is stored in the file and binds every future reader on every device, so trading it away to fit today’s host is irreversible.

Fields

§requested_bytes: usize

The size, in bytes, of the working buffer Argon2id could not obtain: params.m_kib rounded up to whole blocks.

§

Deflate(String)

The input buffer cannot be deflated. compress_to_vec itself is infallible, so in practice this is the 1 GiB input-size rejection.

§

Mimetype(String)

The input’s own mimetype member cannot be carried into the output. Four reasons, all of which classify itself tolerates (its check is starts_with("application/vnd.") over the first 1024 bytes):

  • over 1 KiB, which is all classify ever looked at;
  • not valid UTF-8;
  • containing a character outside XML 1.0’s Char production, which would emit a manifest.xml real LibreOffice’s expat rejects;
  • containing a tab, LF or CR. Those are legal Chars, but XML attribute-value normalization rewrites each to a space on the way back in, so the verbatim mimetype zip member and the parsed manifest:media-type would then disagree.

All four fail closed rather than writing a package that classifies but will not open.

§

Zip(String)

A zip failure on either side: reading the input’s own mimetype member, or building the outer container encrypt writes. The string is a diagnostic; do not match on its content.

§

Internal(String)

A crypto primitive rejected parameters encrypt chose itself – the wholesome profile’s Argon2id tuple, its 32-byte key, its 12-byte nonce. Unreachable today: every one of those is a compile-time constant guarded by const asserts beside the profile, which is why this carries no recovery advice.

Not where a host’s inability to allocate Argon2id’s working memory lands: that is EncryptError::HostCannotAllocate, a distinct variant because it blames the machine, not a parameter a crypto primitive refused.

Also covers a supposedly infallible write failing: io::Write for Vec<u8> through quick-xml, when building the manifest.

It exists because the alternative is a panic in a library. This is deliberately not a BadParameters analogue: that variant would report an untrusted manifest field, which encrypt never reads. This reports an internal invariant a dependency bump could invalidate under us – if argon2 or aes-gcm ever narrows what it accepts, the failure surfaces as an Err a caller can handle rather than an abort it cannot.

§

Io(Error)

The caller’s reader or writer failed. Nothing is implied about the package. The error is the caller’s own value, so a cancellation can be recognized in it.

Trait Implementations§

Source§

impl Debug for EncryptError

Source§

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

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

impl Display for EncryptError

Source§

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

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

impl Error for EncryptError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<DetectError> for EncryptError

Source§

fn from(source: DetectError) -> Self

Converts to this type from the input type.
Source§

impl From<EncryptError> for ReencryptError

Source§

fn from(e: EncryptError) -> Self

Converts to this type from the input type.

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.