aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErick Tryzelaar <[email protected]>2013-08-15 07:30:37 -0700
committerErick Tryzelaar <[email protected]>2013-08-15 07:55:22 -0700
commit5ba7c49a91c27a9bc2c32a6e8a6e6c03ca3b4618 (patch)
tree20dc30c6d8c28633d8e7dfd940e65c94d4692cc6
parentUpdate to rust 0.8-pre (diff)
downloadrust-openssl-5ba7c49a91c27a9bc2c32a6e8a6e6c03ca3b4618.tar.xz
rust-openssl-5ba7c49a91c27a9bc2c32a6e8a6e6c03ca3b4618.zip
Add destructors to all the types that need destructing
-rw-r--r--hash.rs9
-rw-r--r--pkey.rs8
-rw-r--r--symm.rs9
3 files changed, 26 insertions, 0 deletions
diff --git a/hash.rs b/hash.rs
index 2b964518..421cdc23 100644
--- a/hash.rs
+++ b/hash.rs
@@ -25,6 +25,7 @@ mod libcrypto {
#[link_args = "-lcrypto"]
extern {
fn EVP_MD_CTX_create() -> EVP_MD_CTX;
+ fn EVP_MD_CTX_destroy(ctx: EVP_MD_CTX);
fn EVP_md5() -> EVP_MD;
fn EVP_sha1() -> EVP_MD;
@@ -96,6 +97,14 @@ impl Hasher {
}
}
+impl Drop for Hasher {
+ fn drop(&self) {
+ unsafe {
+ libcrypto::EVP_MD_CTX_destroy(self.ctx);
+ }
+ }
+}
+
/**
* Hashes the supplied input data using hash t, returning the resulting hash
* value
diff --git a/pkey.rs b/pkey.rs
index 0c6e807a..2da84458 100644
--- a/pkey.rs
+++ b/pkey.rs
@@ -336,6 +336,14 @@ impl PKey {
}
}
+impl Drop for PKey {
+ fn drop(&self) {
+ unsafe {
+ libcrypto::EVP_PKEY_free(self.evp);
+ }
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/symm.rs b/symm.rs
index 0f4f3246..a675d094 100644
--- a/symm.rs
+++ b/symm.rs
@@ -16,6 +16,7 @@ pub mod libcrypto {
#[link_args = "-lcrypto"]
fn EVP_CIPHER_CTX_new() -> EVP_CIPHER_CTX;
fn EVP_CIPHER_CTX_set_padding(ctx: EVP_CIPHER_CTX, padding: c_int);
+ fn EVP_CIPHER_CTX_free(ctx: EVP_CIPHER_CTX);
fn EVP_aes_128_ecb() -> EVP_CIPHER;
fn EVP_aes_128_cbc() -> EVP_CIPHER;
@@ -149,6 +150,14 @@ impl Crypter {
}
}
+impl Drop for Crypter {
+ fn drop(&self) {
+ unsafe {
+ libcrypto::EVP_CIPHER_CTX_free(self.ctx);
+ }
+ }
+}
+
/**
* Encrypts data, using the specified crypter type in encrypt mode with the
* specified key and iv; returns the resulting (encrypted) data.