Skip to main content

Decryptor

Enum Decryptor 

Source
#[non_exhaustive]
pub enum Decryptor { Passphrase(PassphraseDecryptor), PrivateKey(PrivateKeyDecryptor), }
Expand description

Type-safe entry point for decryption.

Decryptor::open reads the .fcr header without cryptographic work and returns the variant that matches the file’s recipient kind. Each variant takes only the credentials it can use:

A mismatched-credential call — e.g. trying to decrypt a passphrase-sealed file with a PrivateKey — is therefore a compile error rather than a runtime CryptoError::DecryptorModeMismatch failure.

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.
§

Passphrase(PassphraseDecryptor)

File is sealed with a passphrase. Decrypt via PassphraseDecryptor::decrypt.

§

PrivateKey(PrivateKeyDecryptor)

File is sealed to one or more public-key recipients. Decrypt via PrivateKeyDecryptor::decrypt.

Implementations§

Source§

impl Decryptor

Source

pub fn open(input: impl AsRef<Path>) -> Result<Self, CryptoError>

Probes the .fcr header (cheap structural read; no recipient unwrap, no MAC, no payload bytes touched) and returns the matching variant.

§Errors

Returns CryptoError::InputPath if input does not exist and CryptoError::InvalidInput if input is a directory. Files that do not contain a FerroCrypt header return CryptoError::InvalidFormat with FormatDefect::BadMagic. Malformed headers, unsupported versions, unknown critical recipients, and illegal recipient mixes return their corresponding CryptoError or FormatDefect variants.

Source

pub fn open_with_limits( input: impl AsRef<Path>, header_read_limits: HeaderReadLimits, ) -> Result<Self, CryptoError>

Same as Decryptor::open but uses the supplied HeaderReadLimits for the structural header read instead of the conservative defaults.

Callers handling files whose recipient strings, recipient counts, or header lengths legitimately exceed the defaults (for example, forward-compatible files with larger future recipient bodies) should construct a HeaderReadLimits via the builder methods and pass it here. The same limits are stashed on the returned variant so the second header read inside PassphraseDecryptor::decrypt / PrivateKeyDecryptor::decrypt uses them too — callers do not need to set them twice.

§Errors

Returns the same errors as Decryptor::open, but applies the supplied HeaderReadLimits during structural header parsing.

Trait Implementations§

Source§

impl Debug for Decryptor

Source§

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

Formats the value using the given formatter. Read more

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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.