@@ -24,7 +24,7 @@ use std::slice;
24
24
use std:: str;
25
25
26
26
use crate :: asn1:: {
27
- Asn1BitStringRef , Asn1Enumerated , Asn1IntegerRef , Asn1Object , Asn1ObjectRef ,
27
+ Asn1BitStringRef , Asn1Enumerated , Asn1Integer , Asn1IntegerRef , Asn1Object , Asn1ObjectRef ,
28
28
Asn1OctetStringRef , Asn1StringRef , Asn1Time , Asn1TimeRef , Asn1Type ,
29
29
} ;
30
30
use crate :: bio:: MemBioSlice ;
@@ -1902,6 +1902,51 @@ impl X509Crl {
1902
1902
}
1903
1903
}
1904
1904
1905
+ /// Read the value of the crl_number extensions.
1906
+ /// Returns None if the extension is not present.
1907
+ pub fn read_crl_number ( & self ) -> Result < Option < i64 > , ErrorStack > {
1908
+ unsafe {
1909
+ let mut crit = 0 ;
1910
+ let number = Asn1Integer :: from_ptr_opt ( std:: mem:: transmute ( ffi:: X509_CRL_get_ext_d2i (
1911
+ self . as_ptr ( ) ,
1912
+ ffi:: NID_crl_number ,
1913
+ & mut crit,
1914
+ std:: ptr:: null_mut ( ) ,
1915
+ ) ) ) ;
1916
+ match number {
1917
+ None => {
1918
+ if crit == -1 {
1919
+ // extension was not found
1920
+ Ok ( None )
1921
+ } else {
1922
+ Err ( ErrorStack :: get ( ) )
1923
+ }
1924
+ }
1925
+
1926
+ Some ( number) => Ok ( Some ( ffi:: ASN1_INTEGER_get ( number. as_ptr ( ) ) ) ) ,
1927
+ }
1928
+ }
1929
+ }
1930
+
1931
+ /// Set the crl_number extension's value.
1932
+ /// If the extension is not present, it will be added.
1933
+ pub fn set_crl_number ( & mut self , value : i64 ) -> Result < ( ) , ErrorStack > {
1934
+ unsafe {
1935
+ let number = ffi:: ASN1_INTEGER_new ( ) ;
1936
+ let number = Asn1Integer :: from_ptr ( number) ;
1937
+ cvt ( ffi:: ASN1_INTEGER_set ( number. as_ptr ( ) , value) ) ?;
1938
+
1939
+ cvt ( ffi:: X509_CRL_add1_ext_i2d (
1940
+ self . as_ptr ( ) ,
1941
+ ffi:: NID_crl_number ,
1942
+ std:: mem:: transmute ( number. as_ptr ( ) ) ,
1943
+ 0 ,
1944
+ ffi:: X509V3_ADD_REPLACE ,
1945
+ ) )
1946
+ . map ( |_| ( ) )
1947
+ }
1948
+ }
1949
+
1905
1950
/// Revoke the given certificate.
1906
1951
/// This function won't produce duplicate entries in case the certificate was already revoked.
1907
1952
/// Sets the CRL's last_updated time to the current time before returning irregardless of the given certificate.
0 commit comments