[−][src]Struct ssri::Integrity
Representation of a full Subresource Integrity string.
Integrity
can be used for parsing and also includes convenience methods
for shorthand versions of IntegrityOpts
and
IntegrityChecker
.
Example
let source = "sha256-uU0nuZNNPgilLlLX2n2r+sSE7+N6U4DukIj3rOLvzek="; let parsed: Integrity = source.parse().unwrap(); assert_eq!(parsed.to_string(), source);
Fields
hashes: Vec<Hash>
Implementations
impl Integrity
[src]
pub fn pick_algorithm(&self) -> Algorithm
[src]
Pick the most secure available Algorithm
in this Integrity
.
Example
use ssri::{Integrity, Algorithm}; let sri: Integrity = "sha1-deadbeef sha256-badc0ffee".parse().unwrap(); let algorithm = sri.pick_algorithm(); assert_eq!(algorithm, Algorithm::Sha256);
pub fn from<B: AsRef<[u8]>>(data: B) -> Integrity
[src]
Create a new Integrity
based on data
. Use
IntegrityOpts
for more options.
Example
use ssri::Integrity; let sri = Integrity::from(b"hello"); assert_eq!(sri.to_string(), "sha256-LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=".to_owned());
pub fn concat(&self, other: Integrity) -> Self
[src]
Join together two Integrity
instances. Hashes will be grouped and
sorted by algorithm but otherwise kept in the same order.
Example
use ssri::Integrity; let sri1: Integrity = "sha256-deadbeef".parse().unwrap(); let sri2: Integrity = "sha256-badc0ffee".parse().unwrap(); let sri3 = sri1.concat(sri2); assert_eq!(sri3.to_string(), "sha256-deadbeef sha256-badc0ffee".to_owned());
pub fn check<B: AsRef<[u8]>>(&self, data: B) -> Result<Algorithm, Error>
[src]
Check some data against this Integrity
. For more options, use
Checker
.
Example
use ssri::{Algorithm, Integrity}; let sri = Integrity::from(b"hello"); let algorithm = sri.check(b"hello").unwrap(); assert_eq!(algorithm, Algorithm::Sha256);
pub fn to_hex(&self) -> (Algorithm, String)
[src]
Converts the first Hash
in this Integrity
into its hex string
format.
Example
use ssri::{Algorithm, Integrity}; let sri = Integrity::from(b"hello"); let (algo, hex) = sri.to_hex(); assert_eq!(algo, Algorithm::Sha256); assert_eq!(hex, "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824".to_owned());
pub fn matches(&self, other: &Self) -> Option<Algorithm>
[src]
Compares self
against a given SRI to see if there's a match. The
deciding algorithm is determined by other
.
Example
use ssri::{Algorithm, Integrity}; let sri1 = Integrity::from(b"hello"); let sri2 = Integrity::from(b"hello").concat(Integrity::from(b"world")); let m = sri1.matches(&sri2); assert_eq!(m, Some(Algorithm::Sha256));
Trait Implementations
impl Clone for Integrity
[src]
impl Debug for Integrity
[src]
impl<'de> Deserialize<'de> for Integrity
[src]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
impl Display for Integrity
[src]
impl Eq for Integrity
[src]
impl FromStr for Integrity
[src]
type Err = Error
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Integrity, Self::Err>
[src]
Parses a string into an Integrity instance.
Example
use ssri::Integrity; let sri: Integrity = "sha256-deadbeef".parse().unwrap(); assert_eq!(sri.to_string(), String::from("sha256-deadbeef"));
impl PartialEq<Integrity> for Integrity
[src]
impl Serialize for Integrity
[src]
impl StructuralEq for Integrity
[src]
impl StructuralPartialEq for Integrity
[src]
Auto Trait Implementations
impl RefUnwindSafe for Integrity
impl Send for Integrity
impl Sync for Integrity
impl Unpin for Integrity
impl UnwindSafe for Integrity
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,