Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
b4c735e
Initial support for OpenSSL 3.0.0-alpha1
sfackler Apr 29, 2020
676e112
fix constness
sfackler Apr 29, 2020
17ef4bb
Fix error function tracking
sfackler Apr 29, 2020
d081c2b
Update to 3.0.0-alpha5
sfackler Jul 22, 2020
2a29aac
Merge remote-tracking branch 'origin/master' into openssl-300
sfackler Jul 22, 2020
0940b29
Merge remote-tracking branch 'origin/master' into openssl-300
sfackler Jul 22, 2020
2bc060f
Update openssl-errors for 3.0.0
sfackler Jul 24, 2020
f824aec
rustfmt
sfackler Jul 24, 2020
2ab15f0
Add circle builds
sfackler Jul 24, 2020
65b3d03
Work around openssl bug
sfackler Jul 24, 2020
695d5c8
fix tests
sfackler Jul 24, 2020
e4542ef
Update to alpha6
sfackler Aug 8, 2020
bd7d8dc
Merge remote-tracking branch 'origin/master' into openssl-300
sfackler Aug 15, 2020
2dc1290
Merge remote-tracking branch 'origin/master' into openssl-300
sfackler Oct 26, 2020
203ca55
Bump to alpha7
sfackler Oct 26, 2020
f959bd5
fixes
sfackler Oct 26, 2020
57f748c
more fixes
sfackler Oct 26, 2020
0e7ccc1
Remove stray println
sfackler Oct 26, 2020
e71ba98
bump to alpha8
sfackler Nov 13, 2020
80c0082
Merge remote-tracking branch 'origin/master' into openssl-300
sfackler Nov 13, 2020
bc01070
Merge remote-tracking branch 'origin/master' into openssl-300
sfackler Nov 13, 2020
7ff4a14
Merge remote-tracking branch 'origin/master' into openssl-300
sfackler Nov 14, 2020
e1e7b40
Bump to alpha9
sfackler Nov 29, 2020
2c9ff44
Merge remote-tracking branch 'origin/master' into openssl-300
sfackler Dec 2, 2020
eefdc57
unignore test for 3.0.0
sfackler Dec 3, 2020
bd6a125
fix arg mutability
sfackler Dec 3, 2020
8d3cf26
Revert "unignore test for 3.0.0"
sfackler Dec 3, 2020
e593a72
Test against alpha10
sfackler Jan 7, 2021
63a3199
Test against alpha11
sfackler Feb 4, 2021
00577e4
Merge remote-tracking branch 'origin/master' into openssl-300
sfackler Feb 5, 2021
de41f55
fix constness in alpha11
sfackler Feb 5, 2021
831af85
fix cfg-if
sfackler Feb 5, 2021
0f7182a
clippy
sfackler Feb 5, 2021
c479746
Fix X509V3_CTX layout
sfackler Feb 5, 2021
40de0f5
Merge remote-tracking branch 'origin/master' into openssl-300
sfackler Feb 20, 2021
72e1ea6
update to alpha-12
sfackler Feb 20, 2021
114e815
fix constants
sfackler Feb 20, 2021
81676ee
Update to alpha13
sfackler Mar 17, 2021
2b0ab01
Update rsa.rs
sfackler Mar 18, 2021
83480b0
Merge remote-tracking branch 'origin/master' into openssl-300
sfackler Mar 18, 2021
542c7b1
Merge branch 'master' into openssl-300
sfackler Mar 24, 2021
405a581
bump to alpha 14
sfackler Apr 13, 2021
2a5160c
Merge branch 'master' into openssl-300
sfackler Apr 13, 2021
9a32382
fix DH test
sfackler Apr 13, 2021
a9fe565
flag off test to 102+
sfackler Apr 13, 2021
cc1c74c
Update to alpha15
sfackler Apr 22, 2021
0ca6055
Update ci.yml
sfackler May 8, 2021
770ba32
Update ssl.rs
sfackler May 8, 2021
39df95b
Merge remote-tracking branch 'origin/master' into openssl-300
sfackler May 23, 2021
f7d5c50
bump to alpha 17
sfackler May 23, 2021
8c3e29f
flag off deprecated sha API in 3.0
sfackler May 23, 2021
b50dc27
fix sslmode size
sfackler May 23, 2021
5febb69
define OSSL_LIB_CTX
sfackler May 23, 2021
0c18a79
rustfmt
sfackler May 23, 2021
33b868c
wrong crate!
sfackler May 23, 2021
0a511e7
fix build
sfackler May 23, 2021
8086cc3
we are an old edition
sfackler May 23, 2021
3be2f3b
fix build
sfackler May 23, 2021
15699ad
rustfmt
sfackler May 23, 2021
75cec0c
move constants to cfg'd area
sfackler May 23, 2021
7e68a80
more fixes
sfackler May 23, 2021
4a1dbec
resize the right type
sfackler May 24, 2021
11c5af3
fix unused import
sfackler May 24, 2021
a30478c
fix constant types
sfackler May 24, 2021
805a9c4
Update ci.yml
sfackler Jun 18, 2021
136abc0
clippy
sfackler Jun 18, 2021
cb3e941
fix function names
sfackler Jun 18, 2021
9434332
asdf
sfackler Jun 18, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ jobs:
library:
- name: openssl
version: vendored
- name: openssl
version: 3.0.0-beta1
dl-path: /
- name: openssl
version: 1.1.1k
dl-path: /
Expand Down
1 change: 1 addition & 0 deletions openssl-errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ readme = "README.md"
categories = ["api-bindings"]

