Skip to content

Commit

Permalink
algorithm-registry: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
baloo committed Nov 19, 2023
1 parent df6d2f4 commit 032aca4
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 2 deletions.
121 changes: 120 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
resolver = "2"
members = [
"algorithm-registry",
"blobby",
"block-buffer",
"block-padding",
Expand All @@ -15,7 +16,7 @@ members = [
"opaque-debug",
"wycheproof2blb",
"zeroize",
"zeroize/derive"
"zeroize/derive",
]

[profile.dev]
Expand Down
29 changes: 29 additions & 0 deletions algorithm-registry/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "algorithm-registry"
version = "0.1.0"
description = """
Utility to lookup algorithms from their OID
"""
authors = ["RustCrypto Developers"]
license = "MIT OR Apache-2.0"
readme = "README.md"
edition = "2018"
documentation = "https://docs.rs/algorithm-db"
repository = "https://github.com/RustCrypto/hashes"
categories = ["cryptography"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
const-oid = { version = "0.9" }
digest = "0.10.7"

sha1 = { version = "0.10.6", features = ["oid"], optional = true }
sha2 = { version = "0.10.8", features = ["oid"], optional = true }
sha3 = { version = "0.10.8", features = ["oid"], optional = true }

[features]
default = ["sha1", "sha2", "sha3"]
sha1 = ["dep:sha1"]
sha2 = ["dep:sha2"]
sha3 = ["dep:sha3"]
9 changes: 9 additions & 0 deletions algorithm-registry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# [RustCrypto]: Algorithm Registry

Registry allows a user to dynamically lookup an implementation of algorithm by OID.
This is used for validation of certificates and other structures.


[//]: # (links)

[RustCrypto]: https://github.com/rustcrypto
36 changes: 36 additions & 0 deletions algorithm-registry/src/digest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use const_oid::{AssociatedOid, ObjectIdentifier};
use digest::{Digest, DynDigest};

/// [`get_digest`] would lookup the
pub fn get_digest(identifier: ObjectIdentifier) -> Option<Box<dyn DynDigest>> {
macro_rules! check_match {
($h:ty) => {
if (identifier == <$h as AssociatedOid>::OID) {
return Some(Box::new(<$h>::new()));
}
};
}

#[cfg(feature = "sha1")]
{
check_match!(sha1::Sha1);
}

#[cfg(feature = "sha2")]
{
check_match!(sha2::Sha224);
check_match!(sha2::Sha256);
check_match!(sha2::Sha384);
check_match!(sha2::Sha512);
}

#[cfg(feature = "sha3")]
{
check_match!(sha3::Sha3_224);
check_match!(sha3::Sha3_256);
check_match!(sha3::Sha3_384);
check_match!(sha3::Sha3_512);
}

None
}
4 changes: 4 additions & 0 deletions algorithm-registry/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#![doc = include_str!("../README.md")]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]

pub mod digest;

0 comments on commit 032aca4

Please sign in to comment.