aboutsummaryrefslogtreecommitdiff
path: root/lockchain-core/src/crypto/random.rs
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2018-08-06 15:46:57 +0200
committerKatharina Fey <kookie@spacekookie.de>2018-08-06 15:46:57 +0200
commit24da2df81265ddfbbeb7dd10fd59eb828afa41b8 (patch)
treeced252085b35d8fc24f36c18d9eb07e6d375b3d4 /lockchain-core/src/crypto/random.rs
parent0231f3963c655e8ed99b6139a98aa15f018d7227 (diff)
Doing some file management, moving stuff around
Diffstat (limited to 'lockchain-core/src/crypto/random.rs')
-rw-r--r--lockchain-core/src/crypto/random.rs46
1 files changed, 0 insertions, 46 deletions
diff --git a/lockchain-core/src/crypto/random.rs b/lockchain-core/src/crypto/random.rs
deleted file mode 100644
index 7d31992..0000000
--- a/lockchain-core/src/crypto/random.rs
+++ /dev/null
@@ -1,46 +0,0 @@
-//! A small convenience wrapper around `rand`
-
-use rand::{thread_rng, Rng};
-
-/// Generate a random number with an upper bound
-pub fn number(bound: u64) -> u64 {
- return thread_rng().next_u64() % bound;
-}
-
-/// Generate a sequence of random bytes that are returned
-/// as a vector.
-///
-/// Can at most allocate 2048 bytes at a time
-/// FIXME: That shouldn't have a limit!
-pub fn bytes(length: usize) -> Vec<u8> {
- let mut vec: Vec<u8> = Vec::new();
-
- if length > 2048 {
- return vec;
- }
-
- let mut random_data = [0u8; 2048];
- thread_rng().fill_bytes(&mut random_data);
-
- for i in 0..length {
- vec.push(random_data[i]);
- }
-
- return vec;
-}
-
-/// A small utility wraper around bcrypt to allow
-/// easy password checking.
-pub mod passwd {
- use bcrypt::{self, DEFAULT_COST};
-
- /// Create a new password, returning a hash
- pub fn create(pw: &str) -> Option<String> {
- Some(bcrypt::hash(pw, DEFAULT_COST).ok()?)
- }
-
- /// Verify a password against it's stored hash
- pub fn verify(pw: &str, hash: &str) -> Option<bool> {
- bcrypt::verify(pw, hash).ok()
- }
-}