aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
blob: 4342a7464430801dc4d17be0b84c45aac238fcf7 (plain)
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

extern crate rand;
extern crate curve25519_dalek;
extern crate sha2;

mod spake2;
pub use spake2::*;

#[cfg(test)]
extern crate num_bigint;
#[cfg(test)]
extern crate hex;

#[cfg(test)]
mod tests {
    use spake2::{SPAKE2, Ed25519Group};

    #[test]
    fn test_basic() {
        let (s1, msg1) = SPAKE2::<Ed25519Group>::start_a(b"password",
                                                         b"idA", b"idB");
        let (s2, msg2) = SPAKE2::<Ed25519Group>::start_b(b"password",
                                                         b"idA", b"idB");
        let key1 = s1.finish(msg2.as_slice()).unwrap();
        let key2 = s2.finish(msg1.as_slice()).unwrap();
        assert_eq!(key1, key2);
    }

    #[test]
    fn test_basic_symmetric() {
        let (s1, msg1) = SPAKE2::<Ed25519Group>::start_symmetric(b"password",
                                                                 b"idS");
        let (s2, msg2) = SPAKE2::<Ed25519Group>::start_symmetric(b"password",
                                                                 b"idS");
        let key1 = s1.finish(msg2.as_slice()).unwrap();
        let key2 = s2.finish(msg1.as_slice()).unwrap();
        assert_eq!(key1, key2);
    }


    #[test]
    fn it_works() {
    }

    #[test]
    #[should_panic(expected = "nope")]
    fn it_panics() {
        assert!(false, "nope");
    }
}