-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
200 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |