Skip to content

Commit 2e6bc97

Browse files
committed
Add X509Extension::data function
This function allows reading extension data bytes.
1 parent 00dacb9 commit 2e6bc97

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

openssl/src/x509/mod.rs

+23
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,29 @@ impl X509ExtensionRef {
10401040
to_der,
10411041
ffi::i2d_X509_EXTENSION
10421042
}
1043+
1044+
/// Returns the field value of an `X509Extension`.
1045+
///
1046+
/// # Examples
1047+
///
1048+
/// ```
1049+
/// use openssl::asn1::{Asn1Object, Asn1OctetString};
1050+
/// use openssl::x509::X509Extension;
1051+
///
1052+
/// let extension = X509Extension::new_from_der(&Asn1Object::from_str("2.999").unwrap(),
1053+
/// true,
1054+
/// &Asn1OctetString::new_from_bytes(b"\x30\x03\x01\x01\xff").unwrap(),
1055+
/// ).unwrap();
1056+
/// let value = extension.data().as_slice();
1057+
/// assert_eq!(value, [48, 3, 1, 1, 255]);
1058+
/// ```
1059+
#[corresponds(X509_EXTENSION_get_data)]
1060+
pub fn data(&self) -> &Asn1OctetStringRef {
1061+
unsafe {
1062+
let data = ffi::X509_EXTENSION_get_data(self.as_ptr());
1063+
Asn1OctetStringRef::from_ptr(data)
1064+
}
1065+
}
10431066
}
10441067

10451068
/// A builder used to construct an `X509Name`.

0 commit comments

Comments
 (0)