[dependencies]
cfg-if = "0.1"
libc = "0.2"

openssl-sys = { version = "0.9.42", path = "../openssl-sys" }
Expand Down
13 changes: 13 additions & 0 deletions openssl-errors/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![allow(clippy::inconsistent_digit_grouping, clippy::unusual_byte_groupings)]

use std::env;

fn main() {
if let Ok(version) = env::var("DEP_OPENSSL_VERSION_NUMBER") {
let version = u64::from_str_radix(&version, 16).unwrap();

if version >= 0x3_00_00_00_0 {
println!("cargo:rustc-cfg=ossl300");
}
}
}
191 changes: 146 additions & 45 deletions openssl-errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#![warn(missing_docs)]
#![doc(html_root_url = "https://docs.rs/openssl-errors/0.1")]

use cfg_if::cfg_if;
use libc::{c_char, c_int};
use std::borrow::Cow;
use std::marker::PhantomData;
Expand All @@ -70,19 +71,37 @@ pub trait Library {
fn id() -> c_int;
}

cfg_if! {
if #[cfg(ossl300)] {
type FunctionInner = *const c_char;
} else {
type FunctionInner = c_int;
}
}

/// A function declaration, parameterized by its error library.
pub struct Function<T>(c_int, PhantomData<T>);
pub struct Function<T>(FunctionInner, PhantomData<T>);

// manual impls necessary for the 3.0.0 case
unsafe impl<T> Sync for Function<T> where T: Sync {}
unsafe impl<T> Send for Function<T> where T: Send {}

