aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Ballard <[email protected]>2013-05-10 20:22:14 -0700
committerKevin Ballard <[email protected]>2013-05-10 20:22:14 -0700
commit4e79896c962699e92e29bba97a07987cf26dec25 (patch)
treeca62dd4c9f9ff1313c0412f744ad8fa62e5bb7b4
parentTweak for rust trunk (c081ffb 2013-04-30 02:21:37 -0700) (diff)
downloadrust-openssl-4e79896c962699e92e29bba97a07987cf26dec25.tar.xz
rust-openssl-4e79896c962699e92e29bba97a07987cf26dec25.zip
Remove unnecessary `unsafe` blocks
-rw-r--r--hash.rs8
-rw-r--r--hex.rs12
-rw-r--r--pkey.rs36
3 files changed, 23 insertions, 33 deletions
diff --git a/hash.rs b/hash.rs
index 14b39aa4..78dfd08e 100644
--- a/hash.rs
+++ b/hash.rs
@@ -98,11 +98,9 @@ pub impl Hasher {
* value
*/
pub fn hash(t: HashType, data: &[u8]) -> ~[u8] {
- unsafe {
- let h = Hasher(t);
- h.update(data);
- h.final()
- }
+ let h = Hasher(t);
+ h.update(data);
+ h.final()
}
#[cfg(test)]
diff --git a/hex.rs b/hex.rs
index 2193e49c..abd62e8a 100644
--- a/hex.rs
+++ b/hex.rs
@@ -34,10 +34,8 @@ impl<'self> ToHex for &'self [u8] {
let xhi = (x >> 4) & 0x0F;
let xlo = (x ) & 0x0F;
- unsafe {
- str::push_char(&mut s, chars[xhi]);
- str::push_char(&mut s, chars[xlo]);
- }
+ str::push_char(&mut s, chars[xhi]);
+ str::push_char(&mut s, chars[xlo]);
}
s
@@ -61,9 +59,7 @@ impl<'self> FromHex for &'self str {
else { fail!(~"bad hex character"); };
if i % 2 == 0 {
- unsafe {
- vec::push(&mut vec, nibble << 4);
- }
+ vec::push(&mut vec, nibble << 4);
}
else {
vec[i/2] |= nibble;
@@ -89,4 +85,4 @@ mod tests {
}
-} \ No newline at end of file
+}
diff --git a/pkey.rs b/pkey.rs
index 87fcc6a6..bdd18ada 100644
--- a/pkey.rs
+++ b/pkey.rs
@@ -100,18 +100,16 @@ pub fn PKey() -> PKey {
///Represents a public key, optionally with a private key attached.
priv impl PKey {
priv fn _tostr(&self, f: @fn(*EVP_PKEY, &*mut u8) -> c_int) -> ~[u8] {
- unsafe {
- let buf = ptr::mut_null();
- let len = f(self.evp, &buf);
- if len < 0 as c_int { return ~[]; }
- let mut s = vec::from_elem(len as uint, 0u8);
+ let buf = ptr::mut_null();
+ let len = f(self.evp, &buf);
+ if len < 0 as c_int { return ~[]; }
+ let mut s = vec::from_elem(len as uint, 0u8);
- let r = do vec::as_mut_buf(s) |ps, _len| {
- f(self.evp, &ps)
- };
+ let r = do vec::as_mut_buf(s) |ps, _len| {
+ f(self.evp, &ps)
+ };
- vec::slice(s, 0u, r as uint).to_owned()
- }
+ vec::slice(s, 0u, r as uint).to_owned()
}
priv fn _fromstr(
@@ -119,12 +117,10 @@ priv impl PKey {
s: &[u8],
f: @fn(c_int, &*EVP_PKEY, &*u8, c_uint) -> *EVP_PKEY
) {
- unsafe {
- do vec::as_imm_buf(s) |ps, len| {
- let evp = ptr::null();
- f(6 as c_int, &evp, &ps, len as c_uint);
- self.evp = evp;
- }
+ do vec::as_imm_buf(s) |ps, len| {
+ let evp = ptr::null();
+ f(6 as c_int, &evp, &ps, len as c_uint);
+ self.evp = evp;
}
}
}
@@ -298,24 +294,24 @@ pub impl PKey {
* Encrypts data using OAEP padding, returning the encrypted data. The
* 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.
*/
- 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(),
* 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
* 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] {
unsafe {