From b0066f471a155d11d682f7884a5ac0562ff39bd0 Mon Sep 17 00:00:00 2001 From: Michael Rossberg Date: Wed, 15 Nov 2023 21:39:24 +0100 Subject: [PATCH] more functions mocked --- openssl/src/x509/mod.rs | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs index d242a818d..4782f18a9 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. -- GitLab