Commit e073b4d2 authored by Zhang Jingqiang's avatar Zhang Jingqiang
Browse files

add more x509 extension helper functions

parent 0c50e4a4
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -102,6 +102,14 @@ extern "C" {
    pub fn X509_get_key_usage(x: *mut X509) -> u32;
    #[cfg(ossl110)]
    pub fn X509_get_extended_key_usage(x: *mut X509) -> u32;
    #[cfg(ossl110)]
    pub fn X509_get0_subject_key_id(x: *mut X509) -> *const ASN1_OCTET_STRING;
    #[cfg(ossl110)]
    pub fn X509_get0_authority_key_id(x: *mut X509) -> *const ASN1_OCTET_STRING;
    #[cfg(ossl110)]
    pub fn X509_get0_authority_issuer(x: *mut X509) -> *const stack_st_GENERAL_NAME;
    #[cfg(ossl110)]
    pub fn X509_get0_authority_serial(x: *mut X509) -> *const ASN1_INTEGER;
}

#[repr(C)]
+40 −0
Original line number Diff line number Diff line
@@ -483,6 +483,46 @@ impl X509Ref {
        }
    }

    /// Returns this certificate's subject key id, if it exists.
    #[corresponds(X509_get0_subject_key_id)]
    #[cfg(ossl110)]
    pub fn subject_key_id(&self) -> Option<&Asn1StringRef> {
        unsafe {
            let data = ffi::X509_get0_subject_key_id(self.as_ptr());
            Asn1StringRef::from_const_ptr_opt(data as *const _)
        }
    }

    /// Returns this certificate's authority key id, if it exists.
    #[corresponds(X509_get0_authority_key_id)]
    #[cfg(ossl110)]
    pub fn authority_key_id(&self) -> Option<&Asn1StringRef> {
        unsafe {
            let data = ffi::X509_get0_authority_key_id(self.as_ptr());
            Asn1StringRef::from_const_ptr_opt(data as *const _)
        }
    }

    /// Returns this certificate's authority issuer name entries, if they exist.
    #[corresponds(X509_get0_authority_issuer)]
    #[cfg(ossl110)]
    pub fn authority_issuer(&self) -> Option<Stack<GeneralName>> {
        unsafe {
            let stack = ffi::X509_get0_authority_issuer(self.as_ptr());
            Stack::from_ptr_opt(stack as *mut _)
        }
    }

    /// Returns this certificate's authority serial number, if it exists.
    #[corresponds(X509_get0_authority_serial)]
    #[cfg(ossl110)]
    pub fn authority_serial(&self) -> Option<&Asn1IntegerRef> {
        unsafe {
            let r = ffi::X509_get0_authority_serial(self.as_ptr());
            Asn1IntegerRef::from_const_ptr_opt(r)
        }
    }

    #[corresponds(X509_get_pubkey)]
    pub fn public_key(&self) -> Result<PKey<Public>, ErrorStack> {
        unsafe {