#[non_exhaustive]pub enum HashAlgorithm {
MD5,
SHA1,
RipeMD,
SHA256,
SHA384,
SHA512,
SHA224,
SHA3_256,
SHA3_512,
Private(u8),
Unknown(u8),
}
Expand description
The OpenPGP hash algorithms as defined in Section 9.5 of RFC 9580.
§Examples
Use HashAlgorithm
to set the preferred hash algorithms on a signature:
use sequoia_openpgp as openpgp;
use openpgp::packet::signature::SignatureBuilder;
use openpgp::types::{HashAlgorithm, SignatureType};
let mut builder = SignatureBuilder::new(SignatureType::DirectKey)
.set_hash_algo(HashAlgorithm::SHA512);
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
MD5
Rivest et.al. message digest 5.
SHA1
NIST Secure Hash Algorithm (deprecated)
RipeMD
RIPEMD-160
SHA256
256-bit version of SHA2
SHA384
384-bit version of SHA2
SHA512
512-bit version of SHA2
SHA224
224-bit version of SHA2
SHA3_256
256-bit version of SHA3
SHA3_512
512-bit version of SHA3
Private(u8)
Private hash algorithm identifier.
Unknown(u8)
Unknown hash algorithm identifier.
Implementations§
Source§impl HashAlgorithm
impl HashAlgorithm
Sourcepub fn is_supported(self) -> bool
pub fn is_supported(self) -> bool
Whether Sequoia supports this algorithm.
Source§impl HashAlgorithm
impl HashAlgorithm
Sourcepub fn context(self) -> Result<Builder>
pub fn context(self) -> Result<Builder>
Creates a new hash context for this algorithm.
§Errors
Fails with Error::UnsupportedHashAlgorithm
if Sequoia does
not support this algorithm. See
HashAlgorithm::is_supported
.
Sourcepub fn oid(self) -> Result<&'static [u8]>
pub fn oid(self) -> Result<&'static [u8]>
Returns the prefix of a serialized DigestInfo
structure
that contains the ASN.1 OID of this hash algorithm.
The prefix is used for encoding RSA signatures according to
the EMSA-PKCS1-v1_5
algorithm as specified in RFC 8017.
let algo = HashAlgorithm::SHA512;
let digest = // raw bytes of the digest
let digest_info = Vec::from(algo.oid()?).extend(digest);
§Errors
Fails with Error::UnsupportedHashAlgorithm
for unknown or
private hash algorithms.
Source§impl HashAlgorithm
impl HashAlgorithm
Sourcepub fn text_name(&self) -> Result<&str>
pub fn text_name(&self) -> Result<&str>
Returns the text name of this algorithm.
Section 9.5 of RFC 9580 defines a textual representation of hash algorithms. This is used in cleartext signed messages (see Section 7 of RFC 9580).
§Examples
assert_eq!(HashAlgorithm::RipeMD.text_name()?, "RIPEMD160");
Sourcepub fn digest_size(&self) -> Result<usize>
pub fn digest_size(&self) -> Result<usize>
Returns the digest size for this algorithm.
Sourcepub fn salt_size(&self) -> Result<usize>
pub fn salt_size(&self) -> Result<usize>
Returns the salt size for this algorithm.
Version 6 signatures salt the hash, and the size of the hash is dependent on the hash algorithm.
Sourcepub fn variants() -> impl Iterator<Item = Self>
pub fn variants() -> impl Iterator<Item = Self>
Returns an iterator over all valid variants.
Returns an iterator over all known variants. This does not
include the HashAlgorithm::Private
, or
HashAlgorithm::Unknown
variants.
Trait Implementations§
Source§impl Clone for HashAlgorithm
impl Clone for HashAlgorithm
Source§fn clone(&self) -> HashAlgorithm
fn clone(&self) -> HashAlgorithm
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read more