11//! Encrypted SSH private key tests.
22
33#![ cfg( feature = "alloc" ) ]
4- // TODO(tarcieri): fix `getrandom` feature
5- #![ allow( unexpected_cfgs) ]
64
75use hex_literal:: hex;
86use ssh_key:: { Algorithm , Cipher , Kdf , KdfAlg , PrivateKey } ;
@@ -297,11 +295,12 @@ fn encode_openssh_aes256_gcm() {
297295#[ cfg( all( feature = "encryption" , feature = "getrandom" ) ) ]
298296#[ test]
299297fn encrypt_openssh_aes128_cbc ( ) {
300- use rand_core :: { OsRng , TryRngCore } ;
298+ use getrandom :: { SysRng , rand_core :: UnwrapErr } ;
301299
300+ let mut rng = UnwrapErr ( SysRng ) ;
302301 let key_dec = PrivateKey :: from_openssh ( OPENSSH_ED25519_EXAMPLE ) . unwrap ( ) ;
303302 let key_enc = key_dec
304- . encrypt_with_cipher ( & mut OsRng . unwrap_err ( ) , Cipher :: Aes128Cbc , PASSWORD )
303+ . encrypt_with_cipher ( & mut rng , Cipher :: Aes128Cbc , PASSWORD )
305304 . unwrap ( ) ;
306305
307306 // Ensure encrypted key round trips through encoder/decoder
@@ -317,11 +316,11 @@ fn encrypt_openssh_aes128_cbc() {
317316#[ cfg( all( feature = "encryption" , feature = "getrandom" ) ) ]
318317#[ test]
319318fn encrypt_openssh_aes192_cbc ( ) {
320- use rand_core :: OsRng ;
319+ use getrandom :: SysRng ;
321320
322321 let key_dec = PrivateKey :: from_openssh ( OPENSSH_ED25519_EXAMPLE ) . unwrap ( ) ;
323322 let key_enc = key_dec
324- . encrypt_with_cipher ( & mut OsRng , Cipher :: Aes192Cbc , PASSWORD )
323+ . encrypt_with_cipher ( & mut SysRng , Cipher :: Aes192Cbc , PASSWORD )
325324 . unwrap ( ) ;
326325
327326 // Ensure encrypted key round trips through encoder/decoder
@@ -337,11 +336,11 @@ fn encrypt_openssh_aes192_cbc() {
337336#[ cfg( all( feature = "encryption" , feature = "getrandom" ) ) ]
338337#[ test]
339338fn encrypt_openssh_aes256_cbc ( ) {
340- use rand_core :: OsRng ;
339+ use getrandom :: SysRng ;
341340
342341 let key_dec = PrivateKey :: from_openssh ( OPENSSH_ED25519_EXAMPLE ) . unwrap ( ) ;
343342 let key_enc = key_dec
344- . encrypt_with_cipher ( & mut OsRng , Cipher :: Aes256Cbc , PASSWORD )
343+ . encrypt_with_cipher ( & mut SysRng , Cipher :: Aes256Cbc , PASSWORD )
345344 . unwrap ( ) ;
346345
347346 // Ensure encrypted key round trips through encoder/decoder
@@ -357,11 +356,11 @@ fn encrypt_openssh_aes256_cbc() {
357356#[ cfg( all( feature = "encryption" , feature = "getrandom" ) ) ]
358357#[ test]
359358fn encrypt_openssh_aes128_ctr ( ) {
360- use rand_core :: OsRng ;
359+ use getrandom :: SysRng ;
361360
362361 let key_dec = PrivateKey :: from_openssh ( OPENSSH_ED25519_EXAMPLE ) . unwrap ( ) ;
363362 let key_enc = key_dec
364- . encrypt_with_cipher ( & mut OsRng , Cipher :: Aes128Ctr , PASSWORD )
363+ . encrypt_with_cipher ( & mut SysRng , Cipher :: Aes128Ctr , PASSWORD )
365364 . unwrap ( ) ;
366365
367366 // Ensure encrypted key round trips through encoder/decoder
@@ -377,11 +376,11 @@ fn encrypt_openssh_aes128_ctr() {
377376#[ cfg( all( feature = "encryption" , feature = "getrandom" ) ) ]
378377#[ test]
379378fn encrypt_openssh_aes192_ctr ( ) {
380- use rand_core :: OsRng ;
379+ use getrandom :: SysRng ;
381380
382381 let key_dec = PrivateKey :: from_openssh ( OPENSSH_ED25519_EXAMPLE ) . unwrap ( ) ;
383382 let key_enc = key_dec
384- . encrypt_with_cipher ( & mut OsRng , Cipher :: Aes192Ctr , PASSWORD )
383+ . encrypt_with_cipher ( & mut SysRng , Cipher :: Aes192Ctr , PASSWORD )
385384 . unwrap ( ) ;
386385
387386 // Ensure encrypted key round trips through encoder/decoder
@@ -397,10 +396,10 @@ fn encrypt_openssh_aes192_ctr() {
397396#[ cfg( all( feature = "encryption" , feature = "getrandom" ) ) ]
398397#[ test]
399398fn encrypt_openssh_aes256_ctr ( ) {
400- use rand_core :: OsRng ;
399+ use getrandom :: SysRng ;
401400
402401 let key_dec = PrivateKey :: from_openssh ( OPENSSH_ED25519_EXAMPLE ) . unwrap ( ) ;
403- let key_enc = key_dec. encrypt ( & mut OsRng , PASSWORD ) . unwrap ( ) ;
402+ let key_enc = key_dec. encrypt ( & mut SysRng , PASSWORD ) . unwrap ( ) ;
404403
405404 // Ensure encrypted key round trips through encoder/decoder
406405 let key_enc_str = key_enc. to_openssh ( Default :: default ( ) ) . unwrap ( ) ;
@@ -415,12 +414,12 @@ fn encrypt_openssh_aes256_ctr() {
415414#[ cfg( all( feature = "encryption" , feature = "getrandom" ) ) ]
416415#[ test]
417416fn encrypt_openssh_aes128_gcm ( ) {
418- use rand_core :: OsRng ;
417+ use getrandom :: SysRng ;
419418
420419 let key_dec = PrivateKey :: from_openssh ( OPENSSH_ED25519_EXAMPLE ) . unwrap ( ) ;
421420
422421 let key_enc = key_dec
423- . encrypt_with_cipher ( & mut OsRng , Cipher :: Aes128Gcm , PASSWORD )
422+ . encrypt_with_cipher ( & mut SysRng , Cipher :: Aes128Gcm , PASSWORD )
424423 . unwrap ( ) ;
425424
426425 // Ensure encrypted key round trips through encoder/decoder
@@ -436,12 +435,12 @@ fn encrypt_openssh_aes128_gcm() {
436435#[ cfg( all( feature = "encryption" , feature = "getrandom" ) ) ]
437436#[ test]
438437fn encrypt_openssh_aes256_gcm ( ) {
439- use rand_core :: OsRng ;
438+ use getrandom :: SysRng ;
440439
441440 let key_dec = PrivateKey :: from_openssh ( OPENSSH_ED25519_EXAMPLE ) . unwrap ( ) ;
442441
443442 let key_enc = key_dec
444- . encrypt_with_cipher ( & mut OsRng , Cipher :: Aes256Gcm , PASSWORD )
443+ . encrypt_with_cipher ( & mut SysRng , Cipher :: Aes256Gcm , PASSWORD )
445444 . unwrap ( ) ;
446445
447446 // Ensure encrypted key round trips through encoder/decoder
@@ -457,12 +456,12 @@ fn encrypt_openssh_aes256_gcm() {
457456#[ cfg( all( feature = "encryption" , feature = "getrandom" ) ) ]
458457#[ test]
459458fn encrypt_openssh_chacha20_poly1305 ( ) {
460- use rand_core :: OsRng ;
459+ use getrandom :: SysRng ;
461460
462461 let key_dec = PrivateKey :: from_openssh ( OPENSSH_ED25519_EXAMPLE ) . unwrap ( ) ;
463462
464463 let key_enc = key_dec
465- . encrypt_with_cipher ( & mut OsRng , Cipher :: ChaCha20Poly1305 , PASSWORD )
464+ . encrypt_with_cipher ( & mut SysRng , Cipher :: ChaCha20Poly1305 , PASSWORD )
466465 . unwrap ( ) ;
467466
468467 // Ensure encrypted key round trips through encoder/decoder
@@ -478,12 +477,12 @@ fn encrypt_openssh_chacha20_poly1305() {
478477#[ cfg( all( feature = "tdes" , feature = "getrandom" ) ) ]
479478#[ test]
480479fn encrypt_openssh_3des ( ) {
481- use rand_core :: OsRng ;
480+ use getrandom :: SysRng ;
482481
483482 let key_dec = PrivateKey :: from_openssh ( OPENSSH_ED25519_EXAMPLE ) . unwrap ( ) ;
484483
485484 let key_enc = key_dec
486- . encrypt_with_cipher ( & mut OsRng , Cipher :: TdesCbc , PASSWORD )
485+ . encrypt_with_cipher ( & mut SysRng , Cipher :: TdesCbc , PASSWORD )
487486 . unwrap ( ) ;
488487
489488 // Ensure encrypted key round trips through encoder/decoder
0 commit comments