Skip to content

Commit

Permalink
Merge pull request #2 from csssuf/yasna
Browse files Browse the repository at this point in the history
types: use yasna for OIDs instead of simple_asn1
  • Loading branch information
csssuf authored Mar 7, 2018
2 parents d68df91 + 43c9e91 commit 9352850
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ categories = ["cryptography", "parser-implementations"]
license = "Apache-2.0"

[dependencies]
simple_asn1 = "0.1"
byteorder = "1.2"
digest = "0.7"
failure = "0.1"
Expand All @@ -20,6 +19,7 @@ num = "0.1.40"
ripemd160 = "0.7"
sha-1 = "0.7"
sha2 = "0.7"
yasna = "0.1.3"

[dependencies.nom]
version = "^3.2"
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
//! [`Packet::to_bytes`]: enum.Packet.html#method.to_bytes
//! [`Packet::from_bytes`]: enum.Packet.html#method.from_bytes
//! [`SignaturePacket`]: struct.SignaturePacket.html
#[macro_use]
extern crate simple_asn1;
extern crate byteorder;
extern crate digest;
#[macro_use]
Expand All @@ -32,6 +30,7 @@ extern crate num;
extern crate ripemd160;
extern crate sha1;
extern crate sha2;
extern crate yasna;

mod packet;
mod signature;
Expand Down
27 changes: 17 additions & 10 deletions src/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use simple_asn1::OID;
use digest::Digest;
use failure::Error;
use num::BigUint;
use yasna::models::ObjectIdentifier;

/// Type for public key algorithms supported by OpenPGP.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -102,15 +101,23 @@ macro_rules! hash {
}

impl HashAlgorithm {
pub fn asn1_oid(&self) -> Result<OID, Error> {
pub fn asn1_oid(&self) -> Result<ObjectIdentifier, Error> {
let oid = match *self {
HashAlgorithm::Md5 => oid![1, 2, 840, 113549, 2, 5],
HashAlgorithm::Sha1 => oid![1, 3, 14, 3, 2, 26],
HashAlgorithm::Ripemd160 => oid![1, 3, 36, 3, 2, 1],
HashAlgorithm::Sha256 => oid![2, 16, 840, 1, 101, 3, 4, 2, 1],
HashAlgorithm::Sha384 => oid![2, 16, 840, 1, 101, 3, 4, 2, 2],
HashAlgorithm::Sha512 => oid![2, 16, 840, 1, 101, 3, 4, 2, 3],
HashAlgorithm::Sha224 => oid![2, 16, 840, 1, 101, 3, 4, 2, 4],
HashAlgorithm::Md5 => ObjectIdentifier::from_slice(&[1, 2, 840, 113_549, 2, 5]),
HashAlgorithm::Sha1 => ObjectIdentifier::from_slice(&[1, 3, 14, 3, 2, 26]),
HashAlgorithm::Ripemd160 => ObjectIdentifier::from_slice(&[1, 3, 36, 3, 2, 1]),
HashAlgorithm::Sha256 => {
ObjectIdentifier::from_slice(&[2, 16, 840, 1, 101, 3, 4, 2, 1])
}
HashAlgorithm::Sha384 => {
ObjectIdentifier::from_slice(&[2, 16, 840, 1, 101, 3, 4, 2, 2])
}
HashAlgorithm::Sha512 => {
ObjectIdentifier::from_slice(&[2, 16, 840, 1, 101, 3, 4, 2, 3])
}
HashAlgorithm::Sha224 => {
ObjectIdentifier::from_slice(&[2, 16, 840, 1, 101, 3, 4, 2, 4])
}
HashAlgorithm::Unknown => bail!(AlgorithmError::HashAlgorithmError),
};

Expand Down

0 comments on commit 9352850

Please sign in to comment.