@@ -362,59 +362,50 @@ mod tests {
362
362
let peer_public =
363
363
agreement:: UnparsedPublicKey :: new ( alg, test_case. consume_bytes ( "PeerQ" ) ) ;
364
364
365
- match test_case. consume_optional_string ( "Error" ) {
366
- None => {
367
- let my_private_bytes = test_case. consume_bytes ( "D" ) ;
368
- let my_private = {
369
- let rng = test:: rand:: FixedSliceRandom {
370
- bytes : & my_private_bytes,
371
- } ;
372
- agreement:: EphemeralPrivateKey :: generate_for_test ( alg, & rng) ?
365
+ if test_case. consume_optional_string ( "Error" ) . is_none ( ) {
366
+ let my_private_bytes = test_case. consume_bytes ( "D" ) ;
367
+ let my_private = {
368
+ let rng = test:: rand:: FixedSliceRandom {
369
+ bytes : & my_private_bytes,
373
370
} ;
374
- let my_public = test_case. consume_bytes ( "MyQ" ) ;
375
- let output = test_case. consume_bytes ( "Output" ) ;
376
-
377
- assert_eq ! ( my_private. algorithm( ) , alg) ;
378
-
379
- let computed_public = my_private. compute_public_key ( ) . unwrap ( ) ;
380
- assert_eq ! ( computed_public. as_ref( ) , & my_public[ ..] ) ;
381
-
382
- assert_eq ! ( my_private. algorithm( ) , alg) ;
383
-
384
- let result = agreement:: agree_ephemeral (
385
- my_private,
386
- & peer_public,
387
- ( ) ,
388
- |key_material| {
389
- assert_eq ! ( key_material, & output[ ..] ) ;
390
- Ok ( ( ) )
391
- } ,
392
- ) ;
393
- assert_eq ! (
394
- result,
395
- Ok ( ( ) ) ,
396
- "Failed on private key: {:?}" ,
397
- test:: to_hex( my_private_bytes)
398
- ) ;
399
- }
400
-
401
- Some ( _) => {
402
- fn kdf_not_called ( _: & [ u8 ] ) -> Result < ( ) , ( ) > {
403
- panic ! (
404
- "The KDF was called during ECDH when the peer's \
371
+ agreement:: EphemeralPrivateKey :: generate_for_test ( alg, & rng) ?
372
+ } ;
373
+ let my_public = test_case. consume_bytes ( "MyQ" ) ;
374
+ let output = test_case. consume_bytes ( "Output" ) ;
375
+
376
+ assert_eq ! ( my_private. algorithm( ) , alg) ;
377
+
378
+ let computed_public = my_private. compute_public_key ( ) . unwrap ( ) ;
379
+ assert_eq ! ( computed_public. as_ref( ) , & my_public[ ..] ) ;
380
+
381
+ assert_eq ! ( my_private. algorithm( ) , alg) ;
382
+
383
+ let result =
384
+ agreement:: agree_ephemeral ( my_private, & peer_public, ( ) , |key_material| {
385
+ assert_eq ! ( key_material, & output[ ..] ) ;
386
+ Ok ( ( ) )
387
+ } ) ;
388
+ assert_eq ! (
389
+ result,
390
+ Ok ( ( ) ) ,
391
+ "Failed on private key: {:?}" ,
392
+ test:: to_hex( my_private_bytes)
393
+ ) ;
394
+ } else {
395
+ fn kdf_not_called ( _: & [ u8 ] ) -> Result < ( ) , ( ) > {
396
+ panic ! (
397
+ "The KDF was called during ECDH when the peer's \
405
398
public key is invalid."
406
- ) ;
407
- }
408
- let dummy_private_key =
409
- agreement:: EphemeralPrivateKey :: generate ( alg, & rng) ?;
410
- assert ! ( agreement:: agree_ephemeral(
411
- dummy_private_key,
412
- & peer_public,
413
- ( ) ,
414
- kdf_not_called
415
- )
416
- . is_err( ) ) ;
399
+ ) ;
417
400
}
401
+ let dummy_private_key = agreement:: EphemeralPrivateKey :: generate ( alg, & rng) ?;
402
+ assert ! ( agreement:: agree_ephemeral(
403
+ dummy_private_key,
404
+ & peer_public,
405
+ ( ) ,
406
+ kdf_not_called
407
+ )
408
+ . is_err( ) ) ;
418
409
}
419
410
420
411
Ok ( ( ) )
0 commit comments