#[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),
}crypto-ops only.Expand description
Failures from encrypt.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
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
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
classifyever looked at; - not valid UTF-8;
- containing a character outside XML 1.0’s
Charproduction, which would emit amanifest.xmlreal 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 verbatimmimetypezip member and the parsedmanifest:media-typewould 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
impl Debug for EncryptError
Source§impl Display for EncryptError
impl Display for EncryptError
Source§impl Error for EncryptError
impl Error for EncryptError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<DetectError> for EncryptError
impl From<DetectError> for EncryptError
Source§fn from(source: DetectError) -> Self
fn from(source: DetectError) -> Self
Source§impl From<EncryptError> for ReencryptError
impl From<EncryptError> for ReencryptError
Source§fn from(e: EncryptError) -> Self
fn from(e: EncryptError) -> Self
Auto Trait Implementations§
impl !RefUnwindSafe for EncryptError
impl !UnwindSafe for EncryptError
impl Forget for EncryptError
impl Freeze for EncryptError
impl Move for EncryptError
impl Send for EncryptError
impl Sync for EncryptError
impl Unpin for EncryptError
impl UnsafeUnpin for EncryptError
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> 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