Skip to content

Commit 80e96e0

Browse files
djcbriansmith
authored andcommitted
Change rsa::parse_public_key to return components as Input.
I agree to license my contributions to each file under the terms given at the top of each file I changed.
1 parent 9c85dfd commit 80e96e0

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/rsa/rsa.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,13 @@ pub struct RSAParameters {
102102
}
103103

104104
fn parse_public_key(input: untrusted::Input)
105-
-> Result<(&[u8], &[u8]), error::Unspecified> {
105+
-> Result<(untrusted::Input, untrusted::Input),
106+
error::Unspecified> {
106107
input.read_all(error::Unspecified, |input| {
107108
der::nested(input, der::Tag::Sequence, error::Unspecified, |input| {
108109
let n = try!(der::positive_integer(input));
109110
let e = try!(der::positive_integer(input));
110-
Ok((n.as_slice_less_safe(), e.as_slice_less_safe()))
111+
Ok((n, e))
111112
})
112113
})
113114
}

src/rsa/verification.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ impl signature::VerificationAlgorithm for RSAParameters {
2525
fn verify(&self, public_key: untrusted::Input, msg: untrusted::Input,
2626
signature: untrusted::Input)
2727
-> Result<(), error::Unspecified> {
28+
let public_key = try!(parse_public_key(public_key));
2829
verify_rsa(self, public_key, msg, signature)
2930
}
3031
}
@@ -61,15 +62,17 @@ rsa_pkcs1!(RSA_PKCS1_3072_8192_SHA384, 3072, &super::RSA_PKCS1_SHA384,
6162
"Verification of signatures using RSA keys of 3072-8192 bits,
6263
PKCS#1.5 padding, and SHA-384.");
6364

64-
fn verify_rsa(params: &RSAParameters, public_key: untrusted::Input,
65+
fn verify_rsa(params: &RSAParameters,
66+
(n, e): (untrusted::Input, untrusted::Input),
6567
msg: untrusted::Input, signature: untrusted::Input)
6668
-> Result<(), error::Unspecified> {
6769
const MAX_BITS: usize = 8192;
6870

69-
let (n, e) = try!(parse_public_key(public_key));
7071
let signature = signature.as_slice_less_safe();
7172

7273
let mut decoded = [0u8; (MAX_BITS + 7) / 8];
74+
let n = n.as_slice_less_safe();
75+
let e = e.as_slice_less_safe();
7376
if signature.len() > decoded.len() {
7477
return Err(error::Unspecified);
7578
}

0 commit comments

Comments
 (0)