Mangle c helper functions
We want to make sure that multiple openssl versions can coexist in the same dependency tree. Closes #438
This commit is contained in:
parent
9cc089a6ad
commit
5042d3d170
|
|
@ -1,2 +1,4 @@
|
||||||
target/
|
target/
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
|
.idea/
|
||||||
|
*.iml
|
||||||
|
|
|
||||||
|
|
@ -3,19 +3,19 @@
|
||||||
#include <openssl/dh.h>
|
#include <openssl/dh.h>
|
||||||
#include <openssl/bn.h>
|
#include <openssl/bn.h>
|
||||||
|
|
||||||
void rust_SSL_CTX_clone(SSL_CTX *ctx) {
|
void rust_0_8_SSL_CTX_clone(SSL_CTX *ctx) {
|
||||||
CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);
|
CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rust_X509_clone(X509 *x509) {
|
void rust_0_8_X509_clone(X509 *x509) {
|
||||||
CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
|
CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
|
||||||
}
|
}
|
||||||
|
|
||||||
STACK_OF(X509_EXTENSION) *rust_X509_get_extensions(X509 *x) {
|
STACK_OF(X509_EXTENSION) *rust_0_8_X509_get_extensions(X509 *x) {
|
||||||
return x->cert_info ? x->cert_info->extensions : NULL;
|
return x->cert_info ? x->cert_info->extensions : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
DH *rust_DH_new_from_params(BIGNUM *p, BIGNUM *g, BIGNUM *q) {
|
DH *rust_0_8_DH_new_from_params(BIGNUM *p, BIGNUM *g, BIGNUM *q) {
|
||||||
DH *dh;
|
DH *dh;
|
||||||
|
|
||||||
if ((dh = DH_new()) == NULL) {
|
if ((dh = DH_new()) == NULL) {
|
||||||
|
|
@ -28,32 +28,32 @@ DH *rust_DH_new_from_params(BIGNUM *p, BIGNUM *g, BIGNUM *q) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#if OPENSSL_VERSION_NUMBER < 0x10000000L
|
#if OPENSSL_VERSION_NUMBER < 0x10000000L
|
||||||
int rust_HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int key_len, const EVP_MD *md, ENGINE *impl) {
|
int rust_0_8_HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int key_len, const EVP_MD *md, ENGINE *impl) {
|
||||||
HMAC_Init_ex(ctx, key, key_len, md, impl);
|
HMAC_Init_ex(ctx, key, key_len, md, impl);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rust_HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len) {
|
int rust_0_8_HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len) {
|
||||||
HMAC_Update(ctx, data, len);
|
HMAC_Update(ctx, data, len);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rust_HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len) {
|
int rust_0_8_HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len) {
|
||||||
HMAC_Final(ctx, md, len);
|
HMAC_Final(ctx, md, len);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
int rust_HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int key_len, const EVP_MD *md, ENGINE *impl) {
|
int rust_0_8_HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int key_len, const EVP_MD *md, ENGINE *impl) {
|
||||||
return HMAC_Init_ex(ctx, key, key_len, md, impl);
|
return HMAC_Init_ex(ctx, key, key_len, md, impl);
|
||||||
}
|
}
|
||||||
|
|
||||||
int rust_HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len) {
|
int rust_0_8_HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len) {
|
||||||
return HMAC_Update(ctx, data, len);
|
return HMAC_Update(ctx, data, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
int rust_HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len) {
|
int rust_0_8_HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len) {
|
||||||
return HMAC_Final(ctx, md, len);
|
return HMAC_Final(ctx, md, len);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,12 @@ use libc::{c_int, c_void, c_uint, c_uchar};
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn rust_SSL_CTX_clone(cxt: *mut ffi::SSL_CTX);
|
pub fn rust_0_8_SSL_CTX_clone(cxt: *mut ffi::SSL_CTX);
|
||||||
pub fn rust_X509_clone(x509: *mut ffi::X509);
|
pub fn rust_0_8_X509_clone(x509: *mut ffi::X509);
|
||||||
pub fn rust_X509_get_extensions(x: *mut ffi::X509) -> *mut ffi::stack_st_X509_EXTENSION;
|
pub fn rust_0_8_X509_get_extensions(x: *mut ffi::X509) -> *mut ffi::stack_st_X509_EXTENSION;
|
||||||
|
|
||||||
pub fn rust_HMAC_Init_ex(ctx: *mut ffi::HMAC_CTX, key: *const c_void, keylen: c_int, md: *const ffi::EVP_MD, impl_: *mut ffi::ENGINE) -> c_int;
|
pub fn rust_0_8_HMAC_Init_ex(ctx: *mut ffi::HMAC_CTX, key: *const c_void, keylen: c_int, md: *const ffi::EVP_MD, impl_: *mut ffi::ENGINE) -> c_int;
|
||||||
pub fn rust_HMAC_Final(ctx: *mut ffi::HMAC_CTX, output: *mut c_uchar, len: *mut c_uint) -> c_int;
|
pub fn rust_0_8_HMAC_Final(ctx: *mut ffi::HMAC_CTX, output: *mut c_uchar, len: *mut c_uint) -> c_int;
|
||||||
pub fn rust_HMAC_Update(ctx: *mut ffi::HMAC_CTX, input: *const c_uchar, len: c_uint) -> c_int;
|
pub fn rust_0_8_HMAC_Update(ctx: *mut ffi::HMAC_CTX, input: *const c_uchar, len: c_uint) -> c_int;
|
||||||
pub fn rust_DH_new_from_params(p: *mut ffi::BIGNUM, g: *mut ffi::BIGNUM, q: *mut ffi::BIGNUM) -> *mut ffi::DH;
|
pub fn rust_0_8_DH_new_from_params(p: *mut ffi::BIGNUM, g: *mut ffi::BIGNUM, q: *mut ffi::BIGNUM) -> *mut ffi::DH;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -92,11 +92,11 @@ impl HMAC {
|
||||||
|
|
||||||
fn init_once(&mut self, md: *const ffi::EVP_MD, key: &[u8]) -> Result<(), ErrorStack> {
|
fn init_once(&mut self, md: *const ffi::EVP_MD, key: &[u8]) -> Result<(), ErrorStack> {
|
||||||
unsafe {
|
unsafe {
|
||||||
try_ssl!(c_helpers::rust_HMAC_Init_ex(&mut self.ctx,
|
try_ssl!(c_helpers::rust_0_8_HMAC_Init_ex(&mut self.ctx,
|
||||||
key.as_ptr() as *const _,
|
key.as_ptr() as *const _,
|
||||||
key.len() as c_int,
|
key.len() as c_int,
|
||||||
md,
|
md,
|
||||||
0 as *mut _));
|
0 as *mut _));
|
||||||
}
|
}
|
||||||
self.state = Reset;
|
self.state = Reset;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -113,11 +113,11 @@ impl HMAC {
|
||||||
// If the key and/or md is not supplied it's reused from the last time
|
// If the key and/or md is not supplied it's reused from the last time
|
||||||
// avoiding redundant initializations
|
// avoiding redundant initializations
|
||||||
unsafe {
|
unsafe {
|
||||||
try_ssl!(c_helpers::rust_HMAC_Init_ex(&mut self.ctx,
|
try_ssl!(c_helpers::rust_0_8_HMAC_Init_ex(&mut self.ctx,
|
||||||
0 as *const _,
|
0 as *const _,
|
||||||
0,
|
0,
|
||||||
0 as *const _,
|
0 as *const _,
|
||||||
0 as *mut _));
|
0 as *mut _));
|
||||||
}
|
}
|
||||||
self.state = Reset;
|
self.state = Reset;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -130,7 +130,7 @@ impl HMAC {
|
||||||
while !data.is_empty() {
|
while !data.is_empty() {
|
||||||
let len = cmp::min(data.len(), c_uint::max_value() as usize);
|
let len = cmp::min(data.len(), c_uint::max_value() as usize);
|
||||||
unsafe {
|
unsafe {
|
||||||
try_ssl!(c_helpers::rust_HMAC_Update(&mut self.ctx, data.as_ptr(), len as c_uint));
|
try_ssl!(c_helpers::rust_0_8_HMAC_Update(&mut self.ctx, data.as_ptr(), len as c_uint));
|
||||||
}
|
}
|
||||||
data = &data[len..];
|
data = &data[len..];
|
||||||
}
|
}
|
||||||
|
|
@ -147,7 +147,7 @@ impl HMAC {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut len = ffi::EVP_MAX_MD_SIZE;
|
let mut len = ffi::EVP_MAX_MD_SIZE;
|
||||||
let mut res = vec![0; len as usize];
|
let mut res = vec![0; len as usize];
|
||||||
try_ssl!(c_helpers::rust_HMAC_Final(&mut self.ctx, res.as_mut_ptr(), &mut len));
|
try_ssl!(c_helpers::rust_0_8_HMAC_Final(&mut self.ctx, res.as_mut_ptr(), &mut len));
|
||||||
res.truncate(len as usize);
|
res.truncate(len as usize);
|
||||||
self.state = Finalized;
|
self.state = Finalized;
|
||||||
Ok(res)
|
Ok(res)
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ impl DH {
|
||||||
#[cfg(feature = "dh_from_params")]
|
#[cfg(feature = "dh_from_params")]
|
||||||
pub fn from_params(p: BigNum, g: BigNum, q: BigNum) -> Result<DH, ErrorStack> {
|
pub fn from_params(p: BigNum, g: BigNum, q: BigNum) -> Result<DH, ErrorStack> {
|
||||||
let dh = unsafe {
|
let dh = unsafe {
|
||||||
try_ssl_null!(::c_helpers::rust_DH_new_from_params(p.as_ptr(), g.as_ptr(), q.as_ptr()))
|
try_ssl_null!(::c_helpers::rust_0_8_DH_new_from_params(p.as_ptr(), g.as_ptr(), q.as_ptr()))
|
||||||
};
|
};
|
||||||
mem::forget(p);
|
mem::forget(p);
|
||||||
mem::forget(g);
|
mem::forget(g);
|
||||||
|
|
|
||||||
|
|
@ -662,7 +662,7 @@ impl Clone for SslContext {
|
||||||
/// Requires the `ssl_context_clone` feature.
|
/// Requires the `ssl_context_clone` feature.
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
unsafe {
|
unsafe {
|
||||||
::c_helpers::rust_SSL_CTX_clone(self.as_ptr());
|
::c_helpers::rust_0_8_SSL_CTX_clone(self.as_ptr());
|
||||||
SslContext::from_ptr(self.as_ptr())
|
SslContext::from_ptr(self.as_ptr())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -359,7 +359,7 @@ impl X509Generator {
|
||||||
let req = ffi::X509_to_X509_REQ(cert.as_ptr(), ptr::null_mut(), ptr::null());
|
let req = ffi::X509_to_X509_REQ(cert.as_ptr(), ptr::null_mut(), ptr::null());
|
||||||
try_ssl_null!(req);
|
try_ssl_null!(req);
|
||||||
|
|
||||||
let exts = ::c_helpers::rust_X509_get_extensions(cert.as_ptr());
|
let exts = ::c_helpers::rust_0_8_X509_get_extensions(cert.as_ptr());
|
||||||
if exts != ptr::null_mut() {
|
if exts != ptr::null_mut() {
|
||||||
try_ssl!(ffi::X509_REQ_add_extensions(req, exts));
|
try_ssl!(ffi::X509_REQ_add_extensions(req, exts));
|
||||||
}
|
}
|
||||||
|
|
@ -481,7 +481,7 @@ impl Clone for X509 {
|
||||||
/// Requires the `x509_clone` feature.
|
/// Requires the `x509_clone` feature.
|
||||||
fn clone(&self) -> X509 {
|
fn clone(&self) -> X509 {
|
||||||
unsafe {
|
unsafe {
|
||||||
::c_helpers::rust_X509_clone(self.as_ptr());
|
::c_helpers::rust_0_8_X509_clone(self.as_ptr());
|
||||||
X509::new(self.as_ptr())
|
X509::new(self.as_ptr())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue