logo
#[non_exhaustive]
pub enum S2K {
    Iterated {
        hash: HashAlgorithm,
        salt: [u8; 8],
        hash_bytes: u32,
    },
    Salted {
        hash: HashAlgorithm,
        salt: [u8; 8],
    },
    Simple {
        hash: HashAlgorithm,
    },
    Private {
        tag: u8,
        parameters: Option<Box<[u8]>>,
    },
    Unknown {
        tag: u8,
        parameters: Option<Box<[u8]>>,
    },
}
Expand description

String-to-Key (S2K) specifiers.

String-to-key (S2K) specifiers are used to convert password strings into symmetric-key encryption/decryption keys. See Section 3.7 of RFC 4880. This is used to encrypt messages with a password (see SKESK), and to protect secret keys (see key::Encrypted).

Note: This enum cannot be exhaustively matched to allow future extensions.

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.

Iterated

Fields

hash: HashAlgorithm

Hash used for key derivation.

salt: [u8; 8]

Public salt value mixed into the password.

hash_bytes: u32

Number of bytes to hash.

This parameter increases the workload for an attacker doing a dictionary attack. Note that not all values are representable. See S2K::new_iterated.

Repeatently hashes the password with a public salt value.

Salted

Fields

hash: HashAlgorithm
👎 Deprecated:

Use S2K::Iterated.

Hash used for key derivation.

salt: [u8; 8]
👎 Deprecated:

Use S2K::Iterated.

Public salt value mixed into the password.

👎 Deprecated:

Use S2K::Iterated.

Hashes the password with a public salt value.

This mechanism does not use iteration to increase the time it takes to derive the key from the password. This makes dictionary attacks more feasible. Do not use this variant.

Simple

Fields

hash: HashAlgorithm
👎 Deprecated:

Use S2K::Iterated.

Hash used for key derivation.

👎 Deprecated:

Use S2K::Iterated.

Simply hashes the password.

This mechanism uses neither iteration to increase the time it takes to derive the key from the password nor does it salt the password. This makes dictionary attacks more feasible.

This mechanism has been deprecated in RFC 4880. Do not use this variant.

Private

Fields

tag: u8

Tag identifying the private algorithm.

Tags 100 to 110 are reserved for private use.

parameters: Option<Box<[u8]>>

The parameters for the private algorithm.

This is optional, because when we parse a packet containing an unknown S2K algorithm, we do not know how many octets to attribute to the S2K’s parameters. In this case, parameters is set to None. Note that the information is not lost, but stored in the packet. If the packet is serialized again, it is written out.

Private S2K algorithm.

Unknown

Fields

tag: u8

Tag identifying the unknown algorithm.

parameters: Option<Box<[u8]>>

The parameters for the unknown algorithm.

This is optional, because when we parse a packet containing an unknown S2K algorithm, we do not know how many octets to attribute to the S2K’s parameters. In this case, parameters is set to None. Note that the information is not lost, but stored in the packet. If the packet is serialized again, it is written out.

Unknown S2K algorithm.

Implementations

Creates a new iterated S2K object.

Usually, you should use S2Ks Default implementation to create S2K objects with sane default parameters. The parameters are chosen with contemporary machines in mind, and should also be usable on lower-end devices like smart phones.

Using this method, you can tune the parameters for embedded devices. Note, however, that this also decreases the work factor for attackers doing dictionary attacks.

Derives a key of the given size from a password.

Returns whether this S2K mechanism is supported.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

Writes a serialized version of the object to o.

Exports a serialized version of the object to o. Read more

Computes the maximal length of the serialized representation. Read more

Serializes into the given buffer. Read more

Serializes the packet to a vector.

Exports into the given buffer. Read more

Exports to a vector. Read more

Reads an S2K from reader.

Reads from the given file. Read more

Reads from the given slice. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self

The resulting type after obtaining ownership.

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

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.