aboutsummaryrefslogtreecommitdiff
path: root/openssl-sys/src
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2015-06-27 15:11:11 -0700
committerSteven Fackler <[email protected]>2015-06-27 15:11:11 -0700
commitd0b769c93c623d308c02cb5d86726f4c9607f5f4 (patch)
treefd6e13dd16d8596e5d5d8101bfb39d640155ff91 /openssl-sys/src
parentMerge branch 'release' (diff)
downloadrust-openssl-d0b769c93c623d308c02cb5d86726f4c9607f5f4.tar.xz
rust-openssl-d0b769c93c623d308c02cb5d86726f4c9607f5f4.zip
Move macro replicas into C shim
Diffstat (limited to 'openssl-sys/src')
-rw-r--r--openssl-sys/src/lib.rs46
-rw-r--r--openssl-sys/src/openssl_shim.c (renamed from openssl-sys/src/old_openssl_shim.c)31
2 files changed, 47 insertions, 30 deletions
diff --git a/openssl-sys/src/lib.rs b/openssl-sys/src/lib.rs
index d77264be..ce8e6e37 100644
--- a/openssl-sys/src/lib.rs
+++ b/openssl-sys/src/lib.rs
@@ -9,7 +9,6 @@ extern crate libressl_pnacl_sys;
use libc::{c_void, c_int, c_char, c_ulong, c_long, c_uint, c_uchar, size_t};
use std::mem;
-use std::ptr;
use std::sync::{Mutex, MutexGuard};
use std::sync::{Once, ONCE_INIT};
@@ -263,35 +262,6 @@ pub fn init() {
}
}
-// Functions converted from macros
-pub unsafe fn BIO_eof(b: *mut BIO) -> bool {
- BIO_ctrl(b, BIO_CTRL_EOF, 0, ptr::null_mut()) == 1
-}
-
-pub unsafe fn SSL_CTX_set_options(ssl: *mut SSL_CTX, op: c_long) -> c_long {
- SSL_CTX_ctrl(ssl, SSL_CTRL_OPTIONS, op, ptr::null_mut())
-}
-
-pub unsafe fn BIO_set_mem_eof_return(b: *mut BIO, v: c_int) {
- BIO_ctrl(b, BIO_C_SET_BUF_MEM_EOF_RETURN, v as c_long, ptr::null_mut());
-}
-
-pub unsafe fn SSL_CTX_get_options(ssl: *mut SSL_CTX) -> c_long {
- SSL_CTX_ctrl(ssl, SSL_CTRL_OPTIONS, 0, ptr::null_mut())
-}
-
-pub unsafe fn SSL_CTX_clear_options(ssl: *mut SSL_CTX, op: c_long) -> c_long {
- SSL_CTX_ctrl(ssl, SSL_CTRL_CLEAR_OPTIONS, (op), ptr::null_mut())
-}
-
-pub unsafe fn SSL_CTX_add_extra_chain_cert(ssl: *mut SSL_CTX, cert: *mut X509) -> c_long {
- SSL_CTX_ctrl(ssl, SSL_CTRL_EXTRA_CHAIN_CERT, 0, cert)
-}
-
-pub unsafe fn SSL_CTX_set_read_ahead(ctx: *mut SSL_CTX, m: c_long) -> c_long {
- SSL_CTX_ctrl(ctx, SSL_CTRL_SET_READ_AHEAD, m, ptr::null_mut())
-}
-
// True functions
extern "C" {
pub fn ASN1_INTEGER_set(dest: *mut ASN1_INTEGER, value: c_long) -> c_int;
@@ -610,6 +580,22 @@ extern "C" {
pub fn d2i_RSA_PUBKEY(k: *const *mut RSA, buf: *const *const u8, len: c_uint) -> *mut RSA;
pub fn i2d_RSAPrivateKey(k: *mut RSA, buf: *const *mut u8) -> c_int;
pub fn d2i_RSAPrivateKey(k: *const *mut RSA, buf: *const *const u8, len: c_uint) -> *mut RSA;
+
+ // These functions are defined in OpenSSL as macros, so we shim them
+ #[link_name = "BIO_eof_shim"]
+ pub fn BIO_eof(b: *mut BIO) -> c_int;
+ #[link_name = "BIO_set_mem_eof_return_shim"]
+ pub fn BIO_set_mem_eof_return(b: *mut BIO, v: c_int);
+ #[link_name = "SSL_CTX_set_options_shim"]
+ pub fn SSL_CTX_set_options(ctx: *mut SSL_CTX, options: c_long) -> c_long;
+ #[link_name = "SSL_CTX_get_options_shim"]
+ pub fn SSL_CTX_get_options(ctx: *mut SSL_CTX) -> c_long;
+ #[link_name = "SSL_CTX_clear_options_shim"]
+ pub fn SSL_CTX_clear_options(ctx: *mut SSL_CTX, options: c_long) -> c_long;
+ #[link_name = "SSL_CTX_add_extra_chain_cert_shim"]
+ pub fn SSL_CTX_add_extra_chain_cert(ctx: *mut SSL_CTX, x509: *mut X509) -> c_long;
+ #[link_name = "SSL_CTX_set_read_ahead_shim"]
+ pub fn SSL_CTX_set_read_ahead(ctx: *mut SSL_CTX, m: c_long) -> c_long;
}
pub mod probe;
diff --git a/openssl-sys/src/old_openssl_shim.c b/openssl-sys/src/openssl_shim.c
index 19ce74fc..9b4a9fa2 100644
--- a/openssl-sys/src/old_openssl_shim.c
+++ b/openssl-sys/src/openssl_shim.c
@@ -1,4 +1,5 @@
#include <openssl/hmac.h>
+#include <openssl/ssl.h>
#if OPENSSL_VERSION_NUMBER < 0x1000000L
// Copied from openssl crypto/hmac/hmac.c
@@ -47,3 +48,33 @@ int HMAC_Final_shim(HMAC_CTX *ctx, unsigned char *md, unsigned int *len) {
return HMAC_Final(ctx, md, len);
}
#endif
+
+// shims for OpenSSL macros
+
+int BIO_eof_shim(BIO *b) {
+ return BIO_eof(b);
+}
+
+void BIO_set_mem_eof_return_shim(BIO *b, int v) {
+ BIO_set_mem_eof_return(b, v);
+}
+
+long SSL_CTX_set_options_shim(SSL_CTX *ctx, long options) {
+ return SSL_CTX_set_options(ctx, options);
+}
+
+long SSL_CTX_get_options_shim(SSL_CTX *ctx) {
+ return SSL_CTX_get_options(ctx);
+}
+
+long SSL_CTX_clear_options_shim(SSL_CTX *ctx, long options) {
+ return SSL_CTX_clear_options(ctx, options);
+}
+
+long SSL_CTX_add_extra_chain_cert_shim(SSL_CTX *ctx, X509 *x509) {
+ return SSL_CTX_add_extra_chain_cert(ctx, x509);
+}
+
+long SSL_CTX_set_read_ahead_shim(SSL_CTX *ctx, long m) {
+ return SSL_CTX_set_read_ahead(ctx, m);
+}