Skip to content

Instantly share code, notes, and snippets.

@david415
Created December 14, 2016 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save david415/e541d4f1d70a7e06161128490f52462b to your computer and use it in GitHub Desktop.
Save david415/e541d4f1d70a7e06161128490f52462b to your computer and use it in GitHub Desktop.
rust lioness error handling?
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