From bcf27eaa5a23f70e85f3c2faa22078c4a3fe44a2 Mon Sep 17 00:00:00 2001 From: Roman Proskuryakov Date: Sat, 18 May 2019 21:11:33 +0300 Subject: [PATCH] chore(sodium): update to sodiumoxide 0.2.2 --- Cargo.toml | 2 +- examples/dht_server.rs | 4 ++ src/toxcore/binary_io.rs | 4 ++ src/toxcore/crypto_core.rs | 38 ++++++++++-- src/toxcore/dht/codec.rs | 6 ++ src/toxcore/dht/daemon_state.rs | 1 + src/toxcore/dht/dht_friend.rs | 5 ++ src/toxcore/dht/dht_node.rs | 1 + src/toxcore/dht/kbucket.rs | 2 + src/toxcore/dht/ktree.rs | 4 ++ src/toxcore/dht/lan_discovery.rs | 3 + src/toxcore/dht/packed_node.rs | 6 ++ src/toxcore/dht/packet/cookie.rs | 5 ++ src/toxcore/dht/packet/cookie_response.rs | 3 + src/toxcore/dht/packet/crypto_data.rs | 3 + src/toxcore/dht/packet/crypto_handshake.rs | 3 + src/toxcore/dht/packet/dht_request.rs | 6 ++ src/toxcore/dht/packet/macros.rs | 3 + src/toxcore/dht/request_queue.rs | 13 ++++ src/toxcore/dht/server/mod.rs | 4 ++ src/toxcore/dht/server_ext.rs | 1 + src/toxcore/friend_connection/packet/mod.rs | 1 - .../friend_connection/packet/share_relays.rs | 2 - src/toxcore/net_crypto/crypto_connection.rs | 18 ++++++ src/toxcore/net_crypto/mod.rs | 59 +++++++++++++++++++ src/toxcore/onion/onion_announce.rs | 18 ++++++ src/toxcore/onion/packet/mod.rs | 3 + .../onion/packet/onion_announce_request.rs | 3 + .../onion/packet/onion_announce_response.rs | 3 + .../onion/packet/onion_data_request.rs | 3 + .../onion/packet/onion_data_response.rs | 7 +++ src/toxcore/onion/packet/onion_request_0.rs | 3 + src/toxcore/onion/packet/onion_request_1.rs | 3 + src/toxcore/onion/packet/onion_request_2.rs | 3 + src/toxcore/tcp/client/client.rs | 2 + src/toxcore/tcp/client/connections.rs | 19 ++++++ src/toxcore/tcp/codec.rs | 7 +++ src/toxcore/tcp/handshake/codec.rs | 6 ++ src/toxcore/tcp/handshake/mod.rs | 6 ++ src/toxcore/tcp/links.rs | 15 +++++ src/toxcore/tcp/packet/onion_response.rs | 1 - src/toxcore/tcp/secure.rs | 2 + src/toxcore/tcp/server/server.rs | 15 +++++ src/toxcore/tcp/server/server_ext.rs | 2 + src/toxcore/toxid.rs | 4 ++ src/toxencryptsave_tests/encryptsave_tests.rs | 13 ++++ 46 files changed, 324 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f86b931ce..24368cb60 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ bytes = "0.4" byteorder = "1" futures = "0.1" log = "0.4" -sodiumoxide = { git = "https://github.com/sodiumoxide/sodiumoxide.git", rev = "baf88e5" } +sodiumoxide = "0.2.2" nom = "3.2" cookie-factory = "0.2" get_if_addrs = "0.5" diff --git a/examples/dht_server.rs b/examples/dht_server.rs index 9ede0fd4e..f804cbbff 100644 --- a/examples/dht_server.rs +++ b/examples/dht_server.rs @@ -54,6 +54,10 @@ fn bind_socket(addr: SocketAddr) -> UdpSocket { fn main() { env_logger::init(); + if crypto_init().is_err() { + panic!("Crypto initialization failed."); + } + let (server_pk, server_sk) = gen_keypair(); // Create a channel for server to communicate with network diff --git a/src/toxcore/binary_io.rs b/src/toxcore/binary_io.rs index 96fb57b00..69afcbda3 100644 --- a/src/toxcore/binary_io.rs +++ b/src/toxcore/binary_io.rs @@ -101,6 +101,10 @@ macro_rules! encode_decode_test ( ($test:ident, $value:expr) => ( #[test] fn $test() { + use crate::toxcore::crypto_core::*; + + crypto_init().unwrap(); + let value = $value; let mut buf = [0; 1024 * 1024]; let (_, size) = value.to_bytes((&mut buf, 0)).unwrap(); diff --git a/src/toxcore/crypto_core.rs b/src/toxcore/crypto_core.rs index bad58af2a..e86f339bc 100644 --- a/src/toxcore/crypto_core.rs +++ b/src/toxcore/crypto_core.rs @@ -11,14 +11,24 @@ use crate::toxcore::binary_io::*; // TODO: check if `#[inline]` is actually useful +/** Run before using crypto. -/// Initialize sodiumoxide -#[deprecated( - since = "0.0.10", - note = "libsodium is automatically initialized by sodiumoxide now." -)] +Runs [`sodiumoxide::init()`](../../../sodiumoxide/fn.init.html). + +Returns `Ok` on success, `Err` otherwise. + +E.g. + +``` +use ::tox::toxcore::crypto_core::crypto_init; + +crypto_init().unwrap(); +// second call should yield same result +crypto_init().unwrap(); +``` +*/ pub fn crypto_init() -> Result<(), ()> { - Ok(()) + ::sodiumoxide::init() } @@ -241,6 +251,7 @@ pub mod tests { // test comparing random public keys // testing since it would appear that sodiumoxide doesn't do testing for it fn public_key_cmp_test_random() { + crypto_init().unwrap(); let (alice_publickey, _alice_secretkey) = gen_keypair(); let (bob_publickey, _bob_secretkey) = gen_keypair(); @@ -254,6 +265,7 @@ pub mod tests { #[test] fn random_u32_test() { + crypto_init().unwrap(); let a = random_u32(); let b = random_u32(); assert_ne!(a, 0); @@ -265,6 +277,7 @@ pub mod tests { #[test] fn random_u64_test() { + crypto_init().unwrap(); let a = random_u64(); let b = random_u64(); assert_ne!(a, 0); @@ -275,6 +288,7 @@ pub mod tests { #[test] fn random_usize_test() { + crypto_init().unwrap(); let a = random_usize(); let b = random_usize(); assert_ne!(a, 0); @@ -285,12 +299,14 @@ pub mod tests { #[test] fn random_limit_usize_test() { + crypto_init().unwrap(); let n = random_limit_usize(7); assert!(n < 7); } #[test] fn public_key_valid_test() { + crypto_init().unwrap(); let (pk, _) = gen_keypair(); assert!(public_key_valid(&pk)); @@ -305,6 +321,7 @@ pub mod tests { // test uses "bare" functions provided by `sodiumoxide`, with an exception // of the tested function fn encrypt_precompute_test() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, bob_sk) = gen_keypair(); @@ -326,6 +343,7 @@ pub mod tests { // test uses "bare" functions provided by `sodiumoxide`, with an "exception" // of the tested function fn encrypt_data_symmetric_test() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, bob_sk) = gen_keypair(); @@ -356,6 +374,7 @@ pub mod tests { // test uses "bare" functions provided by `sodiumoxide`, with an exception // of the tested function fn decrypt_data_symmetric_test() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, bob_sk) = gen_keypair(); @@ -376,6 +395,7 @@ pub mod tests { #[test] fn increment_nonce_test_zero_plus_one() { + crypto_init().unwrap(); let cmp_nonce = Nonce([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]); @@ -387,6 +407,7 @@ pub mod tests { #[test] fn increment_nonce_test_0xf_plus_one() { + crypto_init().unwrap(); let cmp_nonce = Nonce([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10]); @@ -400,6 +421,7 @@ pub mod tests { #[test] fn increment_nonce_test_0xff_plus_one() { + crypto_init().unwrap(); let cmp_nonce = Nonce([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]); @@ -413,6 +435,7 @@ pub mod tests { #[test] fn increment_nonce_test_0xff_max() { + crypto_init().unwrap(); let cmp_nonce = Nonce([0; NONCEBYTES]); let mut nonce = Nonce([0xff; NONCEBYTES]); increment_nonce(&mut nonce); @@ -421,6 +444,7 @@ pub mod tests { #[test] fn increment_nonce_test_random() { + crypto_init().unwrap(); let mut nonce = gen_nonce(); let cmp_nonce = nonce; increment_nonce(&mut nonce); @@ -431,6 +455,7 @@ pub mod tests { #[test] fn increment_nonce_number_test_zero_plus_0xff00() { + crypto_init().unwrap(); let cmp_nonce = Nonce([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0]); @@ -442,6 +467,7 @@ pub mod tests { #[test] fn increment_nonce_number_test_0xff0000_plus_0x011000() { + crypto_init().unwrap(); let cmp_nonce = Nonce([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0x10, 0]); diff --git a/src/toxcore/dht/codec.rs b/src/toxcore/dht/codec.rs index 5841c7712..d906f9165 100644 --- a/src/toxcore/dht/codec.rs +++ b/src/toxcore/dht/codec.rs @@ -175,6 +175,7 @@ mod tests { #[test] fn encode_decode() { + crypto_init().unwrap(); let test_packets = vec![ Packet::PingRequest(PingRequest { pk: gen_keypair().0, @@ -318,6 +319,7 @@ mod tests { #[test] fn decode_encrypted_packet_incomplete() { + crypto_init().unwrap(); let stats = Stats::new(); let mut codec = DhtCodec::new(stats); let mut buf = BytesMut::new(); @@ -336,6 +338,7 @@ mod tests { #[test] fn decode_encrypted_packet_error() { + crypto_init().unwrap(); let stats = Stats::new(); let mut codec = DhtCodec::new(stats); let mut buf = BytesMut::new(); @@ -350,6 +353,7 @@ mod tests { #[test] fn decode_encrypted_packet_zero_length() { + crypto_init().unwrap(); let stats = Stats::new(); let mut codec = DhtCodec::new(stats); let mut buf = BytesMut::new(); @@ -362,6 +366,7 @@ mod tests { #[test] fn encode_packet_too_big() { + crypto_init().unwrap(); let stats = Stats::new(); let mut codec = DhtCodec::new(stats); let mut buf = BytesMut::new(); @@ -378,6 +383,7 @@ mod tests { #[test] fn codec_is_clonable() { + crypto_init().unwrap(); let stats = Stats::new(); let codec = DhtCodec::new(stats); let _codec_c = codec.clone(); diff --git a/src/toxcore/dht/daemon_state.rs b/src/toxcore/dht/daemon_state.rs index d31687d1f..44af8b671 100644 --- a/src/toxcore/dht/daemon_state.rs +++ b/src/toxcore/dht/daemon_state.rs @@ -121,6 +121,7 @@ mod tests { #[test] fn daemon_state_serialize_deserialize() { + crypto_init().unwrap(); let (pk, sk) = gen_keypair(); let (tx, rx) = mpsc::channel(1); let alice = Server::new(tx, pk, sk); diff --git a/src/toxcore/dht/dht_friend.rs b/src/toxcore/dht/dht_friend.rs index 983e72eb4..da5ea58d9 100644 --- a/src/toxcore/dht/dht_friend.rs +++ b/src/toxcore/dht/dht_friend.rs @@ -106,6 +106,7 @@ mod tests { #[test] fn addr_is_unknown() { + crypto_init().unwrap(); let pk = gen_keypair().0; let mut friend = DhtFriend::new(pk); @@ -117,6 +118,7 @@ mod tests { #[test] fn addr_is_known() { + crypto_init().unwrap(); let pk = gen_keypair().0; let mut friend = DhtFriend::new(pk); @@ -130,6 +132,7 @@ mod tests { #[test] fn get_returned_addrs() { + crypto_init().unwrap(); let pk = gen_keypair().0; let mut friend = DhtFriend::new(pk); @@ -162,6 +165,7 @@ mod tests { #[test] fn get_returned_addrs_timed_out() { + crypto_init().unwrap(); let pk = gen_keypair().0; let mut friend = DhtFriend::new(pk); @@ -194,6 +198,7 @@ mod tests { #[test] fn can_and_try_add_to_close() { + crypto_init().unwrap(); let pk = PublicKey([0; PUBLICKEYBYTES]); let mut friend = DhtFriend::new(pk); diff --git a/src/toxcore/dht/dht_node.rs b/src/toxcore/dht/dht_node.rs index 60774d20a..0eea77414 100644 --- a/src/toxcore/dht/dht_node.rs +++ b/src/toxcore/dht/dht_node.rs @@ -236,6 +236,7 @@ mod tests { #[test] fn dht_node_clonable() { + crypto_init().unwrap(); let pn = PackedNode { pk: gen_keypair().0, saddr: "127.0.0.1:33445".parse().unwrap(), diff --git a/src/toxcore/dht/kbucket.rs b/src/toxcore/dht/kbucket.rs index b8155da4d..b2e092c93 100644 --- a/src/toxcore/dht/kbucket.rs +++ b/src/toxcore/dht/kbucket.rs @@ -562,6 +562,7 @@ mod tests { #[test] fn kbucket_get_node() { + crypto_init().unwrap(); let (pk, _) = gen_keypair(); let mut kbucket = Kbucket::::new(KBUCKET_DEFAULT_SIZE); @@ -580,6 +581,7 @@ mod tests { #[test] fn kbucket_get_node_mut() { + crypto_init().unwrap(); let (pk, _) = gen_keypair(); let mut kbucket = Kbucket::::new(KBUCKET_DEFAULT_SIZE); diff --git a/src/toxcore/dht/ktree.rs b/src/toxcore/dht/ktree.rs index 2c34ef923..a60f6257a 100644 --- a/src/toxcore/dht/ktree.rs +++ b/src/toxcore/dht/ktree.rs @@ -220,6 +220,7 @@ mod tests { #[test] fn ktree_new() { + crypto_init().unwrap(); let pk = gen_keypair().0; let ktree = Ktree::new(&pk); assert_eq!(pk, ktree.pk); @@ -332,6 +333,7 @@ mod tests { #[test] fn ktree_contains() { + crypto_init().unwrap(); let (pk, _) = gen_keypair(); let mut ktree = Ktree::new(&pk); @@ -351,6 +353,7 @@ mod tests { #[test] fn ktree_can_add() { + crypto_init().unwrap(); let (pk, _) = gen_keypair(); let mut ktree = Ktree::new(&pk); @@ -416,6 +419,7 @@ mod tests { #[test] fn ktree_is_all_discarded() { + crypto_init().unwrap(); let (pk, _) = gen_keypair(); let mut ktree = Ktree::new(&pk); diff --git a/src/toxcore/dht/lan_discovery.rs b/src/toxcore/dht/lan_discovery.rs index 27d146846..bc8791a9e 100644 --- a/src/toxcore/dht/lan_discovery.rs +++ b/src/toxcore/dht/lan_discovery.rs @@ -181,6 +181,7 @@ mod tests { #[test] fn send_ipv4() { + crypto_init().unwrap(); // `+1` for 255.255.255.255 let packets_count = (broadcast_addrs_count() + 1) * (PORTS_PER_DISCOVERY + 1) as usize; @@ -206,6 +207,7 @@ mod tests { #[test] fn send_ipv6() { + crypto_init().unwrap(); // `+2` for ::1 and ::ffff:255.255.255.255 let packets_count = (broadcast_addrs_count() + 2) * (PORTS_PER_DISCOVERY + 1) as usize; @@ -231,6 +233,7 @@ mod tests { #[test] fn cycle_around_ports() { + crypto_init().unwrap(); // `+1` for 255.255.255.255 let packets_count = (broadcast_addrs_count() + 1) * (PORTS_PER_DISCOVERY + 1) as usize; diff --git a/src/toxcore/dht/packed_node.rs b/src/toxcore/dht/packed_node.rs index f043305bd..1c24d2974 100644 --- a/src/toxcore/dht/packed_node.rs +++ b/src/toxcore/dht/packed_node.rs @@ -168,6 +168,7 @@ mod tests { #[test] fn packed_node_new() { + crypto_init().unwrap(); let (pk, _sk) = gen_keypair(); let saddr = "1.2.3.4:12345".parse().unwrap(); @@ -181,6 +182,7 @@ mod tests { #[test] fn packed_node_new_ipv4_mapped() { + crypto_init().unwrap(); let (pk, _sk) = gen_keypair(); let saddr_v6 = "[::ffff:1.2.3.4]:12345".parse().unwrap(); let saddr_v4 = "1.2.3.4:12345".parse().unwrap(); @@ -195,6 +197,7 @@ mod tests { #[test] fn packed_node_ip_type_2() { + crypto_init().unwrap(); let (pk, _sk) = gen_keypair(); let saddr = "1.2.3.4:12345".parse().unwrap(); @@ -205,6 +208,7 @@ mod tests { #[test] fn packed_node_ip_type_10() { + crypto_init().unwrap(); let (pk, _sk) = gen_keypair(); let saddr = "[::1234:4321]:12345".parse().unwrap(); @@ -215,6 +219,7 @@ mod tests { #[test] fn packed_node_ip() { + crypto_init().unwrap(); let (pk, _sk) = gen_keypair(); let saddr = "1.2.3.4:12345".parse().unwrap(); @@ -225,6 +230,7 @@ mod tests { #[test] fn packed_node_socket_addr() { + crypto_init().unwrap(); let (pk, _sk) = gen_keypair(); let saddr = "1.2.3.4:12345".parse().unwrap(); diff --git a/src/toxcore/dht/packet/cookie.rs b/src/toxcore/dht/packet/cookie.rs index 1fc742f0c..4375a238e 100644 --- a/src/toxcore/dht/packet/cookie.rs +++ b/src/toxcore/dht/packet/cookie.rs @@ -197,6 +197,7 @@ mod tests { #[test] fn cookie_encrypt_decrypt() { + crypto_init().unwrap(); let symmetric_key = secretbox::gen_key(); let payload = Cookie::new(gen_keypair().0, gen_keypair().0); // encode payload with symmetric key @@ -209,6 +210,7 @@ mod tests { #[test] fn cookie_encrypt_decrypt_invalid_key() { + crypto_init().unwrap(); let symmetric_key = secretbox::gen_key(); let eve_symmetric_key = secretbox::gen_key(); let payload = Cookie::new(gen_keypair().0, gen_keypair().0); @@ -222,6 +224,7 @@ mod tests { #[test] fn cookie_encrypt_decrypt_invalid() { + crypto_init().unwrap(); let symmetric_key = secretbox::gen_key(); let nonce = secretbox::gen_nonce(); // Try long invalid array @@ -248,6 +251,7 @@ mod tests { #[test] fn cookie_timed_out() { + crypto_init().unwrap(); let mut cookie = Cookie::new(gen_keypair().0, gen_keypair().0); assert!(!cookie.is_timed_out()); cookie.time -= COOKIE_TIMEOUT + 1; @@ -256,6 +260,7 @@ mod tests { #[test] fn hash_depends_on_all_fields() { + crypto_init().unwrap(); let nonce = secretbox::gen_nonce(); let payload = vec![42; 88]; let cookie = EncryptedCookie { diff --git a/src/toxcore/dht/packet/cookie_response.rs b/src/toxcore/dht/packet/cookie_response.rs index 09b963961..538d8269e 100644 --- a/src/toxcore/dht/packet/cookie_response.rs +++ b/src/toxcore/dht/packet/cookie_response.rs @@ -157,6 +157,7 @@ mod tests { #[test] fn cookie_response_encrypt_decrypt() { + crypto_init().unwrap(); let (_alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let shared_secret = encrypt_precompute(&bob_pk, &alice_sk); @@ -177,6 +178,7 @@ mod tests { #[test] fn cookie_response_encrypt_decrypt_invalid_key() { + crypto_init().unwrap(); let (_alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let (_eve_pk, eve_sk) = gen_keypair(); @@ -199,6 +201,7 @@ mod tests { #[test] fn cookie_response_encrypt_decrypt_invalid() { + crypto_init().unwrap(); let (_alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let shared_secret = encrypt_precompute(&bob_pk, &alice_sk); diff --git a/src/toxcore/dht/packet/crypto_data.rs b/src/toxcore/dht/packet/crypto_data.rs index f096e1c8e..fa8392771 100644 --- a/src/toxcore/dht/packet/crypto_data.rs +++ b/src/toxcore/dht/packet/crypto_data.rs @@ -172,6 +172,7 @@ mod tests { #[test] fn crypto_data_encrypt_decrypt() { + crypto_init().unwrap(); let (_alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let shared_secret = encrypt_precompute(&bob_pk, &alice_sk); @@ -196,6 +197,7 @@ mod tests { #[test] fn crypto_data_encrypt_decrypt_invalid_key() { + crypto_init().unwrap(); let (_alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let (_eve_pk, eve_sk) = gen_keypair(); @@ -222,6 +224,7 @@ mod tests { #[test] fn crypto_data_encrypt_decrypt_invalid() { + crypto_init().unwrap(); let (_alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let shared_secret = encrypt_precompute(&bob_pk, &alice_sk); diff --git a/src/toxcore/dht/packet/crypto_handshake.rs b/src/toxcore/dht/packet/crypto_handshake.rs index da2f2aea8..dd5dca6dc 100644 --- a/src/toxcore/dht/packet/crypto_handshake.rs +++ b/src/toxcore/dht/packet/crypto_handshake.rs @@ -196,6 +196,7 @@ mod tests { #[test] fn crypto_handshake_encrypt_decrypt() { + crypto_init().unwrap(); let (_alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let shared_secret = encrypt_precompute(&bob_pk, &alice_sk); @@ -222,6 +223,7 @@ mod tests { #[test] fn crypto_handshake_encrypt_decrypt_invalid_key() { + crypto_init().unwrap(); let (_alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let (_eve_pk, eve_sk) = gen_keypair(); @@ -250,6 +252,7 @@ mod tests { #[test] fn crypto_handshake_encrypt_decrypt_invalid() { + crypto_init().unwrap(); let (_alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let shared_secret = encrypt_precompute(&bob_pk, &alice_sk); diff --git a/src/toxcore/dht/packet/dht_request.rs b/src/toxcore/dht/packet/dht_request.rs index 7633a2fac..1064e9e63 100644 --- a/src/toxcore/dht/packet/dht_request.rs +++ b/src/toxcore/dht/packet/dht_request.rs @@ -528,6 +528,7 @@ mod tests { #[test] fn dht_request_payload_encrypt_decrypt() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, bob_sk) = gen_keypair(); let shared_secret = encrypt_precompute(&bob_pk, &alice_sk); @@ -552,6 +553,7 @@ mod tests { #[test] fn dht_request_payload_encrypt_decrypt_invalid_key() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let (_eve_pk, eve_sk) = gen_keypair(); @@ -576,6 +578,7 @@ mod tests { #[test] fn dht_request_decode_invalid() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, bob_sk) = gen_keypair(); let shared_secret = encrypt_precompute(&bob_pk, &alice_sk); @@ -611,6 +614,7 @@ mod tests { #[test] fn dht_pk_announce_payload_encrypt_decrypt() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let shared_secret = encrypt_precompute(&bob_pk, &alice_sk); @@ -637,6 +641,7 @@ mod tests { #[test] fn dht_pk_announce_payload_encrypt_decrypt_invalid_key() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let (_eve_pk, eve_sk) = gen_keypair(); @@ -664,6 +669,7 @@ mod tests { #[test] fn dht_pk_announce_payload_encrypt_decrypt_invalid() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let shared_secret = encrypt_precompute(&bob_pk, &alice_sk); diff --git a/src/toxcore/dht/packet/macros.rs b/src/toxcore/dht/packet/macros.rs index d372d6f22..744ada186 100644 --- a/src/toxcore/dht/packet/macros.rs +++ b/src/toxcore/dht/packet/macros.rs @@ -18,6 +18,7 @@ macro_rules! dht_packet_encrypt_decrypt ( ($test:ident, $packet:ident, $payload:expr) => ( #[test] fn $test() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let shared_secret = encrypt_precompute(&bob_pk, &alice_sk); @@ -36,6 +37,7 @@ macro_rules! dht_packet_encrypt_decrypt_invalid_key ( ($test:ident, $packet:ident, $payload:expr) => ( #[test] fn $test() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let (_eve_pk, eve_sk) = gen_keypair(); @@ -55,6 +57,7 @@ macro_rules! dht_packet_decode_invalid ( ($test:ident, $packet:ident) => ( #[test] fn $test() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let shared_secret = encrypt_precompute(&bob_pk, &alice_sk); diff --git a/src/toxcore/dht/request_queue.rs b/src/toxcore/dht/request_queue.rs index e1052913b..216d99616 100644 --- a/src/toxcore/dht/request_queue.rs +++ b/src/toxcore/dht/request_queue.rs @@ -90,6 +90,7 @@ mod tests { use tokio_executor; use tokio_timer::clock::*; + use crate::toxcore::crypto_core::*; use crate::toxcore::time::ConstNow; #[test] @@ -100,6 +101,8 @@ mod tests { #[test] fn insert_new_ping_id() { + crypto_init().unwrap(); + let mut queue = RequestQueue::new(Duration::from_secs(42)); let ping_id = queue.new_ping_id(7); @@ -109,6 +112,8 @@ mod tests { #[test] fn check_ping_id() { + crypto_init().unwrap(); + let mut queue = RequestQueue::new(Duration::from_secs(42)); let ping_id = queue.new_ping_id(7); @@ -126,6 +131,8 @@ mod tests { #[test] fn check_ping_id_nonexistent() { + crypto_init().unwrap(); + let mut queue = RequestQueue::new(Duration::from_secs(42)); let ping_id = queue.new_ping_id(()); @@ -135,6 +142,8 @@ mod tests { #[test] fn check_ping_id_timed_out() { + crypto_init().unwrap(); + let mut queue = RequestQueue::new(Duration::from_secs(42)); let ping_id = queue.new_ping_id(()); @@ -152,6 +161,8 @@ mod tests { #[test] fn clear_timed_out() { + crypto_init().unwrap(); + let mut queue = RequestQueue::new(Duration::from_secs(42)); let ping_id_1 = queue.new_ping_id(()); @@ -180,6 +191,8 @@ mod tests { #[test] fn get_values() { + crypto_init().unwrap(); + let mut queue = RequestQueue::new(Duration::from_secs(42)); let _ping_id_1 = queue.new_ping_id(1); diff --git a/src/toxcore/dht/server/mod.rs b/src/toxcore/dht/server/mod.rs index e9e6549a0..01060f18d 100644 --- a/src/toxcore/dht/server/mod.rs +++ b/src/toxcore/dht/server/mod.rs @@ -1463,6 +1463,8 @@ mod tests { fn create_node() -> (Server, PrecomputedKey, PublicKey, SecretKey, mpsc::Receiver<(Packet, SocketAddr)>, SocketAddr) { + crypto_init().unwrap(); + let (pk, sk) = gen_keypair(); let (tx, rx) = mpsc::channel(32); let alice = Server::new(tx, pk, sk); @@ -1475,6 +1477,7 @@ mod tests { #[test] fn server_is_clonable() { + crypto_init().unwrap(); let (pk, sk) = gen_keypair(); let (tx, _rx) = mpsc::channel(1); let server = Server::new(tx, pk, sk); @@ -2052,6 +2055,7 @@ mod tests { // handle_cookie_request #[test] fn handle_cookie_request() { + crypto_init().unwrap(); let (udp_tx, udp_rx) = mpsc::channel(1); let (dht_pk, dht_sk) = gen_keypair(); let mut alice = Server::new(udp_tx.clone(), dht_pk, dht_sk.clone()); diff --git a/src/toxcore/dht/server_ext.rs b/src/toxcore/dht/server_ext.rs index 7fb97659a..23ca6aea3 100644 --- a/src/toxcore/dht/server_ext.rs +++ b/src/toxcore/dht/server_ext.rs @@ -85,6 +85,7 @@ mod tests { #[test] fn run_socket() { + crypto_init().unwrap(); let (client_pk, client_sk) = gen_keypair(); let (server_pk, server_sk) = gen_keypair(); let shared_secret = precompute(&server_pk, &client_sk); diff --git a/src/toxcore/friend_connection/packet/mod.rs b/src/toxcore/friend_connection/packet/mod.rs index 1bc4d4fb1..da9afc3ad 100644 --- a/src/toxcore/friend_connection/packet/mod.rs +++ b/src/toxcore/friend_connection/packet/mod.rs @@ -46,7 +46,6 @@ mod tests { use super::*; use crate::toxcore::toxid::NoSpam; use crate::toxcore::dht::packed_node::*; - use crate::toxcore::crypto_core::*; encode_decode_test!( packet_alive_encode_decode, diff --git a/src/toxcore/friend_connection/packet/share_relays.rs b/src/toxcore/friend_connection/packet/share_relays.rs index 5dd1870bc..0b0b51dd3 100644 --- a/src/toxcore/friend_connection/packet/share_relays.rs +++ b/src/toxcore/friend_connection/packet/share_relays.rs @@ -53,8 +53,6 @@ impl ToBytes for ShareRelays { mod tests { use super::*; - use crate::toxcore::crypto_core::*; - encode_decode_test!( share_relays_encode_decode, ShareRelays::new(vec![ diff --git a/src/toxcore/net_crypto/crypto_connection.rs b/src/toxcore/net_crypto/crypto_connection.rs index 7f7c10c64..576057f61 100644 --- a/src/toxcore/net_crypto/crypto_connection.rs +++ b/src/toxcore/net_crypto/crypto_connection.rs @@ -672,6 +672,7 @@ mod tests { #[test] fn status_packet_should_be_sent() { + crypto_init().unwrap(); // just created packet should be sent let mut packet = StatusPacket::new_cookie_request(CookieRequest { pk: gen_keypair().0, @@ -701,6 +702,7 @@ mod tests { #[test] fn status_packet_is_timed_out() { + crypto_init().unwrap(); // just created packet isn't timed out let mut packet = StatusPacket::new_cookie_request(CookieRequest { pk: gen_keypair().0, @@ -725,6 +727,7 @@ mod tests { #[test] fn sent_packet_clone() { + crypto_init().unwrap(); let sent_packet = SentPacket::new(vec![42; 123]); let sent_packet_c = sent_packet.clone(); assert_eq!(sent_packet_c, sent_packet); @@ -732,6 +735,7 @@ mod tests { #[test] fn recv_packet_clone() { + crypto_init().unwrap(); let recv_packet = RecvPacket::new(vec![42; 123]); let recv_packet_c = recv_packet.clone(); assert_eq!(recv_packet_c, recv_packet); @@ -739,6 +743,7 @@ mod tests { #[test] fn crypto_connection_clone() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (real_pk, _real_sk) = gen_keypair(); let (peer_dht_pk, _peer_dht_sk) = gen_keypair(); @@ -788,6 +793,7 @@ mod tests { #[test] fn update_congestion_stats() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (real_pk, _real_sk) = gen_keypair(); let (peer_dht_pk, _peer_dht_sk) = gen_keypair(); @@ -821,6 +827,7 @@ mod tests { #[test] fn request_packet_interval() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (real_pk, _real_sk) = gen_keypair(); let (peer_dht_pk, _peer_dht_sk) = gen_keypair(); @@ -848,6 +855,7 @@ mod tests { #[test] fn is_established() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (real_pk, _real_sk) = gen_keypair(); let (peer_dht_pk, _peer_dht_sk) = gen_keypair(); @@ -867,6 +875,7 @@ mod tests { #[test] fn is_not_confirmed() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (real_pk, _real_sk) = gen_keypair(); let (peer_dht_pk, _peer_dht_sk) = gen_keypair(); @@ -896,6 +905,7 @@ mod tests { #[test] fn set_get_udp_addr_v4() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (real_pk, _real_sk) = gen_keypair(); let (peer_dht_pk, _peer_dht_sk) = gen_keypair(); @@ -910,6 +920,7 @@ mod tests { #[test] fn set_get_udp_addr_v6() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (real_pk, _real_sk) = gen_keypair(); let (peer_dht_pk, _peer_dht_sk) = gen_keypair(); @@ -924,6 +935,7 @@ mod tests { #[test] fn get_udp_addr_alive_ipv6_lan() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (real_pk, _real_sk) = gen_keypair(); let (peer_dht_pk, _peer_dht_sk) = gen_keypair(); @@ -942,6 +954,7 @@ mod tests { #[test] fn get_udp_addr_alive_ipv4_lan() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (real_pk, _real_sk) = gen_keypair(); let (peer_dht_pk, _peer_dht_sk) = gen_keypair(); @@ -960,6 +973,7 @@ mod tests { #[test] fn get_udp_addr_alive_ipv6() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (real_pk, _real_sk) = gen_keypair(); let (peer_dht_pk, _peer_dht_sk) = gen_keypair(); @@ -978,6 +992,7 @@ mod tests { #[test] fn get_udp_addr_alive_ipv4() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (real_pk, _real_sk) = gen_keypair(); let (peer_dht_pk, _peer_dht_sk) = gen_keypair(); @@ -1002,6 +1017,7 @@ mod tests { #[test] fn get_udp_addr_ipv6() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (real_pk, _real_sk) = gen_keypair(); let (peer_dht_pk, _peer_dht_sk) = gen_keypair(); @@ -1025,6 +1041,7 @@ mod tests { #[test] fn get_udp_addr_ipv4() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (real_pk, _real_sk) = gen_keypair(); let (peer_dht_pk, _peer_dht_sk) = gen_keypair(); @@ -1046,6 +1063,7 @@ mod tests { #[test] fn get_udp_addr_none() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (real_pk, _real_sk) = gen_keypair(); let (peer_dht_pk, _peer_dht_sk) = gen_keypair(); diff --git a/src/toxcore/net_crypto/mod.rs b/src/toxcore/net_crypto/mod.rs index f6405f1cf..93632e9a8 100644 --- a/src/toxcore/net_crypto/mod.rs +++ b/src/toxcore/net_crypto/mod.rs @@ -919,6 +919,7 @@ mod tests { #[test] fn net_crypto_clone() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -943,6 +944,7 @@ mod tests { #[test] fn add_remove_friend() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -972,6 +974,7 @@ mod tests { #[test] fn handle_cookie_request() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -1014,6 +1017,7 @@ mod tests { #[test] fn handle_cookie_request_invalid() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -1046,6 +1050,7 @@ mod tests { #[test] fn handle_udp_cookie_request() { + crypto_init().unwrap(); let (udp_tx, udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -1097,6 +1102,7 @@ mod tests { #[test] fn handle_udp_cookie_request_invalid() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -1131,6 +1137,7 @@ mod tests { #[test] fn handle_cookie_response() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -1179,6 +1186,7 @@ mod tests { #[test] fn handle_cookie_response_invalid_status() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -1230,6 +1238,7 @@ mod tests { #[test] fn handle_cookie_response_invalid_request_id() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -1272,6 +1281,7 @@ mod tests { #[test] fn handle_udp_cookie_response() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -1329,6 +1339,7 @@ mod tests { #[test] fn handle_udp_cookie_response_no_connection() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -1370,6 +1381,7 @@ mod tests { #[test] fn handle_crypto_handshake_in_cookie_requesting_status() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -1426,6 +1438,7 @@ mod tests { #[test] fn handle_crypto_handshake_in_not_confirmed_status() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -1495,6 +1508,7 @@ mod tests { #[test] fn handle_crypto_handshake_invalid_status() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -1551,6 +1565,7 @@ mod tests { #[test] fn handle_crypto_handshake_invalid_hash() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -1599,6 +1614,7 @@ mod tests { #[test] fn handle_crypto_handshake_timed_out_cookie() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -1648,6 +1664,7 @@ mod tests { #[test] fn handle_crypto_handshake_invalid_peer_real_pk() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -1697,6 +1714,7 @@ mod tests { #[test] fn handle_crypto_handshake_invalid_peer_dht_pk() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -1753,6 +1771,7 @@ mod tests { #[test] fn handle_udp_crypto_handshake() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -1818,6 +1837,7 @@ mod tests { #[test] fn handle_udp_crypto_handshake_new_connection() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -1881,6 +1901,7 @@ mod tests { #[test] fn handle_udp_crypto_handshake_unexpected() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -1929,6 +1950,7 @@ mod tests { #[test] fn handle_crypto_data_lossy() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -1989,6 +2011,7 @@ mod tests { #[test] fn handle_crypto_data_lossy_increment_nonce() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -2055,6 +2078,7 @@ mod tests { #[test] fn handle_crypto_data_lossy_update_rtt() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -2137,6 +2161,7 @@ mod tests { #[test] fn handle_crypto_data_lossy_invalid_buffer_start() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -2192,6 +2217,7 @@ mod tests { #[test] fn handle_crypto_data_lossless() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, lossless_rx) = mpsc::unbounded(); @@ -2281,6 +2307,7 @@ mod tests { #[test] fn handle_crypto_data_lossless_too_big_index() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -2336,6 +2363,7 @@ mod tests { #[test] fn handle_crypto_data_kill() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -2392,6 +2420,7 @@ mod tests { #[test] fn handle_crypto_data_request() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -2478,6 +2507,7 @@ mod tests { #[test] fn handle_crypto_data_empty_request() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -2536,6 +2566,7 @@ mod tests { #[test] fn handle_crypto_data_invalid_packet_id() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -2591,6 +2622,7 @@ mod tests { #[test] fn handle_crypto_data_empty_data() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -2646,6 +2678,7 @@ mod tests { #[test] fn handle_crypto_data_invalid_status() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -2688,6 +2721,7 @@ mod tests { #[test] fn handle_udp_crypto_data_lossy() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -2757,6 +2791,7 @@ mod tests { #[test] fn send_status_packet() { + crypto_init().unwrap(); let (udp_tx, udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -2805,6 +2840,7 @@ mod tests { #[test] fn send_packet_udp() { + crypto_init().unwrap(); let (udp_tx, udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -2848,6 +2884,7 @@ mod tests { #[test] fn send_packet_udp_attempt() { + crypto_init().unwrap(); let (udp_tx, udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -2898,6 +2935,7 @@ mod tests { #[test] fn send_packet_no_udp_attempt() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -2937,6 +2975,7 @@ mod tests { #[test] fn send_packet_tcp() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -2973,6 +3012,7 @@ mod tests { #[test] fn main_loop_sends_status_packets() { + crypto_init().unwrap(); let (udp_tx, udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -3015,6 +3055,7 @@ mod tests { #[test] fn main_loop_removes_timed_out_connections() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -3065,6 +3106,7 @@ mod tests { #[test] fn main_loop_sends_request_packets() { + crypto_init().unwrap(); let (udp_tx, udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -3122,6 +3164,7 @@ mod tests { #[test] fn main_loop_sends_requested_packets() { + crypto_init().unwrap(); let (udp_tx, udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -3192,6 +3235,7 @@ mod tests { #[test] fn send_status_packet_established() { + crypto_init().unwrap(); let (udp_tx, udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -3237,6 +3281,7 @@ mod tests { #[test] fn send_data_packet() { + crypto_init().unwrap(); let (udp_tx, udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -3299,6 +3344,7 @@ mod tests { #[test] fn send_request_packet() { + crypto_init().unwrap(); let (udp_tx, udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -3371,6 +3417,7 @@ mod tests { #[test] fn send_request_packet_too_many_missing_packets() { + crypto_init().unwrap(); let (udp_tx, udp_rx) = mpsc::channel(1); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -3427,6 +3474,7 @@ mod tests { #[test] fn send_requested_packets() { + crypto_init().unwrap(); let (udp_tx, udp_rx) = mpsc::channel(2); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -3506,6 +3554,7 @@ mod tests { #[test] fn send_lossless() { + crypto_init().unwrap(); let (udp_tx, udp_rx) = mpsc::channel(2); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -3576,6 +3625,7 @@ mod tests { #[test] fn send_lossless_no_connection() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(2); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -3603,6 +3653,7 @@ mod tests { #[test] fn send_lossless_invalid_packet_id() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(2); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -3630,6 +3681,7 @@ mod tests { #[test] fn add_connection() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(2); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -3668,6 +3720,7 @@ mod tests { #[test] fn add_connection_already_exists() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(2); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -3704,6 +3757,7 @@ mod tests { #[test] fn set_friend_udp_addr() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(2); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -3743,6 +3797,7 @@ mod tests { #[test] fn set_friend_udp_addr_update() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(2); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -3786,6 +3841,7 @@ mod tests { #[test] fn set_friend_udp_addr_no_connection() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(2); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -3816,6 +3872,7 @@ mod tests { #[test] fn kill_connection() { + crypto_init().unwrap(); let (udp_tx, udp_rx) = mpsc::channel(2); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -3876,6 +3933,7 @@ mod tests { #[test] fn kill_connection_no_connection() { + crypto_init().unwrap(); let (udp_tx, _udp_rx) = mpsc::channel(2); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); @@ -3903,6 +3961,7 @@ mod tests { #[test] fn kill_connection_not_established() { + crypto_init().unwrap(); let (udp_tx, udp_rx) = mpsc::channel(2); let (dht_pk_tx, _dht_pk_rx) = mpsc::unbounded(); let (lossless_tx, _lossless_rx) = mpsc::unbounded(); diff --git a/src/toxcore/onion/onion_announce.rs b/src/toxcore/onion/onion_announce.rs index 92571af1c..d0ef9d6b2 100644 --- a/src/toxcore/onion/onion_announce.rs +++ b/src/toxcore/onion/onion_announce.rs @@ -347,6 +347,7 @@ mod tests { #[test] fn announce_entry_valid() { + crypto_init().unwrap(); let entry = OnionAnnounceEntry::new( PublicKey::from_slice(&[1; 32]).unwrap(), "1.2.3.4".parse().unwrap(), @@ -362,6 +363,7 @@ mod tests { #[test] fn announce_entry_expired() { + crypto_init().unwrap(); let entry = OnionAnnounceEntry::new( PublicKey::from_slice(&[1; 32]).unwrap(), "1.2.3.4".parse().unwrap(), @@ -386,6 +388,7 @@ mod tests { #[test] fn ping_id_respects_timeout_gap() { + crypto_init().unwrap(); let onion_announce = OnionAnnounce::new(gen_keypair().0); let time = SystemTime::now(); @@ -403,6 +406,7 @@ mod tests { #[test] fn ping_id_depends_on_all_args() { + crypto_init().unwrap(); let onion_announce = OnionAnnounce::new(gen_keypair().0); let time_1 = SystemTime::now(); @@ -433,6 +437,7 @@ mod tests { } fn create_random_entry(saddr: SocketAddr) -> OnionAnnounceEntry { + crypto_init().unwrap(); OnionAnnounceEntry::new( gen_keypair().0, saddr.ip(), @@ -447,6 +452,7 @@ mod tests { #[test] fn onion_announce_is_clonable() { + crypto_init().unwrap(); let dht_pk = gen_keypair().0; let mut onion_announce = OnionAnnounce::new(dht_pk); let entry = create_random_entry("1.2.3.4:12345".parse().unwrap()); @@ -457,6 +463,7 @@ mod tests { #[test] fn expired_entry_not_in_entries() { + crypto_init().unwrap(); let dht_pk = gen_keypair().0; let mut onion_announce = OnionAnnounce::new(dht_pk); @@ -481,6 +488,7 @@ mod tests { // Tests for OnionAnnounce::add_to_entries #[test] fn add_to_entries_when_limit_is_not_reached() { + crypto_init().unwrap(); let dht_pk = gen_keypair().0; let mut onion_announce = OnionAnnounce::new(dht_pk); @@ -503,6 +511,7 @@ mod tests { #[test] fn add_to_entries_should_update_existent_entry() { + crypto_init().unwrap(); let dht_pk = gen_keypair().0; let mut onion_announce = OnionAnnounce::new(dht_pk); @@ -543,6 +552,7 @@ mod tests { #[test] fn add_to_entries_should_replace_timed_out_entries() { + crypto_init().unwrap(); let dht_pk = gen_keypair().0; let mut onion_announce = OnionAnnounce::new(dht_pk); @@ -592,6 +602,7 @@ mod tests { #[test] fn add_to_entries_should_replace_the_farthest_entry() { + crypto_init().unwrap(); let dht_pk = PublicKey::from_slice(&[0; 32]).unwrap(); let mut onion_announce = OnionAnnounce::new(dht_pk); @@ -627,6 +638,7 @@ mod tests { #[test] fn add_to_entries_should_should_not_add_the_farthest_entry() { + crypto_init().unwrap(); let dht_pk = PublicKey::from_slice(&[0; 32]).unwrap(); let mut onion_announce = OnionAnnounce::new(dht_pk); @@ -660,6 +672,7 @@ mod tests { // Tests for OnionAnnounce::handle_onion_announce_request #[test] fn handle_announce_failed_to_find_node() { + crypto_init().unwrap(); let dht_pk = gen_keypair().0; let search_pk = gen_keypair().0; let data_pk = gen_keypair().0; @@ -697,6 +710,7 @@ mod tests { #[test] fn handle_announce_node_is_found() { + crypto_init().unwrap(); let dht_pk = gen_keypair().0; let data_pk = gen_keypair().0; let packet_pk = gen_keypair().0; @@ -736,6 +750,7 @@ mod tests { #[test] fn handle_announce_successfully_announced() { + crypto_init().unwrap(); let dht_pk = gen_keypair().0; let search_pk = gen_keypair().0; let data_pk = gen_keypair().0; @@ -776,6 +791,7 @@ mod tests { #[test] fn handle_announce_failed_to_find_ourselves_with_different_data_pk() { // weird case, should we remove it? + crypto_init().unwrap(); let dht_pk = gen_keypair().0; let data_pk = gen_keypair().0; let packet_pk = gen_keypair().0; @@ -816,6 +832,7 @@ mod tests { // Tests for OnionAnnounce::handle_onion_announce_request #[test] fn handle_data_request() { + crypto_init().unwrap(); let (dht_pk, _dht_sk) = gen_keypair(); let mut onion_announce = OnionAnnounce::new(dht_pk); @@ -860,6 +877,7 @@ mod tests { #[test] fn handle_data_request_unknown_destination() { + crypto_init().unwrap(); let (dht_pk, _dht_sk) = gen_keypair(); let onion_announce = OnionAnnounce::new(dht_pk); diff --git a/src/toxcore/onion/packet/mod.rs b/src/toxcore/onion/packet/mod.rs index 6fe95f8ad..b83fd337d 100644 --- a/src/toxcore/onion/packet/mod.rs +++ b/src/toxcore/onion/packet/mod.rs @@ -203,6 +203,7 @@ mod tests { #[test] fn onion_return_encrypt_decrypt() { + crypto_init().unwrap(); let alice_symmetric_key = secretbox::gen_key(); let bob_symmetric_key = secretbox::gen_key(); // alice encrypt @@ -231,6 +232,7 @@ mod tests { #[test] fn onion_return_encrypt_decrypt_invalid_key() { + crypto_init().unwrap(); let alice_symmetric_key = secretbox::gen_key(); let bob_symmetric_key = secretbox::gen_key(); let eve_symmetric_key = secretbox::gen_key(); @@ -255,6 +257,7 @@ mod tests { #[test] fn onion_return_decrypt_invalid() { + crypto_init().unwrap(); let symmetric_key = secretbox::gen_key(); let nonce = secretbox::gen_nonce(); // Try long invalid array diff --git a/src/toxcore/onion/packet/onion_announce_request.rs b/src/toxcore/onion/packet/onion_announce_request.rs index 7b4b19850..ab6dc2ac9 100644 --- a/src/toxcore/onion/packet/onion_announce_request.rs +++ b/src/toxcore/onion/packet/onion_announce_request.rs @@ -247,6 +247,7 @@ mod tests { #[test] fn onion_announce_request_payload_encrypt_decrypt() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let shared_secret = encrypt_precompute(&bob_pk, &alice_sk); @@ -266,6 +267,7 @@ mod tests { #[test] fn onion_announce_request_payload_encrypt_decrypt_invalid_key() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let (_eve_pk, eve_sk) = gen_keypair(); @@ -286,6 +288,7 @@ mod tests { #[test] fn onion_announce_request_decrypt_invalid() { + crypto_init().unwrap(); let (_alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let shared_secret = precompute(&bob_pk, &alice_sk); diff --git a/src/toxcore/onion/packet/onion_announce_response.rs b/src/toxcore/onion/packet/onion_announce_response.rs index d4f807619..329cc6347 100644 --- a/src/toxcore/onion/packet/onion_announce_response.rs +++ b/src/toxcore/onion/packet/onion_announce_response.rs @@ -192,6 +192,7 @@ mod tests { #[test] fn onion_announce_response_payload_encrypt_decrypt() { + crypto_init().unwrap(); let (_alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let shared_secret = encrypt_precompute(&bob_pk, &alice_sk); @@ -212,6 +213,7 @@ mod tests { #[test] fn onion_announce_response_payload_encrypt_decrypt_invalid_key() { + crypto_init().unwrap(); let (_alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let (_eve_pk, eve_sk) = gen_keypair(); @@ -233,6 +235,7 @@ mod tests { #[test] fn onion_announce_response_decrypt_invalid() { + crypto_init().unwrap(); let (_alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let shared_secret = precompute(&bob_pk, &alice_sk); diff --git a/src/toxcore/onion/packet/onion_data_request.rs b/src/toxcore/onion/packet/onion_data_request.rs index ba5dbb508..fa5e44522 100644 --- a/src/toxcore/onion/packet/onion_data_request.rs +++ b/src/toxcore/onion/packet/onion_data_request.rs @@ -199,6 +199,7 @@ mod tests { #[test] fn inner_onion_data_request_encrypt_decrypt() { + crypto_init().unwrap(); let (real_pk, _real_sk) = gen_keypair(); let (data_pk, _data_sk) = gen_keypair(); let (temporary_pk, temporary_sk) = gen_keypair(); @@ -218,6 +219,7 @@ mod tests { #[test] fn inner_onion_data_request_encrypt_decrypt_invalid_key() { + crypto_init().unwrap(); let (real_pk, _real_sk) = gen_keypair(); let (data_pk, _data_sk) = gen_keypair(); let (temporary_pk, temporary_sk) = gen_keypair(); @@ -238,6 +240,7 @@ mod tests { #[test] fn inner_onion_data_request_encrypt_decrypt_invalid() { + crypto_init().unwrap(); let (real_pk, _real_sk) = gen_keypair(); let (data_pk, _data_sk) = gen_keypair(); let (temporary_pk, temporary_sk) = gen_keypair(); diff --git a/src/toxcore/onion/packet/onion_data_response.rs b/src/toxcore/onion/packet/onion_data_response.rs index 0917b8c31..d858e9b33 100644 --- a/src/toxcore/onion/packet/onion_data_response.rs +++ b/src/toxcore/onion/packet/onion_data_response.rs @@ -241,6 +241,7 @@ mod tests { #[test] fn onion_data_response_encrypt_decrypt() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let nonce = gen_nonce(); @@ -259,6 +260,7 @@ mod tests { #[test] fn onion_data_response_encrypt_decrypt_invalid_key() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let (_eve_pk, eve_sk) = gen_keypair(); @@ -278,6 +280,7 @@ mod tests { #[test] fn onion_data_response_encrypt_decrypt_invalid() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let shared_secret = encrypt_precompute(&bob_pk, &alice_sk); @@ -296,6 +299,7 @@ mod tests { #[test] fn onion_data_response_payload_encrypt_decrypt() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let nonce = gen_nonce(); @@ -324,6 +328,7 @@ mod tests { #[test] fn onion_data_response_payload_encrypt_decrypt_invalid_key() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let (_eve_pk, eve_sk) = gen_keypair(); @@ -353,6 +358,7 @@ mod tests { #[test] fn onion_data_response_payload_encrypt_decrypt_invalid() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let shared_secret = encrypt_precompute(&bob_pk, &alice_sk); @@ -379,6 +385,7 @@ mod tests { #[test] fn onion_data_response_payload_encrypt_decrypt_friend_request() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let nonce = gen_nonce(); diff --git a/src/toxcore/onion/packet/onion_request_0.rs b/src/toxcore/onion/packet/onion_request_0.rs index d8b30b222..500c9d8e9 100644 --- a/src/toxcore/onion/packet/onion_request_0.rs +++ b/src/toxcore/onion/packet/onion_request_0.rs @@ -186,6 +186,7 @@ mod tests { #[test] fn onion_request_0_payload_encrypt_decrypt() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let shared_secret = encrypt_precompute(&bob_pk, &alice_sk); @@ -208,6 +209,7 @@ mod tests { #[test] fn onion_request_0_payload_encrypt_decrypt_invalid_key() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let (_eve_pk, eve_sk) = gen_keypair(); @@ -231,6 +233,7 @@ mod tests { #[test] fn onion_request_0_decrypt_invalid() { + crypto_init().unwrap(); let (_alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let shared_secret = precompute(&bob_pk, &alice_sk); diff --git a/src/toxcore/onion/packet/onion_request_1.rs b/src/toxcore/onion/packet/onion_request_1.rs index 3a319d4b9..6905d1080 100644 --- a/src/toxcore/onion/packet/onion_request_1.rs +++ b/src/toxcore/onion/packet/onion_request_1.rs @@ -201,6 +201,7 @@ mod tests { #[test] fn onion_request_1_payload_encrypt_decrypt() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let shared_secret = encrypt_precompute(&bob_pk, &alice_sk); @@ -227,6 +228,7 @@ mod tests { #[test] fn onion_request_1_payload_encrypt_decrypt_invalid_key() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let (_eve_pk, eve_sk) = gen_keypair(); @@ -254,6 +256,7 @@ mod tests { #[test] fn onion_request_1_decrypt_invalid() { + crypto_init().unwrap(); let (_alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let shared_secret = precompute(&bob_pk, &alice_sk); diff --git a/src/toxcore/onion/packet/onion_request_2.rs b/src/toxcore/onion/packet/onion_request_2.rs index a574c4a4b..166a3d5cd 100644 --- a/src/toxcore/onion/packet/onion_request_2.rs +++ b/src/toxcore/onion/packet/onion_request_2.rs @@ -193,6 +193,7 @@ mod tests { #[test] fn onion_request_2_payload_encrypt_decrypt() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let shared_secret = encrypt_precompute(&bob_pk, &alice_sk); @@ -223,6 +224,7 @@ mod tests { #[test] fn onion_request_2_payload_encrypt_decrypt_invalid_key() { + crypto_init().unwrap(); let (alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let (_eve_pk, eve_sk) = gen_keypair(); @@ -254,6 +256,7 @@ mod tests { #[test] fn onion_request_2_decrypt_invalid() { + crypto_init().unwrap(); let (_alice_pk, alice_sk) = gen_keypair(); let (bob_pk, _bob_sk) = gen_keypair(); let shared_secret = precompute(&bob_pk, &alice_sk); diff --git a/src/toxcore/tcp/client/client.rs b/src/toxcore/tcp/client/client.rs index 55c0f737d..9771d823e 100644 --- a/src/toxcore/tcp/client/client.rs +++ b/src/toxcore/tcp/client/client.rs @@ -534,6 +534,7 @@ pub mod tests { use crate::toxcore::tcp::server::{Server, ServerExt}; pub fn create_client() -> (mpsc::UnboundedReceiver<(PublicKey, IncomingPacket)>, mpsc::Receiver, Client) { + crypto_init().unwrap(); let relay_addr = "127.0.0.1:12345".parse().unwrap(); let (relay_pk, _relay_sk) = gen_keypair(); let (incoming_tx, incoming_rx) = mpsc::unbounded(); @@ -1140,6 +1141,7 @@ pub mod tests { .map_err(|(e, _)| e) } + crypto_init().unwrap(); // run server let (server_pk, server_sk) = gen_keypair(); diff --git a/src/toxcore/tcp/client/connections.rs b/src/toxcore/tcp/client/connections.rs index 89d88aed2..78fbe550a 100644 --- a/src/toxcore/tcp/client/connections.rs +++ b/src/toxcore/tcp/client/connections.rs @@ -393,6 +393,7 @@ mod tests { #[test] fn add_relay_global() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (incoming_tx, _incoming_rx) = mpsc::unbounded(); let connections = Connections::new(dht_pk, dht_sk, incoming_tx); @@ -409,6 +410,7 @@ mod tests { #[test] fn add_relay_global_exists() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (incoming_tx, _incoming_rx) = mpsc::unbounded(); let connections = Connections::new(dht_pk, dht_sk, incoming_tx); @@ -425,6 +427,7 @@ mod tests { #[test] fn add_relay_connection() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (incoming_tx, _incoming_rx) = mpsc::unbounded(); let connections = Connections::new(dht_pk, dht_sk, incoming_tx); @@ -450,6 +453,7 @@ mod tests { #[test] fn add_relay_connection_relay_exists() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (incoming_tx, _incoming_rx) = mpsc::unbounded(); let connections = Connections::new(dht_pk, dht_sk, incoming_tx); @@ -478,6 +482,7 @@ mod tests { #[test] fn add_connection() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (incoming_tx, _incoming_rx) = mpsc::unbounded(); let connections = Connections::new(dht_pk, dht_sk, incoming_tx); @@ -505,6 +510,7 @@ mod tests { #[test] fn add_connection_no_relay() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (incoming_tx, _incoming_rx) = mpsc::unbounded(); let connections = Connections::new(dht_pk, dht_sk, incoming_tx); @@ -517,6 +523,7 @@ mod tests { #[test] fn remove_connection() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (incoming_tx, _incoming_rx) = mpsc::unbounded(); let connections = Connections::new(dht_pk, dht_sk, incoming_tx); @@ -546,6 +553,7 @@ mod tests { #[test] fn remove_connection_no_connection() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (incoming_tx, _incoming_rx) = mpsc::unbounded(); let connections = Connections::new(dht_pk, dht_sk, incoming_tx); @@ -557,6 +565,7 @@ mod tests { #[test] fn send_data() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (incoming_tx, _incoming_rx) = mpsc::unbounded(); let connections = Connections::new(dht_pk, dht_sk, incoming_tx); @@ -616,6 +625,7 @@ mod tests { #[test] fn send_data_no_connection() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (incoming_tx, _incoming_rx) = mpsc::unbounded(); let connections = Connections::new(dht_pk, dht_sk, incoming_tx); @@ -627,6 +637,7 @@ mod tests { #[test] fn send_oob() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (incoming_tx, _incoming_rx) = mpsc::unbounded(); let connections = Connections::new(dht_pk, dht_sk, incoming_tx); @@ -649,6 +660,7 @@ mod tests { #[test] fn send_oob_no_relay() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (incoming_tx, _incoming_rx) = mpsc::unbounded(); let connections = Connections::new(dht_pk, dht_sk, incoming_tx); @@ -661,6 +673,7 @@ mod tests { #[test] fn send_onion() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (incoming_tx, _incoming_rx) = mpsc::unbounded(); let connections = Connections::new(dht_pk, dht_sk, incoming_tx); @@ -690,6 +703,7 @@ mod tests { #[test] fn send_onion_no_relay() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (incoming_tx, _incoming_rx) = mpsc::unbounded(); let connections = Connections::new(dht_pk, dht_sk, incoming_tx); @@ -712,6 +726,7 @@ mod tests { #[test] fn set_connection_status() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (incoming_tx, _incoming_rx) = mpsc::unbounded(); let connections = Connections::new(dht_pk, dht_sk, incoming_tx); @@ -730,6 +745,7 @@ mod tests { #[test] fn set_connection_status_no_connection() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (incoming_tx, _incoming_rx) = mpsc::unbounded(); let connections = Connections::new(dht_pk, dht_sk, incoming_tx); @@ -780,6 +796,7 @@ mod tests { #[test] fn main_loop_put_to_sleep() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (incoming_tx, _incoming_rx) = mpsc::unbounded(); let connections = Connections::new(dht_pk, dht_sk, incoming_tx); @@ -822,6 +839,7 @@ mod tests { #[test] fn main_loop_remove_unsuccessful() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (incoming_tx, _incoming_rx) = mpsc::unbounded(); let connections = Connections::new(dht_pk, dht_sk, incoming_tx); @@ -869,6 +887,7 @@ mod tests { #[test] fn main_loop_remove_not_used() { + crypto_init().unwrap(); let (dht_pk, dht_sk) = gen_keypair(); let (incoming_tx, _incoming_rx) = mpsc::unbounded(); let connections = Connections::new(dht_pk, dht_sk, incoming_tx); diff --git a/src/toxcore/tcp/codec.rs b/src/toxcore/tcp/codec.rs index 8a9477356..0e3364b65 100644 --- a/src/toxcore/tcp/codec.rs +++ b/src/toxcore/tcp/codec.rs @@ -253,6 +253,7 @@ mod tests { #[test] fn encode_decode() { + crypto_init().unwrap(); let (pk, _) = gen_keypair(); let (alice_channel, bob_channel) = create_channels(); let mut buf = BytesMut::new(); @@ -317,6 +318,7 @@ mod tests { } #[test] fn decode_encrypted_packet_incomplete() { + crypto_init().unwrap(); let (alice_channel, _) = create_channels(); let mut buf = BytesMut::new(); buf.extend_from_slice(b"\x00"); @@ -328,6 +330,7 @@ mod tests { } #[test] fn decode_encrypted_packet_zero_length() { + crypto_init().unwrap(); let (alice_channel, _) = create_channels(); let mut buf = BytesMut::new(); buf.extend_from_slice(b"\x00\x00"); @@ -339,6 +342,7 @@ mod tests { } #[test] fn decode_encrypted_packet_wrong_key() { + crypto_init().unwrap(); let (alice_channel, _) = create_channels(); let (mallory_channel, _) = create_channels(); @@ -355,6 +359,7 @@ mod tests { } #[test] fn decode_packet_imcomplete() { + crypto_init().unwrap(); let (alice_channel, _) = create_channels(); let mut buf = BytesMut::new(); @@ -366,6 +371,7 @@ mod tests { } #[test] fn decode_packet_error() { + crypto_init().unwrap(); let alice_session = Session::random(); // assume we got Alice's PK via handshake @@ -397,6 +403,7 @@ mod tests { #[test] fn encode_packet_too_big() { + crypto_init().unwrap(); let (alice_channel, _) = create_channels(); let mut buf = BytesMut::new(); let stats = Stats::new(); diff --git a/src/toxcore/tcp/handshake/codec.rs b/src/toxcore/tcp/handshake/codec.rs index 4de565208..64f040eb0 100644 --- a/src/toxcore/tcp/handshake/codec.rs +++ b/src/toxcore/tcp/handshake/codec.rs @@ -95,6 +95,7 @@ mod tests { #[test] fn client_encode_decode() { + crypto_init().unwrap(); let (pk, _) = gen_keypair(); let nonce = gen_nonce(); let mut buf = BytesMut::new(); @@ -106,12 +107,14 @@ mod tests { } #[test] fn client_decode_incomplete() { + crypto_init().unwrap(); let mut buf = BytesMut::new(); let mut codec = ClientHandshakeCodec { }; assert!(codec.decode(&mut buf).unwrap().is_none()); } #[test] fn client_encode_too_big() { + crypto_init().unwrap(); let nonce = gen_nonce(); let (pk, _) = gen_keypair(); let handshake = ClientHandshake { pk, nonce, payload: vec![42; ENC_PAYLOAD_SIZE + 1] }; @@ -121,6 +124,7 @@ mod tests { } #[test] fn server_encode_decode() { + crypto_init().unwrap(); let nonce = gen_nonce(); let mut buf = BytesMut::new(); let mut codec = ServerHandshakeCodec { }; @@ -131,12 +135,14 @@ mod tests { } #[test] fn server_decode_incomplete() { + crypto_init().unwrap(); let mut buf = BytesMut::new(); let mut codec = ServerHandshakeCodec { }; assert!(codec.decode(&mut buf).unwrap().is_none()); } #[test] fn server_encode_too_big() { + crypto_init().unwrap(); let nonce = gen_nonce(); let mut buf = BytesMut::new(); let mut codec = ServerHandshakeCodec { }; diff --git a/src/toxcore/tcp/handshake/mod.rs b/src/toxcore/tcp/handshake/mod.rs index cd641f8c3..21ce4dc58 100644 --- a/src/toxcore/tcp/handshake/mod.rs +++ b/src/toxcore/tcp/handshake/mod.rs @@ -192,6 +192,7 @@ mod tests { use crate::toxcore::tcp::handshake::*; fn create_channels_with_handshake() -> (secure::Channel, secure::Channel) { + crypto_init().unwrap(); let (client_pk, client_sk) = gen_keypair(); let (server_pk, server_sk) = gen_keypair(); @@ -241,6 +242,7 @@ mod tests { } #[test] fn client_handshake_with_different_keypair() { + crypto_init().unwrap(); let (client_pk, client_sk) = gen_keypair(); let (server_pk, _) = gen_keypair(); let (_, mallory_sk) = gen_keypair(); @@ -250,6 +252,7 @@ mod tests { } #[test] fn server_handshake_with_different_keypair() { + crypto_init().unwrap(); let (client_pk, client_sk) = gen_keypair(); let (server_pk, server_sk) = gen_keypair(); let (_, mallory_sk) = gen_keypair(); @@ -261,6 +264,7 @@ mod tests { } #[test] fn client_handshake_with_bad_payload() { + crypto_init().unwrap(); let (client_pk, client_sk) = gen_keypair(); let (server_pk, server_sk) = gen_keypair(); fn create_bad_client_handshake(client_pk: &PublicKey, @@ -282,6 +286,7 @@ mod tests { #[test] fn server_handshake_with_bad_payload() { use self::secure::*; + crypto_init().unwrap(); let (client_pk, _) = gen_keypair(); let (_, server_sk) = gen_keypair(); let common_key = encrypt_precompute(&client_pk, &server_sk); @@ -307,6 +312,7 @@ mod tests { use tokio; use tokio::net::{TcpListener, TcpStream}; + crypto_init().unwrap(); let (client_pk, client_sk) = gen_keypair(); let (server_pk, server_sk) = gen_keypair(); diff --git a/src/toxcore/tcp/links.rs b/src/toxcore/tcp/links.rs index 5a7859729..67f46f4ea 100644 --- a/src/toxcore/tcp/links.rs +++ b/src/toxcore/tcp/links.rs @@ -174,6 +174,7 @@ mod tests { #[test] fn link_new() { + crypto_init().unwrap(); let (pk, _) = gen_keypair(); let link = Link::new(pk); assert_eq!(LinkStatus::Registered, link.status); @@ -182,6 +183,7 @@ mod tests { #[test] fn link_upgrade() { + crypto_init().unwrap(); let (pk, _) = gen_keypair(); let mut link = Link::new(pk); link.upgrade(); @@ -190,6 +192,7 @@ mod tests { #[test] fn link_downgrade() { + crypto_init().unwrap(); let (pk, _) = gen_keypair(); let mut link = Link::new(pk); link.upgrade(); @@ -213,6 +216,7 @@ mod tests { #[test] fn links_insert_240() { + crypto_init().unwrap(); let mut links = Links::new(); for _ in 0..240 { // The first 240 must be inserted successfully @@ -227,6 +231,7 @@ mod tests { #[test] fn links_insert_same_pk() { + crypto_init().unwrap(); let mut links = Links::new(); let (pk, _) = gen_keypair(); @@ -239,6 +244,7 @@ mod tests { #[test] fn links_insert_alloc_order() { + crypto_init().unwrap(); let mut links = Links::new(); let (pk1, _) = gen_keypair(); @@ -264,6 +270,7 @@ mod tests { #[test] fn links_insert_by_id() { + crypto_init().unwrap(); let mut links = Links::new(); let (pk1, _) = gen_keypair(); @@ -281,6 +288,7 @@ mod tests { #[test] fn links_by_id() { + crypto_init().unwrap(); let mut links = Links::new(); let (pk, _) = gen_keypair(); @@ -291,6 +299,7 @@ mod tests { #[test] fn links_by_id_nonexistent() { + crypto_init().unwrap(); let links = Links::new(); assert!(links.by_id(MAX_LINKS_N as u8 + 1).is_none()); @@ -298,6 +307,7 @@ mod tests { #[test] fn links_by_pk() { + crypto_init().unwrap(); let mut links = Links::new(); let (pk, _) = gen_keypair(); @@ -308,6 +318,7 @@ mod tests { #[test] fn links_upgrade() { + crypto_init().unwrap(); let mut links = Links::new(); let (pk, _) = gen_keypair(); @@ -324,6 +335,7 @@ mod tests { #[test] fn links_downgrade() { + crypto_init().unwrap(); let mut links = Links::new(); let (pk, _) = gen_keypair(); @@ -341,6 +353,7 @@ mod tests { #[test] fn links_take() { + crypto_init().unwrap(); let mut links = Links::new(); let (pk, _) = gen_keypair(); @@ -356,6 +369,7 @@ mod tests { #[test] fn links_take_nonexistent() { + crypto_init().unwrap(); let mut links = Links::new(); assert!(links.take(MAX_LINKS_N as u8 + 1).is_none()); @@ -363,6 +377,7 @@ mod tests { #[test] fn links_clear() { + crypto_init().unwrap(); let mut links = Links::new(); for _ in 0..240 { // The first 240 must be inserted successfully diff --git a/src/toxcore/tcp/packet/onion_response.rs b/src/toxcore/tcp/packet/onion_response.rs index fb4778a7e..f284b619f 100644 --- a/src/toxcore/tcp/packet/onion_response.rs +++ b/src/toxcore/tcp/packet/onion_response.rs @@ -44,7 +44,6 @@ mod test { use super::*; use crate::toxcore::onion::packet::{OnionAnnounceResponse, OnionDataResponse}; - use crate::toxcore::crypto_core::*; encode_decode_test!( onion_response_with_announce_encode_decode, diff --git a/src/toxcore/tcp/secure.rs b/src/toxcore/tcp/secure.rs index 8339e54ab..1b8a7c616 100644 --- a/src/toxcore/tcp/secure.rs +++ b/src/toxcore/tcp/secure.rs @@ -140,6 +140,7 @@ mod tests { use crate::toxcore::tcp::secure::*; fn create_channels() -> (Channel, Channel) { + crypto_init().unwrap(); let alice_session = Session::random(); let bob_session = Session::random(); @@ -159,6 +160,7 @@ mod tests { } #[test] fn test_secure_communication() { + crypto_init().unwrap(); let (alice_channel, bob_channel) = create_channels(); // And now they may communicate sending encrypted data to each other diff --git a/src/toxcore/tcp/server/server.rs b/src/toxcore/tcp/server/server.rs index 5b04dd7c0..9a0d2cfd5 100644 --- a/src/toxcore/tcp/server/server.rs +++ b/src/toxcore/tcp/server/server.rs @@ -533,6 +533,7 @@ mod tests { #[test] fn server_is_clonable() { + crypto_init().unwrap(); let server = Server::new(); let (client_1, _rx_1) = create_random_client("1.2.3.4:12345".parse().unwrap()); server.insert(client_1).wait().unwrap(); @@ -543,6 +544,7 @@ mod tests { /// A function that generates random keypair, random `std::net::IpAddr`, /// random port, creates mpsc channel and returns created with them Client fn create_random_client(saddr: SocketAddr) -> (Client, mpsc::Receiver) { + crypto_init().unwrap(); let (client_pk, _) = gen_keypair(); let (tx, rx) = mpsc::channel(32); let client = Client::new(tx, &client_pk, saddr.ip(), saddr.port()); @@ -917,6 +919,7 @@ mod tests { } #[test] fn handle_disconnect_notification_0() { + crypto_init().unwrap(); let server = Server::new(); let (client_pk, _) = gen_keypair(); @@ -970,6 +973,7 @@ mod tests { } #[test] fn handle_onion_request() { + crypto_init().unwrap(); let (udp_onion_sink, udp_onion_stream) = mpsc::channel(1); let mut server = Server::new(); server.set_udp_onion_sink(udp_onion_sink); @@ -1122,6 +1126,7 @@ mod tests { } #[test] fn handle_data_0() { + crypto_init().unwrap(); let server = Server::new(); let (client_pk, _) = gen_keypair(); @@ -1311,6 +1316,7 @@ mod tests { } #[test] fn handle_udp_onion_response_for_unknown_client() { + crypto_init().unwrap(); let (udp_onion_sink, _) = mpsc::channel(1); let mut server = Server::new(); server.set_udp_onion_sink(udp_onion_sink); @@ -1340,6 +1346,7 @@ mod tests { // Here be all handle_* tests from PK or to PK not in connected clients list #[test] fn handle_route_request_not_connected() { + crypto_init().unwrap(); let server = Server::new(); let (client_pk_1, _) = gen_keypair(); let (client_pk_2, _) = gen_keypair(); @@ -1352,6 +1359,7 @@ mod tests { } #[test] fn handle_disconnect_notification_not_connected() { + crypto_init().unwrap(); let server = Server::new(); let (client_pk_1, _) = gen_keypair(); @@ -1384,6 +1392,7 @@ mod tests { } #[test] fn handle_ping_request_not_connected() { + crypto_init().unwrap(); let server = Server::new(); let (client_pk_1, _) = gen_keypair(); @@ -1395,6 +1404,7 @@ mod tests { } #[test] fn handle_pong_response_not_connected() { + crypto_init().unwrap(); let server = Server::new(); let (client_pk_1, _) = gen_keypair(); @@ -1406,6 +1416,7 @@ mod tests { } #[test] fn handle_oob_send_not_connected() { + crypto_init().unwrap(); let server = Server::new(); let (client_pk_1, _) = gen_keypair(); let (client_pk_2, _) = gen_keypair(); @@ -1418,6 +1429,7 @@ mod tests { } #[test] fn handle_data_not_connected() { + crypto_init().unwrap(); let server = Server::new(); let (client_pk_1, _) = gen_keypair(); @@ -1472,6 +1484,7 @@ mod tests { } #[test] fn shutdown_not_connected() { + crypto_init().unwrap(); let server = Server::new(); let (client_pk, _) = gen_keypair(); let client_ip_addr = "1.2.3.4".parse().unwrap(); @@ -1483,6 +1496,7 @@ mod tests { } #[test] fn shutdown_inner_not_connected() { + crypto_init().unwrap(); let server = Server::new(); let (client_pk, _) = gen_keypair(); @@ -1541,6 +1555,7 @@ mod tests { } #[test] fn send_onion_request_to_dropped_stream() { + crypto_init().unwrap(); let (udp_onion_sink, udp_onion_stream) = mpsc::channel(1); let mut server = Server::new(); server.set_udp_onion_sink(udp_onion_sink); diff --git a/src/toxcore/tcp/server/server_ext.rs b/src/toxcore/tcp/server/server_ext.rs index 5a18c92c8..ac666e1da 100644 --- a/src/toxcore/tcp/server/server_ext.rs +++ b/src/toxcore/tcp/server/server_ext.rs @@ -287,6 +287,7 @@ mod tests { #[test] fn run_connection() { + crypto_init().unwrap(); let (client_pk, client_sk) = gen_keypair(); let (server_pk, server_sk) = gen_keypair(); @@ -345,6 +346,7 @@ mod tests { #[test] fn run() { + crypto_init().unwrap(); let (client_pk, client_sk) = gen_keypair(); let (server_pk, server_sk) = gen_keypair(); diff --git a/src/toxcore/toxid.rs b/src/toxcore/toxid.rs index 18588abbe..6a2bdadc1 100644 --- a/src/toxcore/toxid.rs +++ b/src/toxcore/toxid.rs @@ -323,6 +323,7 @@ mod tests { #[test] fn no_spam_new_test() { + crypto_init().unwrap(); let ns = NoSpam::random(); // shouldn't be empty, unless your PRNG is crappy assert_ne!(ns.0, [0; NOSPAMBYTES]) @@ -332,6 +333,7 @@ mod tests { #[test] fn no_spam_fmt() { + crypto_init().unwrap(); // check if formatted NoSpam is always upper-case hexadecimal with matching // length let nospam = NoSpam::random(); @@ -357,6 +359,7 @@ mod tests { #[test] fn tox_id_new_nospam() { + crypto_init().unwrap(); let (pk, _) = gen_keypair(); let toxid = ToxId::new(pk); let mut toxid2 = toxid; @@ -378,6 +381,7 @@ mod tests { #[test] fn tox_id_fmt() { + crypto_init().unwrap(); // check if formatted ToxId is always upper-case hexadecimal with matching // length let (pk, _) = gen_keypair(); diff --git a/src/toxencryptsave_tests/encryptsave_tests.rs b/src/toxencryptsave_tests/encryptsave_tests.rs index 22e8c5cba..4b6fb936f 100644 --- a/src/toxencryptsave_tests/encryptsave_tests.rs +++ b/src/toxencryptsave_tests/encryptsave_tests.rs @@ -1,9 +1,12 @@ use crate::toxencryptsave::*; +use crate::toxcore::crypto_core::*; + // is_encrypted() #[test] fn is_encrypted_test() { + crypto_init().unwrap(); assert!(!is_encrypted(b"Hello world.\n"));; assert!(is_encrypted(MAGIC_NUMBER)); assert!(is_encrypted(include_bytes!("ciphertext"))); @@ -14,6 +17,7 @@ fn is_encrypted_test() { #[test] fn pass_encrypt_error_test() { + crypto_init().unwrap(); // empty data assert_eq!(pass_encrypt(&[], &[0]), Err(EncryptionError::Null)); @@ -23,6 +27,7 @@ fn pass_encrypt_error_test() { #[test] fn pass_encrypt_test() { + crypto_init().unwrap(); let plaintext = [42; 16]; let passphrase = [53; 16]; @@ -41,18 +46,21 @@ fn pass_encrypt_test() { #[test] fn pass_decrypt_error_null_test() { + crypto_init().unwrap(); // empty data assert_eq!(pass_decrypt(&[], &[0]), Err(DecryptionError::Null)); } #[test] fn pass_decrypt_error_invalid_length_test() { + crypto_init().unwrap(); // not enough data assert_eq!(pass_decrypt(&[0], &[]), Err(DecryptionError::InvalidLength)); } #[test] fn pass_decrypt_error_key_derivation_test() { + crypto_init().unwrap(); // empty passphrase let ciphertext = include_bytes!("ciphertext"); assert_eq!(pass_decrypt(ciphertext, &[]), Err(KeyDerivationError::Null.into())); @@ -60,6 +68,7 @@ fn pass_decrypt_error_key_derivation_test() { #[test] fn pass_decrypt_error_bad_format_test() { + crypto_init().unwrap(); // one of `MAGIC_NUMBER` bytes is wrong let ciphertext = include_bytes!("ciphertext"); let mut bad_ciphertext = Vec::with_capacity(MAGIC_LENGTH + SALT_LENGTH); @@ -70,6 +79,7 @@ fn pass_decrypt_error_bad_format_test() { #[test] fn pass_decrypt_error_failed_test() { + crypto_init().unwrap(); // a data byte is wrong let ciphertext = include_bytes!("ciphertext"); let mut bad_ciphertext = Vec::with_capacity(EXTRA_LENGTH + 123); @@ -80,6 +90,7 @@ fn pass_decrypt_error_failed_test() { #[test] fn pass_decrypt_test() { + crypto_init().unwrap(); let passphrase = b"encryptsave"; let plaintext = b"Hello world.\n"; let ciphertext = include_bytes!("ciphertext"); @@ -92,6 +103,7 @@ fn pass_decrypt_test() { #[test] fn get_salt_test() { + crypto_init().unwrap(); let ciphertext = include_bytes!("ciphertext"); let salt = &ciphertext[MAGIC_LENGTH .. MAGIC_LENGTH + SALT_LENGTH]; @@ -100,6 +112,7 @@ fn get_salt_test() { #[test] fn get_salt_wrong_magic_test() { + crypto_init().unwrap(); let ciphertext = include_bytes!("ciphertext"); let mut bad_ciphertext = Vec::with_capacity(MAGIC_LENGTH + SALT_LENGTH);