1 #![cfg_attr(fuzzing, no_main)]
2 // Copyright 2023 Google LLC
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 use crypto_provider::{
17     elliptic_curve::EcdhProvider,
18     p256::{P256PublicKey, P256},
19     CryptoProvider,
20 };
21 use crypto_provider_default::CryptoProviderImpl;
22 use derive_fuzztest::fuzztest;
23 
24 type P256PublicKeyAlias<P> = <<P as CryptoProvider>::P256 as EcdhProvider<P256>>::PublicKey;
25 
26 #[fuzztest]
test(input: Vec<u8>)27 fn test(input: Vec<u8>) {
28     let pubkey = P256PublicKeyAlias::<CryptoProviderImpl>::from_sec1_bytes(&input);
29     if let Ok(key) = pubkey {
30         let (x, y) = key
31             .to_affine_coordinates()
32             .expect("Valid keys should always be able to output affine coordinates");
33         let recreated_pubkey =
34             P256PublicKeyAlias::<CryptoProviderImpl>::from_affine_coordinates(&x, &y)
35                 .expect("Creating public key from affine coordinates should succeed");
36         assert_eq!(key, recreated_pubkey);
37     }
38 }
39