@@ -3,14 +3,27 @@ use std::fmt::{self, Debug, Display};
33#[ cfg( feature = "aws-lc-rs" ) ]
44use aws_lc_rs:: signature:: { Ed25519KeyPair , KeyPair as _, Signature as LlSignature } ;
55use data_encoding:: { BASE32_NOPAD , BASE64URL_NOPAD } ;
6+ #[ cfg( all(
7+ not( feature = "aws-lc-rs" ) ,
8+ not( feature = "ring" ) ,
9+ feature = "graviola"
10+ ) ) ]
11+ use graviola:: signing:: eddsa:: Ed25519SigningKey as Ed25519KeyPair ;
612#[ cfg( all( not( feature = "aws-lc-rs" ) , feature = "ring" ) ) ]
713use ring:: signature:: { Ed25519KeyPair , KeyPair as _, Signature as LlSignature } ;
814
9- #[ cfg( not( any( feature = "aws-lc-rs" , feature = "ring" ) ) ) ]
10- compile_error ! ( "Please enable the `aws-lc-rs` or the `ring` feature" ) ;
15+ #[ cfg( not( any( feature = "aws-lc-rs" , feature = "ring" , feature = "graviola" ) ) ) ]
16+ compile_error ! ( "Please enable the `aws-lc-rs`, the `ring` or the `graviola` feature feature" ) ;
1117
1218use crate :: crc:: Crc16 ;
1319
20+ #[ cfg( all(
21+ not( feature = "aws-lc-rs" ) ,
22+ not( feature = "ring" ) ,
23+ feature = "graviola"
24+ ) ) ]
25+ type LlSignature = [ u8 ; 64 ] ;
26+
1427const SEED_PREFIX_BYTE : u8 = 18 << 3 ;
1528
1629/// A `NKey` private/public key pair.
@@ -91,8 +104,11 @@ impl KeyPair {
91104
92105 let kind = raw_seed[ 1 ] ;
93106
107+ #[ cfg( any( feature = "aws-lc-rs" , feature = "ring" ) ) ]
94108 let key = Ed25519KeyPair :: from_seed_unchecked ( & raw_seed[ 2 ..] )
95109 . map_err ( |_| KeyPairFromSeedError :: DecodeError ) ?;
110+ #[ cfg( not( any( feature = "aws-lc-rs" , feature = "ring" ) ) ) ]
111+ let key = Ed25519KeyPair :: from_bytes ( raw_seed[ 2 ..] . try_into ( ) . unwrap ( ) ) . unwrap ( ) ;
96112 Ok ( Self { kind, key } )
97113 }
98114
@@ -126,7 +142,11 @@ impl Display for PublicKey<'_> {
126142 let mut full_raw_seed = [ 0 ; 36 ] ;
127143 full_raw_seed[ 0 ] = SEED_PREFIX_BYTE ;
128144 full_raw_seed[ 1 ] = self . 0 . kind ;
129- full_raw_seed[ 2 ..34 ] . copy_from_slice ( self . 0 . key . public_key ( ) . as_ref ( ) ) ;
145+ #[ cfg( any( feature = "aws-lc-rs" , feature = "ring" ) ) ]
146+ let public_key_bytes = self . 0 . key . public_key ( ) . as_ref ( ) ;
147+ #[ cfg( not( any( feature = "aws-lc-rs" , feature = "ring" ) ) ) ]
148+ let public_key_bytes = & self . 0 . key . public_key ( ) . as_bytes ( ) ;
149+ full_raw_seed[ 2 ..34 ] . copy_from_slice ( public_key_bytes) ;
130150 let crc = Crc16 :: compute ( & full_raw_seed[ ..34 ] ) ;
131151 full_raw_seed[ 34 ..36 ] . copy_from_slice ( & crc. to_raw_encoded ( ) ) ;
132152 Display :: fmt ( & BASE32_NOPAD . encode_display ( & full_raw_seed) , f)
0 commit comments