impl<T> Function<T> {
/// Creates a function from its raw identifier.
/// This is not considered a part of the crate's public API, and is subject to change at any time.
///
/// # Safety
///
/// The inner value must be valid for the lifetime of the process.
#[doc(hidden)]
#[inline]
pub const fn from_raw(raw: c_int) -> Function<T> {
pub const unsafe fn __from_raw(raw: FunctionInner) -> Function<T> {
Function(raw, PhantomData)
}

/// Returns the function's raw identifier.
/// This is not considered a part of the crate's public API, and is subject to change at any time.
#[doc(hidden)]
#[inline]
pub const fn as_raw(&self) -> c_int {
pub const fn __as_raw(&self) -> FunctionInner {
self.0
}
}
Expand All @@ -91,15 +110,17 @@ impl<T> Function<T> {
pub struct Reason<T>(c_int, PhantomData<T>);

impl<T> Reason<T> {
/// Creates a reason from its raw identifier.
/// This is not considered a part of the crate's public API, and is subject to change at any time.
#[doc(hidden)]
#[inline]
pub const fn from_raw(raw: c_int) -> Reason<T> {
pub const fn __from_raw(raw: c_int) -> Reason<T> {
Reason(raw, PhantomData)
}

/// Returns the reason's raw identifier.
/// This is not considered a part of the crate's public API, and is subject to change at any time.
#[doc(hidden)]
#[inline]
pub const fn as_raw(&self) -> c_int {
pub const fn __as_raw(&self) -> c_int {
self.0
}
}
Expand All @@ -119,13 +140,37 @@ pub unsafe fn __put_error<T>(
) where
T: Library,
{
openssl_sys::ERR_put_error(
T::id(),
func.as_raw(),
reason.as_raw(),
file.as_ptr() as *const c_char,
line as c_int,
);
put_error_inner(T::id(), func.0, reason.0, file, line, message)
}

unsafe fn put_error_inner(
library: c_int,
func: FunctionInner,
reason: c_int,
file: &'static str,
line: u32,
message: Option<Cow<'static, str>>,
) {
cfg_if! {
if #[cfg(ossl300)] {
openssl_sys::ERR_new();
openssl_sys::ERR_set_debug(
file.as_ptr() as *const c_char,
line as c_int,
func,
);
openssl_sys::ERR_set_error(library, reason, ptr::null());
} else {
openssl_sys::ERR_put_error(
library,
func,
reason,
file.as_ptr() as *const c_char,
line as c_int,
);
}
}

let data = match message {
Some(Cow::Borrowed(s)) => Some((s.as_ptr() as *const c_char as *mut c_char, 0)),
Some(Cow::Owned(s)) => {
Expand Down Expand Up @@ -223,31 +268,11 @@ macro_rules! openssl_errors {
fn id() -> $crate::export::c_int {
static INIT: $crate::export::Once = $crate::export::Once::new();
static mut LIB_NUM: $crate::export::c_int = 0;
static mut STRINGS: [
$crate::export::ERR_STRING_DATA;
2 + $crate::openssl_errors!(@count $($func_name;)* $($reason_name;)*)
] = [
$crate::export::ERR_STRING_DATA {
error: 0,
string: concat!($lib_str, "\0").as_ptr() as *const $crate::export::c_char,
},
$(
$crate::export::ERR_STRING_DATA {
error: $crate::export::ERR_PACK(0, $lib_name::$func_name.as_raw(), 0),
string: concat!($func_str, "\0").as_ptr() as *const $crate::export::c_char,
},
)*
$(
$crate::export::ERR_STRING_DATA {
error: $crate::export::ERR_PACK(0, 0, $lib_name::$reason_name.as_raw()),
string: concat!($reason_str, "\0").as_ptr() as *const $crate::export::c_char,
},
)*
$crate::export::ERR_STRING_DATA {
error: 0,
string: $crate::export::null(),
}
];
$crate::__openssl_errors_helper! {
@strings $lib_name($lib_str)
functions { $($func_name($func_str);)* }
reasons { $($reason_name($reason_str);)* }
}

unsafe {
INIT.call_once(|| {
Expand All @@ -263,19 +288,21 @@ macro_rules! openssl_errors {
}

impl $lib_name {
$crate::openssl_errors!(@func_consts $lib_name; 1; $($(#[$func_attr])* $func_name;)*);
$crate::openssl_errors!(@func_consts $lib_name; 1; $($(#[$func_attr])* $func_name($func_str);)*);
$crate::openssl_errors!(@reason_consts $lib_name; 1; $($(#[$reason_attr])* $reason_name;)*);
}
)*};
(@func_consts $lib_name:ident; $n:expr; $(#[$attr:meta])* $name:ident; $($tt:tt)*) => {
(@func_consts $lib_name:ident; $n:expr; $(#[$attr:meta])* $name:ident($str:expr); $($tt:tt)*) => {
$(#[$attr])*
pub const $name: $crate::Function<$lib_name> = $crate::Function::from_raw($n);
pub const $name: $crate::Function<$lib_name> = unsafe {
$crate::Function::__from_raw($crate::__openssl_errors_helper!(@func_value $n, $str))
};
$crate::openssl_errors!(@func_consts $lib_name; $n + 1; $($tt)*);
};
(@func_consts $lib_name:ident; $n:expr;) => {};
(@reason_consts $lib_name:ident; $n:expr; $(#[$attr:meta])* $name:ident; $($tt:tt)*) => {
$(#[$attr])*
pub const $name: $crate::Reason<$lib_name> = $crate::Reason::from_raw($n);
pub const $name: $crate::Reason<$lib_name> = $crate::Reason::__from_raw($n);
$crate::openssl_errors!(@reason_consts $lib_name; $n + 1; $($tt)*);
};
(@reason_consts $lib_name:ident; $n:expr;) => {};
Expand All @@ -284,3 +311,77 @@ macro_rules! openssl_errors {
};
(@count) => { 0 };
}

cfg_if! {
if #[cfg(ossl300)] {
#[doc(hidden)]
#[macro_export]
macro_rules! __openssl_errors_helper {
(
@strings $lib_name:ident($lib_str:expr)
functions { $($func_name:ident($func_str:expr);)* }
reasons { $($reason_name:ident($reason_str:expr);)* }
) => {
static mut STRINGS: [
$crate::export::ERR_STRING_DATA;
2 + $crate::openssl_errors!(@count $($reason_name;)*)
] = [
$crate::export::ERR_STRING_DATA {
error: 0,
string: concat!($lib_str, "\0").as_ptr() as *const $crate::export::c_char,
},
$(
$crate::export::ERR_STRING_DATA {
error: $crate::export::ERR_PACK(0, 0, $lib_name::$reason_name.__as_raw()),
string: concat!($reason_str, "\0").as_ptr() as *const $crate::export::c_char,
},
)*
$crate::export::ERR_STRING_DATA {
error: 0,
string: $crate::export::null(),
}
];
};
(@func_value $n:expr, $func_str:expr) => {
concat!($func_str, "\0").as_ptr() as *const $crate::export::c_char
};
}
} else {
#[doc(hidden)]
#[macro_export]
macro_rules! __openssl_errors_helper {
(
@strings $lib_name:ident($lib_str:expr)
functions { $($func_name:ident($func_str:expr);)* }
reasons { $($reason_name:ident($reason_str:expr);)* }
) => {
static mut STRINGS: [
$crate::export::ERR_STRING_DATA;
2 + $crate::openssl_errors!(@count $($func_name;)* $($reason_name;)*)
] = [
$crate::export::ERR_STRING_DATA {
error: 0,
string: concat!($lib_str, "\0").as_ptr() as *const $crate::export::c_char,
},
$(
$crate::export::ERR_STRING_DATA {
error: $crate::export::ERR_PACK(0, $lib_name::$func_name.__as_raw(), 0),
string: concat!($func_str, "\0").as_ptr() as *const $crate::export::c_char,
},
)*
$(
$crate::export::ERR_STRING_DATA {
error: $crate::export::ERR_PACK(0, 0, $lib_name::$reason_name.__as_raw()),
string: concat!($reason_str, "\0").as_ptr() as *const $crate::export::c_char,
},
)*
$crate::export::ERR_STRING_DATA {
error: 0,
string: $crate::export::null(),
}
];
};
(@func_value $n:expr, $func_str:expr) => {$n};
}
}
}
16 changes: 12 additions & 4 deletions openssl-errors/tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cfg_if::cfg_if;
use openssl::error::Error;

openssl_errors::openssl_errors! {
Expand Down Expand Up @@ -27,8 +28,15 @@ fn basic() {
error.file().replace(r"\", "/"),
"openssl-errors/tests/test.rs"
);
assert_eq!(error.line(), 19);
assert_eq!(error.data(), None);
assert_eq!(error.line(), 20);
cfg_if! {
if #[cfg(ossl300)] {
// https://github.com/openssl/openssl/issues/12530
assert!(error.data() == None || error.data() == Some(""));
} else {
assert_eq!(error.data(), None);
}
}
}

#[test]
Expand All @@ -44,7 +52,7 @@ fn static_data() {
error.file().replace(r"\", "/"),
"openssl-errors/tests/test.rs"
);
assert_eq!(error.line(), 36);
assert_eq!(error.line(), 44);
assert_eq!(error.data(), Some("foobar"));
}

Expand All @@ -61,6 +69,6 @@ fn dynamic_data() {
error.file().replace(r"\", "/"),
"openssl-errors/tests/test.rs"
);
assert_eq!(error.line(), 53);
assert_eq!(error.line(), 61);
assert_eq!(error.data(), Some("hello world"));
}
3 changes: 3 additions & 0 deletions openssl-sys/build/cfgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ pub fn get(openssl_version: Option<u64>, libressl_version: Option<u64>) -> Vec<&
} else {
let openssl_version = openssl_version.unwrap();

if openssl_version >= 0x3_00_00_00_0 {
cfgs.push("ossl300");
}
if openssl_version >= 0x1_00_01_00_0 {
cfgs.push("ossl101");
}
Expand Down
9 changes: 9 additions & 0 deletions openssl-sys/build/expando.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
#define VERSION2(n, v) RUST_VERSION_##n##_##v
#define VERSION(n, v) VERSION2(n, v)

#define NEW_VERSION2(a, b, c) RUST_VERSION_NEW_OPENSSL_##a##_##b##_##c
#define NEW_VERSION(a, b, c) NEW_VERSION2(a, b, c)

#ifdef LIBRESSL_VERSION_NUMBER
VERSION(LIBRESSL, LIBRESSL_VERSION_NUMBER)
#elif defined OPENSSL_VERSION_MAJOR
NEW_VERSION(OPENSSL_VERSION_MAJOR, OPENSSL_VERSION_MINOR, OPENSSL_VERSION_PATCH)
#else
VERSION(OPENSSL, OPENSSL_VERSION_NUMBER)
#endif
Expand Down Expand Up @@ -85,3 +90,7 @@ RUST_CONF_OPENSSL_NO_STDIO
#ifdef OPENSSL_NO_SM3
RUST_CONF_OPENSSL_NO_SM3
#endif

#ifdef OPENSSL_NO_DEPRECATED_3_0
RUST_CONF_OPENSSL_NO_DEPRECATED_3_0
#endif
Loading