#[non_exhaustive]pub enum HashAlgorithm {
Sha1,
Sha256,
Sha384,
Sha512,
}Expand description
The hash a file names.
This is the same enum the decrypt path runs on (hash.rs adds the digest, HMAC and
IV-derivation operations to it under the crypto-ops feature), so there is one
spelling table rather than a reporting copy that can drift from an operational one.
Reported as Option<HashAlgorithm>, with None meaning absent or not one of the
four this crate implements.
§Examples
use msoffice_crypto::{classify, HashAlgorithm};
let class = classify(include_bytes!("../tests/fixtures/agile_encrypted.docx"));
assert_eq!(class.key_data.unwrap().hash, Some(HashAlgorithm::Sha512));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Sha1
SHA-1, 20-byte digest.
Sha256
SHA-256, 32-byte digest.
Sha384
SHA-384, 48-byte digest.
Sha512
SHA-512, 64-byte digest. What Office 16 writes for agile.
Implementations§
Source§impl HashAlgorithm
impl HashAlgorithm
Sourcepub fn name(self) -> &'static str
Available on crate feature crypto-ops only.
pub fn name(self) -> &'static str
crypto-ops only.The unhyphenated ECMA-376 spelling — what Office writes, and what this crate
prints in errors. HashAlgorithm::parse also accepts the hyphenated form
(SHA-1), so a file that used it is reported back in the canonical spelling
rather than in its own.
pub rather than pub(crate) for the same reason as Self::digest_len: the
spelling is the one a caller has to put back into hashAlgorithm when it
describes its own parameters, and it is not derivable from Debug, which prints
the Rust variant name (Sha512) and not the attribute value (SHA512).
Sourcepub fn digest_len(self) -> usize
Available on crate feature crypto-ops only.
pub fn digest_len(self) -> usize
crypto-ops only.Digest length in bytes. A hashSize attribute is checked against this before it
is trusted as a truncation length, and keyBits / 8 before it is trusted as one.
Why this is pub when everything else on this impl is internal. It is a fact
about SHA, not about this crate — FIPS 180-4 fixes all four numbers, and no
decision of ours can move them. What is ours is the coupling it feeds: a caller
choosing encryption parameters meets a refusal when keyBits / 8 exceeds the
digest of the hash it named (can_carry_key_bits, internal), and without this
number it cannot reason about that rule before it trips over it — it would have
to hardcode the same four constants to predict our own error. hashSize is not
a companion to this: [MS-OFFCRYPTO] §2.3.4.10 requires it to equal the named
hash’s digest length, so it is derived from this value rather than chosen beside
it, which is why no setter for it exists.