Remove unnecessary `unsafe` blocks
This commit is contained in:
parent
f824a241d4
commit
4e79896c96
2
hash.rs
2
hash.rs
|
|
@ -98,12 +98,10 @@ pub impl Hasher {
|
||||||
* value
|
* value
|
||||||
*/
|
*/
|
||||||
pub fn hash(t: HashType, data: &[u8]) -> ~[u8] {
|
pub fn hash(t: HashType, data: &[u8]) -> ~[u8] {
|
||||||
unsafe {
|
|
||||||
let h = Hasher(t);
|
let h = Hasher(t);
|
||||||
h.update(data);
|
h.update(data);
|
||||||
h.final()
|
h.final()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
|
||||||
4
hex.rs
4
hex.rs
|
|
@ -34,11 +34,9 @@ impl<'self> ToHex for &'self [u8] {
|
||||||
let xhi = (x >> 4) & 0x0F;
|
let xhi = (x >> 4) & 0x0F;
|
||||||
let xlo = (x ) & 0x0F;
|
let xlo = (x ) & 0x0F;
|
||||||
|
|
||||||
unsafe {
|
|
||||||
str::push_char(&mut s, chars[xhi]);
|
str::push_char(&mut s, chars[xhi]);
|
||||||
str::push_char(&mut s, chars[xlo]);
|
str::push_char(&mut s, chars[xlo]);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
@ -61,10 +59,8 @@ impl<'self> FromHex for &'self str {
|
||||||
else { fail!(~"bad hex character"); };
|
else { fail!(~"bad hex character"); };
|
||||||
|
|
||||||
if i % 2 == 0 {
|
if i % 2 == 0 {
|
||||||
unsafe {
|
|
||||||
vec::push(&mut vec, nibble << 4);
|
vec::push(&mut vec, nibble << 4);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
vec[i/2] |= nibble;
|
vec[i/2] |= nibble;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
12
pkey.rs
12
pkey.rs
|
|
@ -100,7 +100,6 @@ 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: @fn(*EVP_PKEY, &*mut u8) -> c_int) -> ~[u8] {
|
priv fn _tostr(&self, f: @fn(*EVP_PKEY, &*mut u8) -> c_int) -> ~[u8] {
|
||||||
unsafe {
|
|
||||||
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,14 +111,12 @@ 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 fn _fromstr(
|
||||||
&mut self,
|
&mut self,
|
||||||
s: &[u8],
|
s: &[u8],
|
||||||
f: @fn(c_int, &*EVP_PKEY, &*u8, c_uint) -> *EVP_PKEY
|
f: @fn(c_int, &*EVP_PKEY, &*u8, c_uint) -> *EVP_PKEY
|
||||||
) {
|
) {
|
||||||
unsafe {
|
|
||||||
do vec::as_imm_buf(s) |ps, len| {
|
do vec::as_imm_buf(s) |ps, len| {
|
||||||
let evp = ptr::null();
|
let evp = ptr::null();
|
||||||
f(6 as c_int, &evp, &ps, len as c_uint);
|
f(6 as c_int, &evp, &ps, len as c_uint);
|
||||||
|
|
@ -127,7 +124,6 @@ priv impl PKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub impl PKey {
|
pub impl PKey {
|
||||||
fn gen(&mut self, keysz: uint) {
|
fn gen(&mut self, keysz: uint) {
|
||||||
|
|
@ -298,24 +294,24 @@ pub impl PKey {
|
||||||
* Encrypts data using OAEP padding, returning the encrypted data. The
|
* Encrypts data using OAEP padding, returning the encrypted data. The
|
||||||
* supplied data must not be larger than max_data().
|
* supplied data must not be larger than max_data().
|
||||||
*/
|
*/
|
||||||
fn encrypt(&self, s: &[u8]) -> ~[u8] { unsafe { self.encrypt_with_padding(s, OAEP) } }
|
fn encrypt(&self, s: &[u8]) -> ~[u8] { self.encrypt_with_padding(s, OAEP) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrypts data, expecting OAEP padding, returning the decrypted data.
|
* Decrypts data, expecting OAEP padding, returning the decrypted data.
|
||||||
*/
|
*/
|
||||||
fn decrypt(&self, s: &[u8]) -> ~[u8] { unsafe { self.decrypt_with_padding(s, OAEP) } }
|
fn decrypt(&self, s: &[u8]) -> ~[u8] { self.decrypt_with_padding(s, OAEP) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Signs data, using OpenSSL's default scheme and sha256. Unlike encrypt(),
|
* Signs data, using OpenSSL's default scheme and sha256. Unlike encrypt(),
|
||||||
* can process an arbitrary amount of data; returns the signature.
|
* can process an arbitrary amount of data; returns the signature.
|
||||||
*/
|
*/
|
||||||
fn sign(&self, s: &[u8]) -> ~[u8] { unsafe { self.sign_with_hash(s, SHA256) } }
|
fn sign(&self, s: &[u8]) -> ~[u8] { self.sign_with_hash(s, SHA256) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies a signature s (using OpenSSL's default scheme and sha256) on a
|
* Verifies a signature s (using OpenSSL's default scheme and sha256) on a
|
||||||
* message m. Returns true if the signature is valid, and false otherwise.
|
* message m. Returns true if the signature is valid, and false otherwise.
|
||||||
*/
|
*/
|
||||||
fn verify(&self, m: &[u8], s: &[u8]) -> bool { unsafe { self.verify_with_hash(m, s, SHA256) } }
|
fn verify(&self, m: &[u8], s: &[u8]) -> bool { self.verify_with_hash(m, s, SHA256) }
|
||||||
|
|
||||||
fn sign_with_hash(&self, s: &[u8], hash: HashType) -> ~[u8] {
|
fn sign_with_hash(&self, s: &[u8], hash: HashType) -> ~[u8] {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue