diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs index d242a818d57fe7b8a6691ad7cf57166829780421..4782f18a916f5b1efaaf3c7b54f1c71d96f00f81 100644 --- a/openssl/src/x509/mod.rs +++ b/openssl/src/x509/mod.rs @@ -8,6 +8,10 @@ //! the secure protocol for browsing the web. use cfg_if::cfg_if; +use ffi::{ + X509_CRL_add0_revoked, X509_CRL_sort, X509_REVOKED_set_revocationDate, + X509_REVOKED_set_serialNumber, +}; use foreign_types::{ForeignType, ForeignTypeRef, Opaque}; use libc::{c_int, c_long, c_uint, c_void}; use std::cmp::{self, Ordering}; @@ -1654,6 +1658,15 @@ impl X509Revoked { X509Revoked, ffi::d2i_X509_REVOKED } + + /// Creates a new `X509Revoked` instance. + #[corresponds(X509_REVOKED_new)] + pub fn new() -> Result { + unsafe { + ffi::init(); + cvt_p(ffi::X509_REVOKED_new()).map(X509Revoked) + } + } } impl X509RevokedRef { @@ -1720,6 +1733,24 @@ impl X509RevokedRef { (c_int::MIN..=-2 | 2.., _) => panic!("OpenSSL should only return -2, -1, 0, or 1 for an extension's criticality but it returned {}", critical), } } + + /// Set the serial number of the revoked certificate + #[corresponds(X509_REVOKED_set_serialNumber)] + pub fn set_serial_number(&self, serial: &Asn1IntegerRef) { + unsafe { + let r = X509_REVOKED_set_serialNumber(self.as_ptr(), serial.as_ptr()); + assert!(r == 1); + } + } + + /// Set the date of the revocation + #[corresponds(X509_REVOKED_set_revocationDate)] + pub fn set_revocation_date(&self, time: &Asn1TimeRef) { + unsafe { + let r = X509_REVOKED_set_revocationDate(self.as_ptr(), time.as_ptr()); + assert!(r == 1); + } + } } /// The CRL entry extension identifying the reason for revocation see [`CrlReason`], @@ -1965,6 +1996,24 @@ impl X509CrlRef { (c_int::MIN..=-2 | 2.., _) => panic!("OpenSSL should only return -2, -1, 0, or 1 for an extension's criticality but it returned {}", critical), } } + + /// Adds revocation. + #[corresponds(X509_CRL_add0_revoked)] + pub fn add_revoked(&self, revoked: &X509Revoked) { + unsafe { + let r = X509_CRL_add0_revoked(self.as_ptr(), ffi::X509_REVOKED_dup(revoked.as_ptr())); + assert!(r == 1); + } + } + + /// Sorts list by serial number. + #[corresponds(X509_CRL_sort)] + pub fn sort(&self) { + unsafe { + let r = X509_CRL_sort(self.as_ptr()); + assert!(r == 1); + } + } } /// The result of peer certificate verification.