Created
December 14, 2016 06:11
-
-
Save david415/e541d4f1d70a7e06161128490f52462b to your computer and use it in GitHub Desktop.
rust lioness error handling?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate crypto; | |
use std::error::Error; | |
use std::fmt; | |
use crypto::mac::Mac; | |
use crypto::blake2b::Blake2b; | |
const LIONESS_KEY_SIZE: u32 = 208; | |
#[derive(Debug)] | |
enum LionessError { | |
BlockSizeError() | |
} | |
impl fmt::Display for LionessError { | |
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | |
write!(f, "LionessError is here!") | |
} | |
} | |
impl Error for LionessError { | |
fn description(&self) -> &str { | |
"I'm a Lioness error." | |
} | |
fn cause(&self) -> Option<&Error> { | |
match *self { | |
LionessError::BlockSizeError(ref err) => Some(err), | |
} | |
} | |
} | |
pub struct LionessCipher {} | |
impl LionessCipher { | |
pub fn new(key: &[u32; 208], blockSize: u32) -> Result<&LionessCipher, LionessError> { | |
if blockSize <= LIONESS_KEY_SIZE { | |
return Err(LionessError::BlockSizeError) | |
} | |
return Ok(&LionessCipher {}) | |
} | |
} | |
// xor function taken from: | |
// https://github.com/DaGenix/rust-crypto/blob/master/src/scrypt.rs | |
fn xor(x: &[u8], y: &[u8], output: &mut [u8]) { | |
for ((out, &x_i), &y_i) in output.iter_mut().zip(x.iter()).zip(y.iter()) { | |
*out = x_i ^ y_i; | |
} | |
} | |
#[cfg(test)] | |
mod tests { | |
fn it_works() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment