pub struct DigestAlgorithm(/* private fields */);
Expand description

The digest algorithms used by RPKI.

These are the algorithms used by the signature algorithms. For use in RPKI, RFC 7935 limits them to exactly one, SHA-256. Because of that, this type is currently a zero-sized struct. If additional algorithms are ever introduced in the future, it will change into an enum.

Implementations§

source§

impl DigestAlgorithm

source

pub fn sha256() -> Self

Creates a value representing the SHA-256 algorithm.

source

pub fn is_sha256(self) -> bool

Returns whether the algorithm is in fact SHA-256.

source

pub fn digest_len(&self) -> usize

Returns the digest size in octets for this algorithm.

source§

impl DigestAlgorithm

source

pub fn digest(self, data: &[u8]) -> Digest

Returns the digest of data using this algorithm.

source

pub fn digest_file(self, path: impl AsRef<Path>) -> Result<Digest, Error>

Calculates the digest for the content of a file.

source

pub fn start(self) -> Context

Returns a digest context for multi-step calculation of the digest.

source§

impl DigestAlgorithm

ASN.1 Values

Digest algorithms appear in CMS either alone or in sets with the following syntax:

DigestAlgorithmIdentifiers ::= SET OF DigestAlgorithmIdentifier
DigestAlgorithmIdentifier  ::= AlgorithmIdentifier
AlgorithmIdentifier        ::= SEQUENCE {
     algorithm                 OBJECT IDENTIFIER,
     parameters                ANY DEFINED BY algorithm OPTIONAL }

In RPKI signed objects, a set is limited to exactly one identifer. The allowed algorithms are limited, too. In particular, RFC 7935 only allows SHA-256. Its algorithm identifier is defined in RFC 5754. The object identifier to be used is id-sha256. When encoding, the parameters field must be absent, whereas when decoding, it may either be absent or NULL.

Note that this differs from SignatureAlgorithm identifiers where the NULL must be present when encoding.

The functions and methods in this section allow decoding and encoding such values.

source

pub fn take_from<S: Source>( cons: &mut Constructed<'_, S> ) -> Result<Self, DecodeError<S::Error>>

Takes and returns a single digest algorithm identifier.

Returns a malformed error if the algorithm isn’t one of the allowed algorithms or if the value isn’t correctly encoded.

source

pub fn take_opt_from<S: Source>( cons: &mut Constructed<'_, S> ) -> Result<Option<Self>, DecodeError<S::Error>>

Takes and returns an optional digest algorithm identifier.

Returns Ok(None) if the next value isn’t a sequence. Returns a malformed error if the sequence isn’t a correctly encoded algorithm identifier or if algorithm isn’t one of the allowed algorithms.

source

pub fn take_set_from<S: Source>( cons: &mut Constructed<'_, S> ) -> Result<Self, DecodeError<S::Error>>

Takes and returns a set of digest algorithm identifiers.

The set must contain exactly one identifier as required everywhere for RPKI. If it contains more than one or identifiers that are not allowed, a malformed error is returned.

source

pub fn skip_set<S: Source>( cons: &mut Constructed<'_, S> ) -> Result<(), DecodeError<S::Error>>

Parses a SET OF DigestAlgorithmIdentifiers.

This is used in the digestAlgorithms field of the SignedData container. It provides all the digest algorithms used later on, so that the data can be read over. We don’t really need this, so this function returns () on success.

Section 2.1.2. of RFC 6488 requires there to be exactly one element chosen from the allowed values.

source

pub fn take_oid_from<S: Source>( cons: &mut Constructed<'_, S> ) -> Result<Self, DecodeError<S::Error>>

Takes a single algorithm object identifier from a constructed value.

source

pub fn encode(self) -> impl Values

Provides an encoder for a single algorithm identifier.

source

pub fn encode_set(self) -> impl Values

Provides an encoder for a indentifer as the sole value of a set.

source

pub fn encode_oid(self) -> impl Values

Provides an encoder for just the object identifier of the algorithm.

Trait Implementations§

source§

impl Clone for DigestAlgorithm

source§

fn clone(&self) -> DigestAlgorithm

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for DigestAlgorithm

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for DigestAlgorithm

source§

fn default() -> DigestAlgorithm

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

impl Hash for DigestAlgorithm

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl PartialEq for DigestAlgorithm

source§

fn eq(&self, other: &DigestAlgorithm) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for DigestAlgorithm

source§

impl Eq for DigestAlgorithm

source§

impl StructuralEq for DigestAlgorithm

source§

impl StructuralPartialEq for DigestAlgorithm

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.