sodium_sys/
lib.rs

1//! [Sodium](https://github.com/jedisct1/libsodium) is a modern, easy-to-use
2//! software library for encryption, decryption, signatures, password hashing
3//! and more.
4//!
5//! It is a portable, cross-compilable, installable, packageable fork of
6//! [NaCl](http://nacl.cr.yp.to), with a compatible API, and an extended API to
7//! improve usability even further.
8//!
9//! Its goal is to provide all of the core operations needed to build
10//! higher-level cryptographic tools.
11//!
12//! Sodium supports a variety of compilers and operating systems, including
13//! Windows (with MinGW or Visual Studio, x86 and x64), iOS and Android.
14//!
15//! The design choices emphasize security, and "magic constants" have clear
16//! rationales.
17//!
18//! And despite the emphasis on high security, primitives are faster
19//! across-the-board than most implementations of the NIST standards.
20//!
21//! Version 1.0.3 was released on May 9, 2015.
22//! Building feature "latest" will build with version 1.0.4.
23//!
24//! [sodium-sys](https://github.com/rustyhorde/sodium-sys) is rust bindings for
25//! [Sodium](https://github.com/jedisct1/libsodium).
26#![allow(non_upper_case_globals)]
27extern crate libc;
28#[cfg(test)]
29extern crate regex;
30
31use std::ffi::NulError;
32use std::str;
33use std::string;
34
35/// Crypography library modules.
36pub mod crypto {
37    pub mod asymmetrickey;
38    pub mod hash;
39    pub mod symmetrickey;
40    pub mod utils;
41}
42
43pub use self::SSError::*;
44
45#[derive(Debug)]
46/// A sodium-sys error.  This is used to wrap various other errors to unify
47/// the Result returns from the library.
48pub enum SSError {
49    /// An error returned from ```CString::new``` to indicate that a nul byte
50    /// was found in the vector provided.
51    CSTR(NulError),
52    /// An error returned from functions that decrypt ciphertext.
53    DECRYPT(&'static str),
54    /// An error returned from functions that encrypt messages.
55    ENCRYPT(&'static str),
56    /// An error returned from functions that hash messages.
57    HASH(&'static str),
58    /// An error returned from functions the generate keypairs.
59    KEYGEN(&'static str),
60    /// An error returned from functions that generate MACs.
61    MAC(&'static str),
62    /// An error returned from signing functions.
63    SIGN(&'static str),
64    /// Errors which can occur when attempting to interpret a byte slice as a
65    /// str.
66    STR(str::Utf8Error),
67    /// A possible error value from the String::from_utf8 function.
68    STRING(string::FromUtf8Error),
69    /// A possible error when verfiying a signed message.
70    VERIFYSIGNED(&'static str),
71}
72
73impl From<NulError> for SSError {
74    fn from(err: NulError) -> SSError {
75        CSTR(err)
76    }
77}
78
79impl From<str::Utf8Error> for SSError {
80    fn from(err: str::Utf8Error) -> SSError {
81        STR(err)
82    }
83}
84
85impl From<string::FromUtf8Error> for SSError {
86    fn from(err: string::FromUtf8Error) -> SSError {
87        STRING(err)
88    }
89}