|
1 | | -use asn1::ObjectIdentifier; |
| 1 | +use simple_asn1::OID; |
2 | 2 | use digest::Digest; |
3 | 3 | use failure::Error; |
| 4 | +use num::BigUint; |
4 | 5 |
|
5 | 6 | /// Type for public key algorithms supported by OpenPGP. |
6 | 7 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
@@ -101,20 +102,19 @@ macro_rules! hash { |
101 | 102 | } |
102 | 103 |
|
103 | 104 | 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], |
113 | 114 | HashAlgorithm::Unknown => bail!(AlgorithmError::HashAlgorithmError), |
114 | 115 | }; |
115 | 116 |
|
116 | | - ObjectIdentifier::new(oid_vec) |
117 | | - .ok_or(AlgorithmError::HashAlgorithmError.into()) |
| 117 | + Ok(oid) |
118 | 118 | } |
119 | 119 |
|
120 | 120 | pub fn hash<T: AsRef<[u8]>>(&self, contents: T) -> Result<Vec<u8>, Error> { |
|
0 commit comments