Add Asn1IntegerRef::to_bn
Also deprecate Asn1IntegerRef since it's just asking for trouble.
This commit is contained in:
parent
7890672725
commit
c82a87a18e
|
|
@ -1655,6 +1655,7 @@ extern "C" {
|
||||||
|
|
||||||
pub fn ASN1_INTEGER_get(dest: *const ASN1_INTEGER) -> c_long;
|
pub fn ASN1_INTEGER_get(dest: *const ASN1_INTEGER) -> c_long;
|
||||||
pub fn ASN1_INTEGER_set(dest: *mut ASN1_INTEGER, value: c_long) -> c_int;
|
pub fn ASN1_INTEGER_set(dest: *mut ASN1_INTEGER, value: c_long) -> c_int;
|
||||||
|
pub fn ASN1_INTEGER_to_BN(ai: *const ASN1_INTEGER, bn: *mut BIGNUM) -> *mut BIGNUM;
|
||||||
pub fn ASN1_GENERALIZEDTIME_free(tm: *mut ASN1_GENERALIZEDTIME);
|
pub fn ASN1_GENERALIZEDTIME_free(tm: *mut ASN1_GENERALIZEDTIME);
|
||||||
pub fn ASN1_GENERALIZEDTIME_print(b: *mut BIO, tm: *const ASN1_GENERALIZEDTIME) -> c_int;
|
pub fn ASN1_GENERALIZEDTIME_print(b: *mut BIO, tm: *const ASN1_GENERALIZEDTIME) -> c_int;
|
||||||
pub fn ASN1_STRING_type_new(ty: c_int) -> *mut ASN1_STRING;
|
pub fn ASN1_STRING_type_new(ty: c_int) -> *mut ASN1_STRING;
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@
|
||||||
//! ```
|
//! ```
|
||||||
use ffi;
|
use ffi;
|
||||||
use foreign_types::{ForeignType, ForeignTypeRef};
|
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::fmt;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
|
@ -34,6 +34,7 @@ use std::str;
|
||||||
|
|
||||||
use {cvt, cvt_p};
|
use {cvt, cvt_p};
|
||||||
use bio::MemBio;
|
use bio::MemBio;
|
||||||
|
use bn::BigNum;
|
||||||
use error::ErrorStack;
|
use error::ErrorStack;
|
||||||
use nid::Nid;
|
use nid::Nid;
|
||||||
use string::OpensslString;
|
use string::OpensslString;
|
||||||
|
|
@ -191,14 +192,24 @@ foreign_type_and_impl_send_sync! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Asn1IntegerRef {
|
impl Asn1IntegerRef {
|
||||||
/// Returns value of ASN.1 integer, or -1 if there is an error, and 0 if the integer is Null.
|
#[allow(missing_docs)]
|
||||||
///
|
#[deprecated(since = "0.10.6", note = "use to_bn instead")]
|
||||||
/// OpenSSL documentation at [`ASN1_INTEGER_get`].
|
|
||||||
///
|
|
||||||
/// [`ASN1_INTEGER_get`]: https://www.openssl.org/docs/man1.1.0/crypto/ASN1_INTEGER_get.html
|
|
||||||
pub fn get(&self) -> i64 {
|
pub fn get(&self) -> i64 {
|
||||||
unsafe { ::ffi::ASN1_INTEGER_get(self.as_ptr()) as 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
|
/// Sets the ASN.1 value to the value of a signed 32-bit integer, for larger numbers
|
||||||
/// see [`bn`].
|
/// see [`bn`].
|
||||||
///
|
///
|
||||||
|
|
|
||||||
|
|
@ -202,6 +202,7 @@ fn x509_builder() {
|
||||||
.next()
|
.next()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!("foobar.com".as_bytes(), cn.data().as_slice());
|
assert_eq!("foobar.com".as_bytes(), cn.data().as_slice());
|
||||||
|
assert_eq!(serial, x509.serial_number().to_bn().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue