//! Test all sorts of formats for serialisation
//!
//! Because `keybob` implements a custom serde serialize/ deserialize
//! we want to make sure that it actually produces good output for
//! different data formats.

extern crate keybob;
extern crate serde;
use keybob::{Key, KeyType};

#[test]
fn json() {
    extern crate serde_json;
    let k = Key::new(KeyType::Aes128);

    let ser = serde_json::to_string(&k).unwrap();
    let de: Key = serde_json::from_str(&ser).unwrap();

    assert_eq!(k, de);
}

#[test]
fn toml() {
    extern crate toml;
    let k = Key::new(KeyType::Aes128);

    let ser = toml::to_string(&k).unwrap();
    let de: Key = toml::from_str(&ser).unwrap();

    assert_eq!(k, de);
}

#[test]
fn messagepack() {
    extern crate rmp_serde as rmps;
    let k = Key::new(KeyType::Aes128);

    let ser = rmps::to_vec(&k).unwrap();
    let de: Key = rmps::from_slice(ser.as_slice()).unwrap();

    assert_eq!(k, de);
}

#[test]
fn bincode() {
    extern crate bincode;

    let k = Key::new(KeyType::Aes128);

    let ser = bincode::serialize(&k).unwrap();
    let de: Key = bincode::deserialize(ser.as_slice()).unwrap();

    assert_eq!(k, de);
}

#[test]
fn cbor() {
    extern crate serde_cbor;

    let k = Key::new(KeyType::Aes128);

    let ser = serde_cbor::to_vec(&k).unwrap();
    let de = serde_cbor::from_slice(ser.as_slice()).unwrap();

    assert_eq!(k, de);
}
