Skip to content

Commit 6f560f0

Browse files
committed
Add X509Extension::data function
This function allows reading extension data bytes.
1 parent 51fc569 commit 6f560f0

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
@@ -1038,6 +1038,29 @@ impl X509ExtensionRef {
10381038
to_der,
10391039
ffi::i2d_X509_EXTENSION
10401040
}
1041+
1042+
/// Returns the field value of an `X509Extension`.
1043+
///
1044+
/// # Examples
1045+
///
1046+
/// ```
1047+
/// use openssl::asn1::{Asn1Object, Asn1OctetString};
1048+
/// use openssl::x509::X509Extension;
1049+
///
1050+
/// let extension = X509Extension::new_from_der(&Asn1Object::from_str("2.999").unwrap(),
1051+
/// true,
1052+
/// &Asn1OctetString::new_from_bytes(b"\x30\x03\x01\x01\xff").unwrap(),
1053+
/// ).unwrap();
1054+
/// let value = extension.data().as_slice();
1055+
/// assert_eq!(value, [48, 3, 1, 1, 255]);
1056+
/// ```
1057+
#[corresponds(X509_EXTENSION_get_data)]
1058+
pub fn data(&self) -> &Asn1OctetStringRef {
1059+
unsafe {
1060+
let data = ffi::X509_EXTENSION_get_data(self.as_ptr());
1061+
Asn1OctetStringRef::from_ptr(data)
1062+
}
1063+
}
10411064
}
10421065

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

0 commit comments

Comments
 (0)