Update for latest incoming (3a3bf8b)

This commit is contained in:
Kevin Ballard 2013-05-29 23:42:07 -07:00
parent 08cdf5fde4
commit 2eba04e579
8 changed files with 26 additions and 16 deletions

View File

@ -5,3 +5,5 @@ crypto: crypto.rc $(wildcard *.rs)
clean: clean:
rm -f crypto libcrypto-*.so rm -f crypto libcrypto-*.so
rm libcrypto-*.dylib
rm -rf *.dSYM

View File

@ -1,4 +1,5 @@
use std::libc::c_uint; use std::libc::c_uint;
use std::{libc,vec,ptr};
pub enum HashType { pub enum HashType {
MD5, MD5,
@ -108,6 +109,7 @@ mod tests {
use super::*; use super::*;
use hex::FromHex; use hex::FromHex;
use hex::ToHex; use hex::ToHex;
use std::vec;
struct HashTest { struct HashTest {
input: ~[u8], input: ~[u8],
@ -125,7 +127,7 @@ mod tests {
let calced = calced_raw.to_hex(); let calced = calced_raw.to_hex();
if calced != hashtest.expected_output { if calced != hashtest.expected_output {
io::println(fmt!("Test failed - %s != %s", calced, hashtest.expected_output)); println(fmt!("Test failed - %s != %s", calced, hashtest.expected_output));
} }
assert!(calced == hashtest.expected_output); assert!(calced == hashtest.expected_output);

2
hex.rs
View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
extern mod std; use std::{str,uint,vec};
pub trait ToHex { pub trait ToHex {
fn to_hex(&self) -> ~str; fn to_hex(&self) -> ~str;

15
hmac.rs
View File

@ -15,6 +15,7 @@
*/ */
use hash::*; use hash::*;
use std::{libc,ptr,vec};
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub struct HMAC_CTX { pub struct HMAC_CTX {
@ -47,12 +48,12 @@ pub fn HMAC(ht: HashType, key: ~[u8]) -> HMAC {
let (evp, mdlen) = evpmd(ht); let (evp, mdlen) = evpmd(ht);
let mut ctx : HMAC_CTX = HMAC_CTX { let mut ctx : HMAC_CTX = HMAC_CTX {
mut md: ptr::null(), md: ptr::null(),
mut md_ctx: ptr::null(), md_ctx: ptr::null(),
mut i_ctx: ptr::null(), i_ctx: ptr::null(),
mut o_ctx: ptr::null(), o_ctx: ptr::null(),
mut key_length: 0, key_length: 0,
mut key: [0u8, .. 128] key: [0u8, .. 128]
}; };
HMAC_CTX_init(&mut ctx, HMAC_CTX_init(&mut ctx,
@ -91,5 +92,5 @@ fn main() {
h.update([00u8]); h.update([00u8]);
io::println(fmt!("%?", h.final())) println(fmt!("%?", h.final()))
} }

View File

@ -1,4 +1,5 @@
use std::libc::c_int; use std::libc::c_int;
use std::{vec,str};
#[link_args = "-lcrypto"] #[link_args = "-lcrypto"]
#[abi = "cdecl"] #[abi = "cdecl"]
@ -43,6 +44,7 @@ pub fn pbkdf2_hmac_sha1(pass: &str, salt: &[u8], iter: uint,
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use std::str;
// Test vectors from // Test vectors from
// http://tools.ietf.org/html/draft-josefsson-pbkdf2-test-vectors-06 // http://tools.ietf.org/html/draft-josefsson-pbkdf2-test-vectors-06

View File

@ -1,4 +1,5 @@
use std::libc::{c_int, c_uint}; use std::libc::{c_int, c_uint};
use std::{libc,cast,ptr,vec};
use hash::{HashType, MD5, SHA1, SHA224, SHA256, SHA384, SHA512}; use hash::{HashType, MD5, SHA1, SHA224, SHA256, SHA384, SHA512};
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
@ -99,7 +100,7 @@ pub fn PKey() -> PKey {
///Represents a public key, optionally with a private key attached. ///Represents a public key, optionally with a private key attached.
priv impl PKey { priv impl PKey {
priv fn _tostr(&self, f: extern "C" unsafe fn(*EVP_PKEY, &*mut u8) -> c_int) -> ~[u8] { priv unsafe fn _tostr(&self, f: extern "C" unsafe fn(*EVP_PKEY, &*mut u8) -> c_int) -> ~[u8] {
let buf = ptr::mut_null(); let buf = ptr::mut_null();
let len = f(self.evp, &buf); let len = f(self.evp, &buf);
if len < 0 as c_int { return ~[]; } if len < 0 as c_int { return ~[]; }
@ -112,7 +113,7 @@ priv impl PKey {
vec::slice(s, 0u, r as uint).to_owned() vec::slice(s, 0u, r as uint).to_owned()
} }
priv fn _fromstr( priv unsafe fn _fromstr(
&mut self, &mut self,
s: &[u8], s: &[u8],
f: extern "C" unsafe fn(c_int, &*EVP_PKEY, &*u8, c_uint) -> *EVP_PKEY f: extern "C" unsafe fn(c_int, &*EVP_PKEY, &*u8, c_uint) -> *EVP_PKEY

View File

@ -1,4 +1,5 @@
use std::libc::c_int; use std::libc::c_int;
use std::vec;
#[link_args = "-lcrypto"] #[link_args = "-lcrypto"]
#[abi = "cdecl"] #[abi = "cdecl"]
@ -28,6 +29,6 @@ mod tests {
#[test] #[test]
fn test_rand_bytes() { fn test_rand_bytes() {
let bytes = rand_bytes(32u); let bytes = rand_bytes(32u);
io::println(fmt!("%?", bytes)); println(fmt!("%?", bytes));
} }
} }

View File

@ -1,4 +1,5 @@
use std::libc::{c_int, c_uint}; use std::libc::{c_int, c_uint};
use std::{libc,vec};
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
type EVP_CIPHER_CTX = *libc::c_void; type EVP_CIPHER_CTX = *libc::c_void;
@ -236,10 +237,10 @@ mod tests {
let computed = cipher.update(pt.from_hex()) + cipher.final(); let computed = cipher.update(pt.from_hex()) + cipher.final();
if computed != expected { if computed != expected {
io::println(fmt!("Computed: %s", computed.to_hex())); println(fmt!("Computed: %s", computed.to_hex()));
io::println(fmt!("Expected: %s", expected.to_hex())); println(fmt!("Expected: %s", expected.to_hex()));
if computed.len() != expected.len() { if computed.len() != expected.len() {
io::println(fmt!("Lengths differ: %u in computed vs %u expected", println(fmt!("Lengths differ: %u in computed vs %u expected",
computed.len(), expected.len())); computed.len(), expected.len()));
} }
fail!(~"test failure"); fail!(~"test failure");