Skip to content

Commit 45f1f53

Browse files
committed
types: use simple_asn1 crate for OIDs
1 parent 22e725e commit 45f1f53

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,18 @@ categories = ["cryptography", "parser-implementations"]
1010
license = "Apache-2.0"
1111

1212
[dependencies]
13+
simple_asn1 = "0.1"
1314
byteorder = "1.2"
1415
digest = "0.7"
1516
failure = "0.1"
1617
failure_derive = "0.1"
1718
gcrypt = "0.5"
1819
md-5 = "0.7"
20+
num = "0.1.40"
1921
ripemd160 = "0.7"
2022
sha-1 = "0.7"
2123
sha2 = "0.7"
2224

23-
[dependencies.asn1]
24-
git = "https://github.com/csssuf/rust-asn1"
25-
branch = "null"
26-
2725
[dependencies.nom]
2826
version = "^3.2"
2927
features = ["verbose-errors"]

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
//! [`Packet::to_bytes`]: enum.Packet.html#method.to_bytes
1818
//! [`Packet::from_bytes`]: enum.Packet.html#method.from_bytes
1919
//! [`SignaturePacket`]: struct.SignaturePacket.html
20-
extern crate asn1;
20+
#[macro_use]
21+
extern crate simple_asn1;
2122
extern crate byteorder;
2223
extern crate digest;
2324
#[macro_use]
@@ -28,6 +29,7 @@ extern crate gcrypt;
2829
extern crate md5;
2930
#[macro_use]
3031
extern crate nom;
32+
extern crate num;
3133
extern crate ripemd160;
3234
extern crate sha1;
3335
extern crate sha2;

src/types.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use asn1::ObjectIdentifier;
1+
use simple_asn1::OID;
22
use digest::Digest;
33
use failure::Error;
4+
use num::BigUint;
45

56
/// Type for public key algorithms supported by OpenPGP.
67
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -101,20 +102,19 @@ macro_rules! hash {
101102
}
102103

103104
impl HashAlgorithm {
104-
pub fn asn1_oid(&self) -> Result<ObjectIdentifier, Error> {
105-
let oid_vec = match *self {
106-
HashAlgorithm::Md5 => vec![1, 2, 840, 113549, 2, 5],
107-
HashAlgorithm::Sha1 => vec![1, 3, 14, 3, 2, 26],
108-
HashAlgorithm::Ripemd160 => vec![1, 3, 36, 3, 2, 1],
109-
HashAlgorithm::Sha256 => vec![2, 16, 840, 1, 101, 3, 4, 2, 1],
110-
HashAlgorithm::Sha384 => vec![2, 16, 840, 1, 101, 3, 4, 2, 2],
111-
HashAlgorithm::Sha512 => vec![2, 16, 840, 1, 101, 3, 4, 2, 3],
112-
HashAlgorithm::Sha224 => vec![2, 16, 840, 1, 101, 3, 4, 2, 4],
105+
pub fn asn1_oid(&self) -> Result<OID, Error> {
106+
let oid = match *self {
107+
HashAlgorithm::Md5 => oid![1, 2, 840, 113549, 2, 5],
108+
HashAlgorithm::Sha1 => oid![1, 3, 14, 3, 2, 26],
109+
HashAlgorithm::Ripemd160 => oid![1, 3, 36, 3, 2, 1],
110+
HashAlgorithm::Sha256 => oid![2, 16, 840, 1, 101, 3, 4, 2, 1],
111+
HashAlgorithm::Sha384 => oid![2, 16, 840, 1, 101, 3, 4, 2, 2],
112+
HashAlgorithm::Sha512 => oid![2, 16, 840, 1, 101, 3, 4, 2, 3],
113+
HashAlgorithm::Sha224 => oid![2, 16, 840, 1, 101, 3, 4, 2, 4],
113114
HashAlgorithm::Unknown => bail!(AlgorithmError::HashAlgorithmError),
114115
};
115116

116-
ObjectIdentifier::new(oid_vec)
117-
.ok_or(AlgorithmError::HashAlgorithmError.into())
117+
Ok(oid)
118118
}
119119

120120
pub fn hash<T: AsRef<[u8]>>(&self, contents: T) -> Result<Vec<u8>, Error> {

0 commit comments

Comments
 (0)