summaryrefslogtreecommitdiffstats
path: root/vendor/spki/src/fingerprint.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:41:41 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:41:41 +0000
commit10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87 (patch)
treebdffd5d80c26cf4a7a518281a204be1ace85b4c1 /vendor/spki/src/fingerprint.rs
parentReleasing progress-linux version 1.70.0+dfsg1-9~progress7.99u1. (diff)
downloadrustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.tar.xz
rustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.zip
Merging upstream version 1.70.0+dfsg2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/spki/src/fingerprint.rs')
-rw-r--r--vendor/spki/src/fingerprint.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/vendor/spki/src/fingerprint.rs b/vendor/spki/src/fingerprint.rs
new file mode 100644
index 000000000..6a3901fb1
--- /dev/null
+++ b/vendor/spki/src/fingerprint.rs
@@ -0,0 +1,43 @@
+//! SPKI fingerprint support.
+
+use der::Writer;
+use sha2::{Digest, Sha256};
+
+/// Size of a SHA-256 SPKI fingerprint in bytes.
+pub(crate) const SIZE: usize = 32;
+
+/// Raw bytes of a SPKI fingerprint i.e. SHA-256 digest of
+/// `SubjectPublicKeyInfo`'s DER encoding.
+///
+/// See [RFC7469 § 2.1.1] for more information.
+///
+/// [RFC7469 § 2.1.1]: https://datatracker.ietf.org/doc/html/rfc7469#section-2.1.1
+#[cfg_attr(docsrs, doc(cfg(feature = "fingerprint")))]
+pub type FingerprintBytes = [u8; SIZE];
+
+/// Writer newtype which accepts DER being serialized on-the-fly and computes a
+/// hash of the contents.
+#[derive(Clone, Default)]
+pub(crate) struct Builder {
+ /// In-progress digest being computed from streaming DER.
+ digest: Sha256,
+}
+
+impl Builder {
+ /// Create a new fingerprint builder.
+ pub fn new() -> Self {
+ Self::default()
+ }
+
+ /// Finish computing a fingerprint, returning the computed digest.
+ pub fn finish(self) -> FingerprintBytes {
+ self.digest.finalize().into()
+ }
+}
+
+impl Writer for Builder {
+ fn write(&mut self, der_bytes: &[u8]) -> der::Result<()> {
+ self.digest.update(der_bytes);
+ Ok(())
+ }
+}