]>
git.proxmox.com Git - rustc.git/blob - vendor/spki/src/fingerprint.rs
1 //! SPKI fingerprint support.
4 use sha2
::{Digest, Sha256}
;
6 /// Size of a SHA-256 SPKI fingerprint in bytes.
7 pub(crate) const SIZE
: usize = 32;
9 /// Raw bytes of a SPKI fingerprint i.e. SHA-256 digest of
10 /// `SubjectPublicKeyInfo`'s DER encoding.
12 /// See [RFC7469 § 2.1.1] for more information.
14 /// [RFC7469 § 2.1.1]: https://datatracker.ietf.org/doc/html/rfc7469#section-2.1.1
15 pub type FingerprintBytes
= [u8; SIZE
];
17 /// Writer newtype which accepts DER being serialized on-the-fly and computes a
18 /// hash of the contents.
19 #[derive(Clone, Default)]
20 pub(crate) struct Builder
{
21 /// In-progress digest being computed from streaming DER.
26 /// Create a new fingerprint builder.
27 pub fn new() -> Self {
31 /// Finish computing a fingerprint, returning the computed digest.
32 pub fn finish(self) -> FingerprintBytes
{
33 self.digest
.finalize().into()
37 impl Writer
for Builder
{
38 fn write(&mut self, der_bytes
: &[u8]) -> der
::Result
<()> {
39 self.digest
.update(der_bytes
);