Skip to content

Commit

Permalink
Add X509VerifyParam::set_email
Browse files Browse the repository at this point in the history
This is substantially similar to the other X.509 verification parameter
options like host.
  • Loading branch information
dhouck committed Aug 22, 2023
1 parent 99ea8a8 commit c317ffe
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions openssl-sys/src/handwritten/x509_vfy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ extern "C" {
#[cfg(any(ossl102, libressl261))]
pub fn X509_VERIFY_PARAM_set_hostflags(param: *mut X509_VERIFY_PARAM, flags: c_uint);
#[cfg(any(ossl102, libressl261))]
pub fn X509_VERIFY_PARAM_set1_email(
param: *mut X509_VERIFY_PARAM,
email: *const c_char,
emaillen: size_t,
) -> c_int;
#[cfg(any(ossl102, libressl261))]
pub fn X509_VERIFY_PARAM_set1_ip(
param: *mut X509_VERIFY_PARAM,
ip: *const c_uchar,
Expand Down
3 changes: 3 additions & 0 deletions openssl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## [Unreleased]

### Added
* Added `X509VerifyParam::set_email`

## [v0.10.56] - 2023-08-06

## Added
Expand Down
15 changes: 15 additions & 0 deletions openssl/src/x509/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@ impl X509VerifyParamRef {
}
}

/// Set the expected email address.
#[corresponds(X509_VERIFY_PARAM_set1_email)]
pub fn set_email(&mut self, email: &str) -> Result<(), ErrorStack> {
unsafe {
// len == 0 means "run strlen" :(
let raw_email = if email.is_empty() { "\0" } else { email };
cvt(ffi::X509_VERIFY_PARAM_set1_email(
self.as_ptr(),
raw_email.as_ptr() as *const _,
email.len(),
))
.map(|_| ())
}
}

/// Set the expected IPv4 or IPv6 address.
#[corresponds(X509_VERIFY_PARAM_set1_ip)]
pub fn set_ip(&mut self, ip: IpAddr) -> Result<(), ErrorStack> {
Expand Down

0 comments on commit c317ffe

Please sign in to comment.