Skip to content

Commit 3c5c1e4

Browse files
author
Adrian Cruceru
committed
Add ECDSA Sig type
1 parent a0896b2 commit 3c5c1e4

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/oid.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ lazy_static! {
1414
// PKCS #1
1515
pub static ref rsaEncryption: ObjectIdentifier = vec![1, 2, 840, 113549, 1, 1, 1].into();
1616
pub static ref sha256WithRSAEncryption: ObjectIdentifier = vec![1, 2, 840, 113549, 1, 1, 11].into();
17+
pub static ref sha256WithECDSAEncryption: ObjectIdentifier = vec![1, 2, 840, 10045, 4, 3, 2].into();
1718

1819
// X.500 attribute types
1920
pub static ref commonName: ObjectIdentifier = vec![2, 5, 4, 3].into();

src/types.rs

+29
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,35 @@ impl BERDecodable for RsaPkcs15<Sha256> {
5454
}
5555
}
5656

57+
pub struct EcdsaPkcs15<H>(pub H);
58+
59+
impl<H> SignatureAlgorithm for EcdsaPkcs15<H> {}
60+
61+
/// sha256WithECDSAEncryption
62+
impl DerWrite for EcdsaPkcs15<Sha256> {
63+
fn write(&self, writer: DERWriter) {
64+
writer.write_sequence(|writer| {
65+
writer.next().write_oid(&oid::sha256WithECDSAEncryption);
66+
writer.next().write_null();
67+
})
68+
}
69+
}
70+
71+
impl BERDecodable for EcdsaPkcs15<Sha256> {
72+
fn decode_ber<'a, 'b>(reader: BERReader<'a, 'b>) -> ASN1Result<Self> {
73+
reader.read_sequence(|seq_reader| {
74+
let oid = ObjectIdentifier::decode_ber(seq_reader.next())?;
75+
seq_reader.next().read_null()?;
76+
if oid == *oid::sha256WithECDSAEncryption {
77+
Ok(EcdsaPkcs15(Sha256))
78+
} else {
79+
Err(ASN1Error::new(ASN1ErrorKind::Invalid))
80+
}
81+
})
82+
}
83+
}
84+
85+
5786
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
5887
pub struct Name {
5988
// The actual ASN.1 type is Vec<HashSet<(ObjectIdentifier, TaggedDerValue)>>.

0 commit comments

Comments
 (0)