@@ -11,14 +11,24 @@ use crate::toxcore::binary_io::*;
1111
1212// TODO: check if `#[inline]` is actually useful
1313
14+ /** Run before using crypto.
1415
15- /// Initialize sodiumoxide
16- #[ deprecated(
17- since = "0.0.10" ,
18- note = "libsodium is automatically initialized by sodiumoxide now."
19- ) ]
16+ Runs [`sodiumoxide::init()`](../../../sodiumoxide/fn.init.html).
17+
18+ Returns `Ok` on success, `Err` otherwise.
19+
20+ E.g.
21+
22+ ```
23+ use ::tox::toxcore::crypto_core::crypto_init;
24+
25+ crypto_init().unwrap();
26+ // second call should yield same result
27+ crypto_init().unwrap();
28+ ```
29+ */
2030pub fn crypto_init ( ) -> Result < ( ) , ( ) > {
21- Ok ( ( ) )
31+ :: sodiumoxide :: init ( )
2232}
2333
2434
@@ -241,6 +251,7 @@ pub mod tests {
241251 // test comparing random public keys
242252 // testing since it would appear that sodiumoxide doesn't do testing for it
243253 fn public_key_cmp_test_random ( ) {
254+ crypto_init ( ) . unwrap ( ) ;
244255 let ( alice_publickey, _alice_secretkey) = gen_keypair ( ) ;
245256 let ( bob_publickey, _bob_secretkey) = gen_keypair ( ) ;
246257
@@ -254,6 +265,7 @@ pub mod tests {
254265
255266 #[ test]
256267 fn random_u32_test ( ) {
268+ crypto_init ( ) . unwrap ( ) ;
257269 let a = random_u32 ( ) ;
258270 let b = random_u32 ( ) ;
259271 assert_ne ! ( a, 0 ) ;
@@ -265,6 +277,7 @@ pub mod tests {
265277
266278 #[ test]
267279 fn random_u64_test ( ) {
280+ crypto_init ( ) . unwrap ( ) ;
268281 let a = random_u64 ( ) ;
269282 let b = random_u64 ( ) ;
270283 assert_ne ! ( a, 0 ) ;
@@ -275,6 +288,7 @@ pub mod tests {
275288
276289 #[ test]
277290 fn random_usize_test ( ) {
291+ crypto_init ( ) . unwrap ( ) ;
278292 let a = random_usize ( ) ;
279293 let b = random_usize ( ) ;
280294 assert_ne ! ( a, 0 ) ;
@@ -285,12 +299,14 @@ pub mod tests {
285299
286300 #[ test]
287301 fn random_limit_usize_test ( ) {
302+ crypto_init ( ) . unwrap ( ) ;
288303 let n = random_limit_usize ( 7 ) ;
289304 assert ! ( n < 7 ) ;
290305 }
291306
292307 #[ test]
293308 fn public_key_valid_test ( ) {
309+ crypto_init ( ) . unwrap ( ) ;
294310 let ( pk, _) = gen_keypair ( ) ;
295311 assert ! ( public_key_valid( & pk) ) ;
296312
@@ -305,6 +321,7 @@ pub mod tests {
305321 // test uses "bare" functions provided by `sodiumoxide`, with an exception
306322 // of the tested function
307323 fn encrypt_precompute_test ( ) {
324+ crypto_init ( ) . unwrap ( ) ;
308325 let ( alice_pk, alice_sk) = gen_keypair ( ) ;
309326 let ( bob_pk, bob_sk) = gen_keypair ( ) ;
310327
@@ -326,6 +343,7 @@ pub mod tests {
326343 // test uses "bare" functions provided by `sodiumoxide`, with an "exception"
327344 // of the tested function
328345 fn encrypt_data_symmetric_test ( ) {
346+ crypto_init ( ) . unwrap ( ) ;
329347 let ( alice_pk, alice_sk) = gen_keypair ( ) ;
330348 let ( bob_pk, bob_sk) = gen_keypair ( ) ;
331349
@@ -356,6 +374,7 @@ pub mod tests {
356374 // test uses "bare" functions provided by `sodiumoxide`, with an exception
357375 // of the tested function
358376 fn decrypt_data_symmetric_test ( ) {
377+ crypto_init ( ) . unwrap ( ) ;
359378 let ( alice_pk, alice_sk) = gen_keypair ( ) ;
360379 let ( bob_pk, bob_sk) = gen_keypair ( ) ;
361380
@@ -376,6 +395,7 @@ pub mod tests {
376395
377396 #[ test]
378397 fn increment_nonce_test_zero_plus_one ( ) {
398+ crypto_init ( ) . unwrap ( ) ;
379399 let cmp_nonce = Nonce ( [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
380400 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
381401 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ] ) ;
@@ -387,6 +407,7 @@ pub mod tests {
387407
388408 #[ test]
389409 fn increment_nonce_test_0xf_plus_one ( ) {
410+ crypto_init ( ) . unwrap ( ) ;
390411 let cmp_nonce = Nonce ( [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
391412 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
392413 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0x10 ] ) ;
@@ -400,6 +421,7 @@ pub mod tests {
400421
401422 #[ test]
402423 fn increment_nonce_test_0xff_plus_one ( ) {
424+ crypto_init ( ) . unwrap ( ) ;
403425 let cmp_nonce = Nonce ( [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
404426 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
405427 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 ] ) ;
@@ -413,6 +435,7 @@ pub mod tests {
413435
414436 #[ test]
415437 fn increment_nonce_test_0xff_max ( ) {
438+ crypto_init ( ) . unwrap ( ) ;
416439 let cmp_nonce = Nonce ( [ 0 ; NONCEBYTES ] ) ;
417440 let mut nonce = Nonce ( [ 0xff ; NONCEBYTES ] ) ;
418441 increment_nonce ( & mut nonce) ;
@@ -421,6 +444,7 @@ pub mod tests {
421444
422445 #[ test]
423446 fn increment_nonce_test_random ( ) {
447+ crypto_init ( ) . unwrap ( ) ;
424448 let mut nonce = gen_nonce ( ) ;
425449 let cmp_nonce = nonce;
426450 increment_nonce ( & mut nonce) ;
@@ -431,6 +455,7 @@ pub mod tests {
431455
432456 #[ test]
433457 fn increment_nonce_number_test_zero_plus_0xff00 ( ) {
458+ crypto_init ( ) . unwrap ( ) ;
434459 let cmp_nonce = Nonce ( [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
435460 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
436461 0 , 0 , 0 , 0 , 0 , 0 , 0xff , 0 ] ) ;
@@ -442,6 +467,7 @@ pub mod tests {
442467
443468 #[ test]
444469 fn increment_nonce_number_test_0xff0000_plus_0x011000 ( ) {
470+ crypto_init ( ) . unwrap ( ) ;
445471 let cmp_nonce = Nonce ( [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
446472 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
447473 0 , 0 , 0 , 0 , 1 , 0 , 0x10 , 0 ] ) ;
0 commit comments