diff options
| author | Steven Fackler <[email protected]> | 2018-03-28 21:13:50 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2018-03-28 21:13:50 +0200 |
| commit | 020b2384c6ad7f488aad6496a1029443ca12ff8c (patch) | |
| tree | 0c2a598e935280291f2ebb4208a0aac81f147b66 /openssl/src | |
| parent | Merge pull request #884 from sfackler/libressl-27 (diff) | |
| parent | Add Asn1IntegerRef::to_bn (diff) | |
| download | rust-openssl-020b2384c6ad7f488aad6496a1029443ca12ff8c.tar.xz rust-openssl-020b2384c6ad7f488aad6496a1029443ca12ff8c.zip | |
Merge pull request #887 from sfackler/get-serialnumber
Add X509Ref::serial_number
Diffstat (limited to 'openssl/src')
| -rw-r--r-- | openssl/src/asn1.rs | 23 | ||||
| -rw-r--r-- | openssl/src/x509/mod.rs | 13 | ||||
| -rw-r--r-- | openssl/src/x509/tests.rs | 1 |
3 files changed, 31 insertions, 6 deletions
diff --git a/openssl/src/asn1.rs b/openssl/src/asn1.rs index d129235a..f6917aae 100644 --- a/openssl/src/asn1.rs +++ b/openssl/src/asn1.rs @@ -26,7 +26,7 @@ //! ``` use ffi; use foreign_types::{ForeignType, ForeignTypeRef}; -use libc::{c_long, c_char, c_int}; +use libc::{c_char, c_int, c_long}; use std::fmt; use std::ptr; use std::slice; @@ -34,6 +34,7 @@ use std::str; use {cvt, cvt_p}; use bio::MemBio; +use bn::BigNum; use error::ErrorStack; use nid::Nid; use string::OpensslString; @@ -191,14 +192,24 @@ foreign_type_and_impl_send_sync! { } impl Asn1IntegerRef { - /// Returns value of ASN.1 integer, or -1 if there is an error, and 0 if the integer is Null. - /// - /// OpenSSL documentation at [`ASN1_INTEGER_get`]. - /// - /// [`ASN1_INTEGER_get`]: https://www.openssl.org/docs/man1.1.0/crypto/ASN1_INTEGER_get.html + #[allow(missing_docs)] + #[deprecated(since = "0.10.6", note = "use to_bn instead")] pub fn get(&self) -> i64 { unsafe { ::ffi::ASN1_INTEGER_get(self.as_ptr()) as i64 } } + + /// Converts the integer to a `BigNum`. + /// + /// This corresponds to [`ASN1_INTEGER_to_BN`]. + /// + /// [`ASN1_INTEGER_to_BN`]: https://www.openssl.org/docs/man1.1.0/crypto/ASN1_INTEGER_get.html + pub fn to_bn(&self) -> Result<BigNum, ErrorStack> { + unsafe { + cvt_p(::ffi::ASN1_INTEGER_to_BN(self.as_ptr(), ptr::null_mut())) + .map(|p| BigNum::from_ptr(p)) + } + } + /// Sets the ASN.1 value to the value of a signed 32-bit integer, for larger numbers /// see [`bn`]. /// diff --git a/openssl/src/x509/mod.rs b/openssl/src/x509/mod.rs index d4714f88..011a2d96 100644 --- a/openssl/src/x509/mod.rs +++ b/openssl/src/x509/mod.rs @@ -523,6 +523,19 @@ impl X509Ref { } } + /// Returns this certificate's serial number. + /// + /// This corresponds to [`X509_get_serialNumber`]. + /// + /// [`X509_get_serialNumber`]: https://www.openssl.org/docs/man1.1.0/crypto/X509_get_serialNumber.html + pub fn serial_number(&self) -> &Asn1IntegerRef { + unsafe { + let r = ffi::X509_get_serialNumber(self.as_ptr()); + assert!(!r.is_null()); + Asn1IntegerRef::from_ptr(r) + } + } + to_pem! { /// Serializes the certificate into a PEM-encoded X509 structure. /// diff --git a/openssl/src/x509/tests.rs b/openssl/src/x509/tests.rs index ecc7f7de..fa8056ad 100644 --- a/openssl/src/x509/tests.rs +++ b/openssl/src/x509/tests.rs @@ -202,6 +202,7 @@ fn x509_builder() { .next() .unwrap(); assert_eq!("foobar.com".as_bytes(), cn.data().as_slice()); + assert_eq!(serial, x509.serial_number().to_bn().unwrap()); } #[test] |