pub enum SriAlgorithm {
Sha256,
Sha384,
Sha512,
}Expand description
Digest algorithm used for Subresource Integrity integrity=
attributes on externalized assets (v0.0.47 plan §3 item 2.3).
Applies to the SRI attributes emitted by the fingerprint plugin
(crate::assets::FingerprintPlugin) and the CSP inline-extraction
plugin (crate::csp::CspPlugin). It deliberately does not
govern CSP directive source hashes (the 'sha256-…' entries
inside a Content-Security-Policy header/meta value) — those stay
SHA-256 for the broadest UA compatibility.
Serialized in ssg.toml as the lowercase strings "sha256",
"sha384", and "sha512"; kept in lockstep with the
security.sri_algorithm enum in ssg.schema.json.
§Examples
use ssg::cmd::SriAlgorithm;
// SHA-384 is the default, matching the documented posture.
assert_eq!(SriAlgorithm::default(), SriAlgorithm::Sha384);
// Every emitted integrity value starts with the algorithm prefix.
let sri = SriAlgorithm::Sha512.integrity(b"body{margin:0}");
assert!(sri.starts_with("sha512-"));Variants§
Sha256
SHA-256 — the pre-v0.0.47 behaviour, kept for back-compat.
Sha384
SHA-384 — the default; matches the README/SECURITY.md claim.
Sha512
SHA-512 — the strongest digest the SRI spec admits.
Implementations§
Source§impl SriAlgorithm
impl SriAlgorithm
Sourcepub const fn prefix(self) -> &'static str
pub const fn prefix(self) -> &'static str
Returns the SRI prefix token for this algorithm
("sha256", "sha384", or "sha512").
§Examples
use ssg::cmd::SriAlgorithm;
assert_eq!(SriAlgorithm::default().prefix(), "sha384");
assert_eq!(SriAlgorithm::Sha256.prefix(), "sha256");Sourcepub fn integrity(self, data: &[u8]) -> String
pub fn integrity(self, data: &[u8]) -> String
Computes the full SRI attribute value for data:
<prefix>-<base64(digest(data))>.
Browsers compare the integrity attribute against
base64(digest(body)) per the
W3C SRI spec,
so the returned string is exactly what a UA will validate the
response body against.
§Examples
use ssg::cmd::SriAlgorithm;
// SHA-384("") — well-known empty-input digest.
assert_eq!(
SriAlgorithm::Sha384.integrity(b""),
"sha384-OLBgp1GsljhM2TJ+sbHjaiH9txEUvgdDTAzHv2P24donTt6/529l+9Ua0vFImLlb"
);Trait Implementations§
Source§impl Clone for SriAlgorithm
impl Clone for SriAlgorithm
Source§fn clone(&self) -> SriAlgorithm
fn clone(&self) -> SriAlgorithm
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for SriAlgorithm
Source§impl Debug for SriAlgorithm
impl Debug for SriAlgorithm
Source§impl Default for SriAlgorithm
impl Default for SriAlgorithm
Source§fn default() -> SriAlgorithm
fn default() -> SriAlgorithm
Source§impl<'de> Deserialize<'de> for SriAlgorithm
impl<'de> Deserialize<'de> for SriAlgorithm
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for SriAlgorithm
Source§impl PartialEq for SriAlgorithm
impl PartialEq for SriAlgorithm
Source§fn eq(&self, other: &SriAlgorithm) -> bool
fn eq(&self, other: &SriAlgorithm) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for SriAlgorithm
impl Serialize for SriAlgorithm
impl StructuralPartialEq for SriAlgorithm
Auto Trait Implementations§
impl Freeze for SriAlgorithm
impl RefUnwindSafe for SriAlgorithm
impl Send for SriAlgorithm
impl Sync for SriAlgorithm
impl Unpin for SriAlgorithm
impl UnsafeUnpin for SriAlgorithm
impl UnwindSafe for SriAlgorithm
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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