Add panic when libsodium initialization failed
The new function wraps initialization of libsodium, but it don't return the result.
@@ -4,6 +4,7 @@ use sodiumoxide::crypto::sign::ed25519::{PublicKey as PublicKeySodium,
verify_detached, gen_keypair as gen_keypair_sodium,
keypair_from_seed};
use sodiumoxide::crypto::hash::sha256::{Digest, hash as hash_sodium};
+use sodiumoxide;
use serde::{Serialize, Serializer};
use serde::de::{self, Visitor, Deserialize, Deserializer};
use hex::{ToHex, FromHex};
@@ -14,7 +15,6 @@ use std::fmt;
use storage::bytes_to_hex;
-pub use sodiumoxide::init;
pub use sodiumoxide::crypto::sign::ed25519::{PUBLICKEYBYTES as PUBLIC_KEY_LENGTH,
SECRETKEYBYTES as SECRET_KEY_LENGTH,
SIGNATUREBYTES as SIGNATURE_LENGTH,
@@ -50,6 +50,12 @@ pub fn hash(m: &[u8]) -> Hash {
Hash(dig)
}
+pub fn init() {
+ if !sodiumoxide::init() {
+ panic!("Cryptographic library hasn't initialized.");
+ }
+}
+
macro_rules! implement_public_sodium_wrapper {
($name:ident, $name_from:ident, $size:expr) => (
#[derive(PartialEq, Eq, Clone, Copy, PartialOrd, Ord, Hash)]
