1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//! Sarkara is a Post-Quantum cryptography library.

#![feature(non_exhaustive)]

#[macro_use] extern crate arrayref;
#[macro_use] extern crate failure;
extern crate rand;
extern crate seckey;
extern crate dilithium;
extern crate kyber;
extern crate norx;
extern crate norx_permutation;
extern crate mem_aead_mrs;

#[cfg(feature = "serde")]
extern crate serde;

#[macro_use] mod common;
pub mod sign;
pub mod kex;
pub mod aead;
pub mod sealedbox;


pub trait Packing: Sized {
    const BYTES_LENGTH: usize;

    fn read_bytes<T, F>(&self, f: F)
        -> T
        where F: FnOnce(&[u8]) -> T;

    /// TODO should be `from_bytes(buf: &[u8; Self::LENGTH]) -> Self`
    fn from_bytes(buf: &[u8]) -> Self;
}


#[derive(Debug, Fail)]
#[non_exhaustive]
#[must_use]
pub enum Error {
    #[fail(display = "Input/Output length does not match")]
    Length,

    #[fail(display = "Fail to pass verification")]
    VerificationFailed,
}