@@ -17,33 +17,34 @@ use kahe_traits::{HasKahe, KaheBase, KaheEncrypt, KaheKeygen, TrySecretKeyInto};
1717use messages:: { ClientMessage , DecryptorPublicKey } ;
1818use prng_traits:: SecurePrng ;
1919use std:: cell:: RefCell ;
20+ use std:: rc:: Rc ;
2021use vahe_traits:: { HasVahe , VaheBase , VerifiableEncrypt } ;
2122
2223/// Lightweight client directly exposing KAHE/VAHE types.
2324pub struct WillowV1Client < Kahe : KaheBase , Vahe : VaheBase > {
24- pub kahe : Kahe ,
25- pub vahe : Vahe ,
25+ pub kahe : Rc < Kahe > ,
26+ pub vahe : Rc < Vahe > ,
2627 pub prng : RefCell < Kahe :: Rng > , // Using a single PRNG for both VAHE and KAHE.
2728}
2829
2930impl < Kahe : KaheBase , Vahe : VaheBase > HasKahe for WillowV1Client < Kahe , Vahe > {
3031 type Kahe = Kahe ;
3132 fn kahe ( & self ) -> & Self :: Kahe {
32- & self . kahe
33+ self . kahe . as_ref ( )
3334 }
3435}
3536
3637impl < Kahe : KaheBase , Vahe : VaheBase > HasVahe for WillowV1Client < Kahe , Vahe > {
3738 type Vahe = Vahe ;
3839 fn vahe ( & self ) -> & Self :: Vahe {
39- & self . vahe
40+ self . vahe . as_ref ( )
4041 }
4142}
4243
4344impl < Kahe : KaheBase , Vahe : VaheBase > WillowV1Client < Kahe , Vahe > {
4445 pub fn new_with_randomly_generated_seed (
45- kahe : Kahe ,
46- vahe : Vahe ,
46+ kahe : Rc < Kahe > ,
47+ vahe : Rc < Vahe > ,
4748 ) -> Result < Self , status:: StatusError > {
4849 let seed = Kahe :: Rng :: generate_seed ( ) ?;
4950 let prng = RefCell :: new ( Kahe :: Rng :: create ( & seed) ?) ;
@@ -122,8 +123,8 @@ mod test {
122123
123124 // Create a client.
124125 let ( kahe_config, ahe_config) = create_shell_configs ( & aggregation_config) ?;
125- let kahe = ShellKahe :: new ( kahe_config, CONTEXT_STRING ) ?;
126- let vahe = ShellVahe :: new ( ahe_config, CONTEXT_STRING ) ?;
126+ let kahe = Rc :: new ( ShellKahe :: new ( kahe_config, CONTEXT_STRING ) ?) ;
127+ let vahe = Rc :: new ( ShellVahe :: new ( ahe_config, CONTEXT_STRING ) ?) ;
127128 let client = WillowV1Client :: new_with_randomly_generated_seed ( kahe, vahe) ?;
128129
129130 // Generate AHE keys.
@@ -159,16 +160,14 @@ mod test {
159160 key_id : b"test" . to_vec ( ) ,
160161 } ;
161162
162- // Create a client .
163+ // Create common KAHE/VAHE instances .
163164 let ( kahe_config, ahe_config) = create_shell_configs ( & aggregation_config) ?;
164- let kahe = ShellKahe :: new ( kahe_config, CONTEXT_STRING ) ?;
165- let vahe = ShellVahe :: new ( ahe_config, CONTEXT_STRING ) ?;
166- let client1 = WillowV1Client :: new_with_randomly_generated_seed ( kahe, vahe) ?;
165+ let kahe = Rc :: new ( ShellKahe :: new ( kahe_config, CONTEXT_STRING ) ?) ;
166+ let vahe = Rc :: new ( ShellVahe :: new ( ahe_config, CONTEXT_STRING ) ?) ;
167167
168- // Create a second client.
169- let ( kahe_config, ahe_config) = create_shell_configs ( & aggregation_config) ?;
170- let kahe = ShellKahe :: new ( kahe_config, CONTEXT_STRING ) ?;
171- let vahe = ShellVahe :: new ( ahe_config, CONTEXT_STRING ) ?;
168+ // Create clients.
169+ let client1 =
170+ WillowV1Client :: new_with_randomly_generated_seed ( Rc :: clone ( & kahe) , Rc :: clone ( & vahe) ) ?;
172171 let client2 = WillowV1Client :: new_with_randomly_generated_seed ( kahe, vahe) ?;
173172
174173 // Generate AHE keys.
0 commit comments