diff options
author | Katharina Fey <kookie@spacekookie.de> | 2018-05-09 00:26:05 +0200 |
---|---|---|
committer | Katharina Fey <kookie@spacekookie.de> | 2018-05-09 00:26:05 +0200 |
commit | 659eaa9ff296ae3e03362593ee756cbe6d1f42ed (patch) | |
tree | 9489e5d205fb4fc0975cd21e41357ad3c2f80af1 /lockchain-core/src/crypto/keys.rs | |
parent | 2d95fbfce49cbb3decbe819aefb9bae1491d1469 (diff) |
Bumping version on core and crypto
Diffstat (limited to '')
-rw-r--r-- | lockchain-core/src/crypto/keys.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lockchain-core/src/crypto/keys.rs b/lockchain-core/src/crypto/keys.rs index f132075..6211851 100644 --- a/lockchain-core/src/crypto/keys.rs +++ b/lockchain-core/src/crypto/keys.rs @@ -1,5 +1,6 @@ //! A module that handles key generation and key loading +use traits::AutoEncoder; use super::utils::{hashing, random}; /// A shared key length parameter for all cryptographic operations @@ -14,12 +15,14 @@ pub struct Key { pub data: Vec<u8>, } +impl AutoEncoder for Key {} + impl Key { /// Create a new key from scratch pub fn generate() -> Key { let data = random::bytes(KEY_LENGTH); - return Key { data: data }; + Key { data: data } } /// Use a password as a key @@ -29,13 +32,17 @@ impl Key { for b in &hashed { vec.push(b.clone()); } - return Key { data: vec }; + Key { data: vec } + } + + pub fn to_vec(&self) -> Vec<u8> { + self.data.clone() } /// Used to get the raw data from this key, as a slice copy pub fn to_slice(&self) -> [u8; KEY_LENGTH] { let mut slice: [u8; KEY_LENGTH] = [0; KEY_LENGTH]; slice.clone_from_slice(&self.data); - return slice; + slice } } |