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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! All crypto-related code.

mod signing;
mod masking;
mod sharing;
mod encryption;

use sda_protocol::*;
use errors::SdaClientResult;

use std::sync::Arc;

pub use self::signing::{
    SignatureKeypair, 
    SignExport, 
    SignatureVerification};
    
pub use self::masking::{
    SecretMaskerConstruction,
    MaskCombinerConstruction,
    SecretUnmaskerConstruction};
    
pub use self::sharing::{
    ShareGeneratorConstruction,
    ShareCombinerConstruction,
    SecretReconstructorConstruction};
    
pub use self::encryption::{
    EncryptionKeypair, 
    EncryptorConstruction, 
    DecryptorConstruction};

pub type Secret = i64;
pub type Mask = i64;
pub type MaskedSecret = i64;
pub type Share = i64;

pub trait KeyGeneration<K> {
    fn new_key(&self) -> SdaClientResult<K>;
}

/// Trait for accessing keys stored in keystore.
pub trait KeyStorage<ID, K> {
    fn put(&self, id: &ID, key: &K) -> SdaClientResult<()>;
    fn get(&self, id: &ID) -> SdaClientResult<Option<K>>;
}

/// Requirements for any keystore used by the client.
pub trait Keystore :
    KeyStorage<EncryptionKeyId, EncryptionKeypair>
    + KeyStorage<VerificationKeyId, SignatureKeypair>
{}

pub trait Suitable<S> {
    fn suitable_for(&self, scheme: &S) -> bool;
}

pub struct CryptoModule {
    keystore: Arc<Keystore>
}

impl CryptoModule {
    pub fn new(keystore: Arc<Keystore>) -> CryptoModule {
        CryptoModule { keystore: keystore }
    }
}