Skip to content
This repository has been archived by the owner on Jan 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #77 from mmoadeli/MAID-1145
Browse files Browse the repository at this point in the history
upgrade sodiumoxide version to
  • Loading branch information
dirvine committed Jun 23, 2015
2 parents 01e7a35 + 8073d25 commit c48255f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -12,6 +12,6 @@ homepage = "http://www.maidsafe.net"
[dependencies]
rustc-serialize = "*"
cbor = "*"
sodiumoxide = "0.0.4"
sodiumoxide = "0.0.5"
rand = "*"
routing="*"
4 changes: 1 addition & 3 deletions src/coin/safecoin.rs
Expand Up @@ -123,7 +123,6 @@ mod test {
use routing::NameType;
use routing::types::{vector_as_u8_64_array, generate_random_vec_u8};
use routing::types::Signature;
use sodiumoxide::crypto::sign;
use routing::sendable::Sendable;
use Random;

Expand All @@ -135,7 +134,7 @@ mod test {
let mut previous_owners = Vec::<NameType>::new();
previous_owners.push(NameType::new(vector_as_u8_64_array(generate_random_vec_u8(64))));
let mut signatures = Vec::<Signature>::new();
signatures.push(Signature::new(sign::Signature(vector_as_u8_64_array(generate_random_vec_u8(64)))));
signatures.push(Signature { signature: generate_random_vec_u8(64)});

SafeCoin {
type_tag: SafeCoinTypeTag,
Expand All @@ -154,4 +153,3 @@ mod test {
assert_eq!(safecoin.type_tag(), 256u64);
}
}

2 changes: 1 addition & 1 deletion src/helper.rs
Expand Up @@ -55,7 +55,7 @@ macro_rules! convert_to_array {
///
/// Return NameType using Public signing & encryption keys
///
pub fn name(public_keys: &(crypto::sign::PublicKey, crypto::asymmetricbox::PublicKey), type_tag: u64,
pub fn name(public_keys: &(crypto::sign::PublicKey, crypto::box_::PublicKey), type_tag: u64,
signature: &crypto::sign::Signature) -> NameType {
let combined_iter = (public_keys.0).0.into_iter().chain((public_keys.1).0.into_iter());
let mut combined: Vec<u8> = Vec::new();
Expand Down
42 changes: 21 additions & 21 deletions src/id/id_type.rs
Expand Up @@ -35,14 +35,14 @@ use routing::NameType;
#[derive(Clone)]
pub struct IdType {
type_tag: u64,
public_keys: (crypto::sign::PublicKey, crypto::asymmetricbox::PublicKey),
secret_keys: (crypto::sign::SecretKey, crypto::asymmetricbox::SecretKey)
public_keys: (crypto::sign::PublicKey, crypto::box_::PublicKey),
secret_keys: (crypto::sign::SecretKey, crypto::box_::SecretKey)
}

impl IdType {
/// Invoked to create an instance of IdType
pub fn new(revocation_id: &RevocationIdType) -> IdType {
let asym_keys = crypto::asymmetricbox::gen_keypair();
let asym_keys = crypto::box_::gen_keypair();
let signing_keys = crypto::sign::gen_keypair();

IdType {
Expand All @@ -64,30 +64,30 @@ impl IdType {
NameType(crypto::hash::sha512::hash(&combined).0)
}
/// Returns the PublicKeys
pub fn public_keys(&self) -> &(crypto::sign::PublicKey, crypto::asymmetricbox::PublicKey){
pub fn public_keys(&self) -> &(crypto::sign::PublicKey, crypto::box_::PublicKey){
&self.public_keys
}
/// Returns the PublicKeys
pub fn secret_keys(&self) -> &(crypto::sign::SecretKey, crypto::asymmetricbox::SecretKey) {
pub fn secret_keys(&self) -> &(crypto::sign::SecretKey, crypto::box_::SecretKey) {
&self.secret_keys
}
/// Signs the data with the SecretKey and returns the Signed data
pub fn sign(&self, data : &[u8]) -> Vec<u8> {
return crypto::sign::sign(&data, &self.secret_keys.0)
}
/// Encrypts and authenticates data. It returns a ciphertext and the Nonce.
pub fn seal(&self, data : &[u8], to : &crypto::asymmetricbox::PublicKey) -> (Vec<u8>, crypto::asymmetricbox::Nonce) {
let nonce = crypto::asymmetricbox::gen_nonce();
let sealed = crypto::asymmetricbox::seal(data, &nonce, &to, &self.secret_keys.1);
pub fn seal(&self, data : &[u8], to : &crypto::box_::PublicKey) -> (Vec<u8>, crypto::box_::Nonce) {
let nonce = crypto::box_::gen_nonce();
let sealed = crypto::box_::seal(data, &nonce, &to, &self.secret_keys.1);
return (sealed, nonce);
}
/// Verifies and decrypts the data
pub fn open(
&self,
data : &[u8],
nonce : &crypto::asymmetricbox::Nonce,
from : &crypto::asymmetricbox::PublicKey) -> Result<Vec<u8>, ::CryptoError> {
return crypto::asymmetricbox::open(&data, &nonce, &from, &self.secret_keys.1).ok_or(::CryptoError::Unknown);
nonce : &crypto::box_::Nonce,
from : &crypto::box_::PublicKey) -> Result<Vec<u8>, ::CryptoError> {
return crypto::box_::open(&data, &nonce, &from, &self.secret_keys.1).ok_or(::CryptoError::Unknown);
}
}

Expand All @@ -108,8 +108,8 @@ impl fmt::Debug for IdType {

impl Encodable for IdType {
fn encode<E: Encoder>(&self, e: &mut E)->Result<(), E::Error> {
let (crypto::sign::PublicKey(pub_sign_vec), crypto::asymmetricbox::PublicKey(pub_asym_vec)) = self.public_keys;
let (crypto::sign::SecretKey(sec_sign_vec), crypto::asymmetricbox::SecretKey(sec_asym_vec)) = self.secret_keys;
let (crypto::sign::PublicKey(pub_sign_vec), crypto::box_::PublicKey(pub_asym_vec)) = self.public_keys;
let (crypto::sign::SecretKey(sec_sign_vec), crypto::box_::SecretKey(sec_asym_vec)) = self.secret_keys;
let type_vec = self.type_tag.to_string().into_bytes();

CborTagEncode::new(5483_001, &(
Expand All @@ -126,9 +126,9 @@ impl Decodable for IdType {
try!(d.read_u64());
let (tag_type_vec, pub_sign_vec, pub_asym_vec, sec_sign_vec, sec_asym_vec) : (Vec<u8>, Vec<u8>, Vec<u8>, Vec<u8>, Vec<u8>) = try!(Decodable::decode(d));
let pub_sign_arr = convert_to_array!(pub_sign_vec, crypto::sign::PUBLICKEYBYTES);
let pub_asym_arr = convert_to_array!(pub_asym_vec, crypto::asymmetricbox::PUBLICKEYBYTES);
let pub_asym_arr = convert_to_array!(pub_asym_vec, crypto::box_::PUBLICKEYBYTES);
let sec_sign_arr = convert_to_array!(sec_sign_vec, crypto::sign::SECRETKEYBYTES);
let sec_asym_arr = convert_to_array!(sec_asym_vec, crypto::asymmetricbox::SECRETKEYBYTES);
let sec_asym_arr = convert_to_array!(sec_asym_vec, crypto::box_::SECRETKEYBYTES);

if pub_sign_arr.is_none() || pub_asym_arr.is_none() || sec_sign_arr.is_none() || sec_asym_arr.is_none() {
return Err(d.error("Bad IdType size"));
Expand All @@ -145,8 +145,8 @@ impl Decodable for IdType {
};

Ok(IdType{ type_tag: type_tag,
public_keys:(crypto::sign::PublicKey(pub_sign_arr.unwrap()), crypto::asymmetricbox::PublicKey(pub_asym_arr.unwrap())),
secret_keys: (crypto::sign::SecretKey(sec_sign_arr.unwrap()), crypto::asymmetricbox::SecretKey(sec_asym_arr.unwrap())) })
public_keys:(crypto::sign::PublicKey(pub_sign_arr.unwrap()), crypto::box_::PublicKey(pub_asym_arr.unwrap())),
secret_keys: (crypto::sign::SecretKey(sec_sign_arr.unwrap()), crypto::box_::SecretKey(sec_asym_arr.unwrap())) })
}
}

Expand Down Expand Up @@ -179,10 +179,10 @@ mod test {
let mut d = cbor::Decoder::from_bytes(e.as_bytes());
let obj_after: IdType = d.decode().next().unwrap().unwrap();

let &(crypto::sign::PublicKey(pub_sign_arr_before), crypto::asymmetricbox::PublicKey(pub_asym_arr_before)) = obj_before.public_keys();
let &(crypto::sign::PublicKey(pub_sign_arr_after), crypto::asymmetricbox::PublicKey(pub_asym_arr_after)) = obj_after.public_keys();
let &(crypto::sign::SecretKey(sec_sign_arr_before), crypto::asymmetricbox::SecretKey(sec_asym_arr_before)) = &obj_before.secret_keys;
let &(crypto::sign::SecretKey(sec_sign_arr_after), crypto::asymmetricbox::SecretKey(sec_asym_arr_after)) = &obj_after.secret_keys;
let &(crypto::sign::PublicKey(pub_sign_arr_before), crypto::box_::PublicKey(pub_asym_arr_before)) = obj_before.public_keys();
let &(crypto::sign::PublicKey(pub_sign_arr_after), crypto::box_::PublicKey(pub_asym_arr_after)) = obj_after.public_keys();
let &(crypto::sign::SecretKey(sec_sign_arr_before), crypto::box_::SecretKey(sec_asym_arr_before)) = &obj_before.secret_keys;
let &(crypto::sign::SecretKey(sec_sign_arr_after), crypto::box_::SecretKey(sec_asym_arr_after)) = &obj_after.secret_keys;

assert_eq!(pub_sign_arr_before, pub_sign_arr_after);
assert_eq!(pub_asym_arr_before, pub_asym_arr_after);
Expand Down
12 changes: 6 additions & 6 deletions src/id/public_id_type.rs
Expand Up @@ -41,7 +41,7 @@ use super::id_type::*;
#[derive(Clone)]
pub struct PublicIdType {
type_tag: u64,
public_keys: (crypto::sign::PublicKey, crypto::asymmetricbox::PublicKey),
public_keys: (crypto::sign::PublicKey, crypto::box_::PublicKey),
revocation_public_key: crypto::sign::PublicKey,
signature: crypto::sign::Signature
}
Expand Down Expand Up @@ -108,7 +108,7 @@ impl PublicIdType {
signature: crypto::sign::Signature(signature_arr.unwrap()) }
}
/// Returns the PublicKeys
pub fn public_keys(&self) -> &(crypto::sign::PublicKey, crypto::asymmetricbox::PublicKey) {
pub fn public_keys(&self) -> &(crypto::sign::PublicKey, crypto::box_::PublicKey) {
&self.public_keys
}
/// Returns revocation public key
Expand All @@ -123,7 +123,7 @@ impl PublicIdType {

impl Encodable for PublicIdType {
fn encode<E: Encoder>(&self, e: &mut E)->Result<(), E::Error> {
let (crypto::sign::PublicKey(ref pub_sign_vec), crypto::asymmetricbox::PublicKey(pub_asym_vec)) = self.public_keys;
let (crypto::sign::PublicKey(ref pub_sign_vec), crypto::box_::PublicKey(pub_asym_vec)) = self.public_keys;
let crypto::sign::PublicKey(ref revocation_public_key_vec) = self.revocation_public_key;
let crypto::sign::Signature(ref signature) = self.signature;
let type_vec = self.type_tag.to_string().into_bytes();
Expand All @@ -141,8 +141,8 @@ impl Decodable for PublicIdType {
try!(d.read_u64());
let (tag_type_vec, pub_sign_vec, pub_asym_vec, revocation_public_key_vec, signature_vec): (Vec<u8>, Vec<u8>, Vec<u8>, Vec<u8>, Vec<u8>) = try!(Decodable::decode(d));
let pub_sign_arr = convert_to_array!(pub_sign_vec, crypto::sign::PUBLICKEYBYTES);
let pub_asym_arr = convert_to_array!(pub_asym_vec, crypto::asymmetricbox::PUBLICKEYBYTES);
let revocation_public_key_arr = convert_to_array!(revocation_public_key_vec, crypto::asymmetricbox::PUBLICKEYBYTES);
let pub_asym_arr = convert_to_array!(pub_asym_vec, crypto::box_::PUBLICKEYBYTES);
let revocation_public_key_arr = convert_to_array!(revocation_public_key_vec, crypto::box_::PUBLICKEYBYTES);
let signature_arr = convert_to_array!(signature_vec, crypto::sign::SIGNATUREBYTES);

if pub_sign_arr.is_none() || pub_asym_arr.is_none() || revocation_public_key_arr.is_none()
Expand All @@ -161,7 +161,7 @@ impl Decodable for PublicIdType {
};

Ok(PublicIdType{ type_tag: type_tag,
public_keys: (crypto::sign::PublicKey(pub_sign_arr.unwrap()), crypto::asymmetricbox::PublicKey(pub_asym_arr.unwrap())),
public_keys: (crypto::sign::PublicKey(pub_sign_arr.unwrap()), crypto::box_::PublicKey(pub_asym_arr.unwrap())),
revocation_public_key: crypto::sign::PublicKey(revocation_public_key_arr.unwrap()),
signature: crypto::sign::Signature(signature_arr.unwrap())})
}
Expand Down

0 comments on commit c48255f

Please sign in to comment.