Skip to content

Commit 61610ef

Browse files
committed
Add X509Extension::data function
This function allows reading extension data bytes.
1 parent 5095d7d commit 61610ef

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
@@ -1056,6 +1056,29 @@ impl X509ExtensionRef {
10561056
to_der,
10571057
ffi::i2d_X509_EXTENSION
10581058
}
1059+
1060+
/// Returns the field value of an `X509Extension`.
1061+
///
1062+
/// # Examples
1063+
///
1064+
/// ```
1065+
/// use openssl::asn1::{Asn1Object, Asn1OctetString};
1066+
/// use openssl::x509::X509Extension;
1067+
///
1068+
/// let extension = X509Extension::new_from_der(&Asn1Object::from_str("2.999").unwrap(),
1069+
/// true,
1070+
/// &Asn1OctetString::new_from_bytes(b"\x30\x03\x01\x01\xff").unwrap(),
1071+
/// ).unwrap();
1072+
/// let value = extension.data().as_slice();
1073+
/// assert_eq!(value, [48, 3, 1, 1, 255]);
1074+
/// ```
1075+
#[corresponds(X509_EXTENSION_get_data)]
1076+
pub fn data(&self) -> &Asn1OctetStringRef {
1077+
unsafe {
1078+
let data = ffi::X509_EXTENSION_get_data(self.as_ptr());
1079+
Asn1OctetStringRef::from_ptr(data)
1080+
}
1081+
}
10591082
}
10601083

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

0 commit comments

Comments
 (0)