Skip to content

Commit

Permalink
Merge pull request #2121 from alex/boringssl-build
Browse files Browse the repository at this point in the history
Fix building with latest BoringSSL
  • Loading branch information
sfackler authored Dec 9, 2023
2 parents a3d3449 + 6fb228b commit e053a9c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ jobs:
- false
library:
- name: boringssl
version: f78fe19fc98e0e6f760e05c6b9d48725004700d0
version: e6489902b7fb692875341b8ab5e57f0515f47bc1
- name: openssl
version: vendored
- name: openssl
Expand Down
9 changes: 9 additions & 0 deletions openssl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ fn cvt_p<T>(r: *mut T) -> Result<*mut T, ErrorStack> {
}
}

#[inline]
fn cvt_p_const<T>(r: *const T) -> Result<*const T, ErrorStack> {
if r.is_null() {
Err(ErrorStack::get())
} else {
Ok(r)
}
}

#[inline]
fn cvt(r: c_int) -> Result<c_int, ErrorStack> {
if r <= 0 {
Expand Down
6 changes: 3 additions & 3 deletions openssl/src/x509/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use crate::ssl::SslRef;
use crate::stack::{Stack, StackRef, Stackable};
use crate::string::OpensslString;
use crate::util::{ForeignTypeExt, ForeignTypeRefExt};
use crate::{cvt, cvt_n, cvt_p};
use crate::{cvt, cvt_n, cvt_p, cvt_p_const};
use openssl_macros::corresponds;

#[cfg(any(ossl102, libressl261))]
Expand Down Expand Up @@ -2548,8 +2548,8 @@ impl X509PurposeRef {
#[corresponds(X509_PURPOSE_get0)]
pub fn from_idx(idx: c_int) -> Result<&'static X509PurposeRef, ErrorStack> {
unsafe {
let ptr = cvt_p(ffi::X509_PURPOSE_get0(idx))?;
Ok(X509PurposeRef::from_ptr(ptr))
let ptr = cvt_p_const(ffi::X509_PURPOSE_get0(idx))?;
Ok(X509PurposeRef::from_const_ptr(ptr))
}
}

Expand Down
9 changes: 3 additions & 6 deletions openssl/src/x509/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ use crate::ssl::SslFiletype;
#[cfg(ossl300)]
use crate::stack::Stack;
use crate::stack::StackRef;
use crate::util::ForeignTypeRefExt;
#[cfg(any(ossl102, libressl261))]
use crate::x509::verify::{X509VerifyFlags, X509VerifyParamRef};
use crate::x509::{X509Object, X509PurposeId, X509};
Expand Down Expand Up @@ -165,9 +166,7 @@ impl X509Lookup<HashDir> {
/// directory.
#[corresponds(X509_LOOKUP_hash_dir)]
pub fn hash_dir() -> &'static X509LookupMethodRef<HashDir> {
// `*mut` cast is needed because BoringSSL returns a `*const`. This is
// ok because we only return an immutable reference.
unsafe { X509LookupMethodRef::from_ptr(ffi::X509_LOOKUP_hash_dir() as *mut _) }
unsafe { X509LookupMethodRef::from_const_ptr(ffi::X509_LOOKUP_hash_dir()) }
}
}

Expand Down Expand Up @@ -199,9 +198,7 @@ impl X509Lookup<File> {
/// into memory at the time the file is added as a lookup source.
#[corresponds(X509_LOOKUP_file)]
pub fn file() -> &'static X509LookupMethodRef<File> {
// `*mut` cast is needed because BoringSSL returns a `*const`. This is
// ok because we only return an immutable reference.
unsafe { X509LookupMethodRef::from_ptr(ffi::X509_LOOKUP_file() as *mut _) }
unsafe { X509LookupMethodRef::from_const_ptr(ffi::X509_LOOKUP_file()) }
}
}

Expand Down

0 comments on commit e053a9c

Please sign in to comment.