Skip to content

Commit a0efe13

Browse files
committed
Apply review feedback
1 parent 576f26c commit a0efe13

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

packages/crypto/tests/wycheproof_secp256r1.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ mod hashers {
6060

6161
// ecdsa_secp256r1_sha512 requires truncating to 32 bytes
6262
pub fn sha512(data: &[u8]) -> [u8; 32] {
63-
let mut out = [0u8; 32];
6463
let hash = Sha512::digest(data).to_vec();
65-
out.copy_from_slice(&hash[0..32]);
66-
out
64+
hash[..32].try_into().unwrap()
6765
}
6866

6967
pub fn sha3_256(data: &[u8]) -> [u8; 32] {
@@ -72,10 +70,8 @@ mod hashers {
7270

7371
// ecdsa_secp256r1_sha3_512 requires truncating to 32 bytes
7472
pub fn sha3_512(data: &[u8]) -> [u8; 32] {
75-
let mut out = [0u8; 32];
7673
let hash = Sha3_512::digest(data).to_vec();
77-
out.copy_from_slice(&hash[0..32]);
78-
out
74+
hash[..32].try_into().unwrap()
7975
}
8076
}
8177

@@ -86,7 +82,7 @@ fn ecdsa_secp256r1_sha256() {
8682
number_of_tests,
8783
test_groups,
8884
} = read_file(SECP256R1_SHA256);
89-
assert_eq!(number_of_tests, 471, "Got unexpected number of tests");
85+
assert!(number_of_tests >= 471, "Got unexpected number of tests");
9086

9187
for group in test_groups {
9288
let public_key = hex::decode(group.public_key.uncompressed).unwrap();
@@ -95,7 +91,6 @@ fn ecdsa_secp256r1_sha256() {
9591
for tc in group.tests {
9692
tested += 1;
9793
assert_eq!(tc.tc_id as usize, tested);
98-
// eprintln!("Test case ID: {}", tc.tc_id);
9994

10095
match tc.result.as_str() {
10196
"valid" | "acceptable" => {
@@ -135,7 +130,7 @@ fn ecdsa_secp256r1_sha512() {
135130
number_of_tests,
136131
test_groups,
137132
} = read_file(SECP256R1_SHA512);
138-
assert_eq!(number_of_tests, 541, "Got unexpected number of tests");
133+
assert!(number_of_tests >= 541, "Got unexpected number of tests");
139134

140135
for group in test_groups {
141136
let public_key = hex::decode(group.public_key.uncompressed).unwrap();
@@ -144,7 +139,6 @@ fn ecdsa_secp256r1_sha512() {
144139
for tc in group.tests {
145140
tested += 1;
146141
assert_eq!(tc.tc_id as usize, tested);
147-
// eprintln!("Test case ID: {}", tc.tc_id);
148142

149143
match tc.result.as_str() {
150144
"valid" | "acceptable" => {
@@ -184,7 +178,7 @@ fn ecdsa_secp256r1_sha3_256() {
184178
number_of_tests,
185179
test_groups,
186180
} = read_file(SECP256R1_SHA3_256);
187-
assert_eq!(number_of_tests, 479, "Got unexpected number of tests");
181+
assert!(number_of_tests >= 479, "Got unexpected number of tests");
188182

189183
for group in test_groups {
190184
let public_key = hex::decode(group.public_key.uncompressed).unwrap();
@@ -193,7 +187,6 @@ fn ecdsa_secp256r1_sha3_256() {
193187
for tc in group.tests {
194188
tested += 1;
195189
assert_eq!(tc.tc_id as usize, tested);
196-
// eprintln!("Test case ID: {}", tc.tc_id);
197190

198191
match tc.result.as_str() {
199192
"valid" | "acceptable" => {
@@ -233,7 +226,7 @@ fn ecdsa_secp256r1_sha3_512() {
233226
number_of_tests,
234227
test_groups,
235228
} = read_file(SECP256R1_SHA3_512);
236-
assert_eq!(number_of_tests, 545, "Got unexpected number of tests");
229+
assert!(number_of_tests >= 545, "Got unexpected number of tests");
237230

238231
for group in test_groups {
239232
let public_key = hex::decode(group.public_key.uncompressed).unwrap();
@@ -242,7 +235,6 @@ fn ecdsa_secp256r1_sha3_512() {
242235
for tc in group.tests {
243236
tested += 1;
244237
assert_eq!(tc.tc_id as usize, tested);
245-
// eprintln!("Test case ID: {}", tc.tc_id);
246238

247239
match tc.result.as_str() {
248240
"valid" | "acceptable" => {

0 commit comments

Comments
 (0)