@@ -8,8 +8,8 @@ use std::io::Write;
8
8
use std:: { cmp, convert:: TryInto , fmt} ;
9
9
10
10
use crypto_box:: {
11
- aead:: { generic_array:: GenericArray , Aead , NewAead } ,
12
- rand_core :: OsRng ,
11
+ aead:: { generic_array:: GenericArray , Aead , KeyInit , OsRng } ,
12
+ SalsaBox ,
13
13
} ;
14
14
use data_encoding:: { HEXLOWER , HEXLOWER_PERMISSIVE } ;
15
15
use serde:: {
@@ -141,7 +141,7 @@ impl KeyPair {
141
141
/// Warning: Be careful with this! The only reason to access the private
142
142
/// key is probably to be able to restore it when working with trusted keys.
143
143
pub fn private_key_hex ( & self ) -> String {
144
- HEXLOWER . encode ( self . private_key . as_bytes ( ) )
144
+ HEXLOWER . encode ( & self . private_key . to_bytes ( ) )
145
145
}
146
146
147
147
/// Encrypt data for the specified public key with the private key.
@@ -151,7 +151,7 @@ impl KeyPair {
151
151
nonce : Nonce ,
152
152
other_key : & PublicKey ,
153
153
) -> SignalingResult < Vec < u8 > > {
154
- let cbox = crypto_box :: Box :: new ( other_key, & self . private_key ) ;
154
+ let cbox = SalsaBox :: new ( other_key, & self . private_key ) ;
155
155
cbox. encrypt ( & nonce. into ( ) , data)
156
156
. map_err ( |_| SignalingError :: Crypto ( "Could not encrypt data" . to_string ( ) ) )
157
157
}
@@ -167,7 +167,7 @@ impl KeyPair {
167
167
nonce : Nonce ,
168
168
other_key : & PublicKey ,
169
169
) -> SignalingResult < Vec < u8 > > {
170
- let cbox = crypto_box :: Box :: new ( other_key, & self . private_key ) ;
170
+ let cbox = SalsaBox :: new ( other_key, & self . private_key ) ;
171
171
cbox. decrypt ( & nonce. into ( ) , data)
172
172
. map_err ( |_| SignalingError :: Crypto ( "Could not decrypt data" . to_string ( ) ) )
173
173
}
@@ -287,7 +287,7 @@ impl UnsignedKeys {
287
287
( & mut bytes[ 32 ..64 ] )
288
288
. write_all ( self . client_public_permanent_key . as_bytes ( ) )
289
289
. unwrap ( ) ;
290
- let cbox = crypto_box :: Box :: new (
290
+ let cbox = SalsaBox :: new (
291
291
client_public_permanent_key,
292
292
server_session_keypair. private_key ( ) ,
293
293
) ;
@@ -315,7 +315,7 @@ impl SignedKeys {
315
315
nonce : Nonce ,
316
316
) -> SignalingResult < UnsignedKeys > {
317
317
// Decrypt bytes
318
- let cbox = crypto_box :: Box :: new ( server_public_permanent_key, permanent_key. private_key ( ) ) ;
318
+ let cbox = SalsaBox :: new ( server_public_permanent_key, permanent_key. private_key ( ) ) ;
319
319
let decrypted = cbox
320
320
. decrypt ( & nonce. into ( ) , & self . 0 [ ..] )
321
321
. map_err ( |_| SignalingError :: Crypto ( "Could not decrypt signed keys" . to_string ( ) ) ) ?;
@@ -413,7 +413,7 @@ use crate::test_helpers::TestRandom;
413
413
#[ cfg( test) ]
414
414
impl TestRandom for PublicKey {
415
415
fn random ( ) -> PublicKey {
416
- let mut rng = crypto_box:: rand_core :: OsRng ;
416
+ let mut rng = crypto_box:: aead :: OsRng ;
417
417
let private_key = PrivateKey :: generate ( & mut rng) ;
418
418
private_key. public_key ( )
419
419
}
@@ -431,7 +431,7 @@ mod tests {
431
431
let ks1 = KeyPair :: new ( ) ;
432
432
let ks2 = KeyPair :: new ( ) ;
433
433
assert_ne ! ( ks1. public_key( ) , ks2. public_key( ) ) ;
434
- assert_ne ! ( ks1. private_key( ) . as_bytes ( ) , ks2. private_key( ) . as_bytes ( ) ) ;
434
+ assert_ne ! ( ks1. private_key( ) . to_bytes ( ) , ks2. private_key( ) . to_bytes ( ) ) ;
435
435
}
436
436
}
437
437
@@ -633,7 +633,7 @@ mod tests {
633
633
. sign ( & kp_server, kp_client. public_key ( ) , unsafe { nonce. clone ( ) } ) ;
634
634
635
635
// Decrypt directly
636
- let cbox = crypto_box :: Box :: new ( kp_server. public_key ( ) , kp_client. private_key ( ) ) ;
636
+ let cbox = SalsaBox :: new ( kp_server. public_key ( ) , kp_client. private_key ( ) ) ;
637
637
let decrypted = cbox
638
638
. decrypt ( & unsafe { nonce. clone ( ) } . into ( ) , & signed. 0 [ ..] )
639
639
. unwrap ( ) ;
0 commit comments