Skip to content

Commit

Permalink
mark supported OpenSSL version range
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Theil <[email protected]>
  • Loading branch information
thillux committed Oct 12, 2023
1 parent cc555a8 commit d759114
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
14 changes: 13 additions & 1 deletion openssl/src/x509/sbgp.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
use std::mem::MaybeUninit;

#[cfg(ossl110)]
use ffi::{
ASIdOrRange_id, ASIdOrRange_range, ASIdentifierChoice_asIdsOrRanges,
ASIdentifierChoice_inherit, IPAddressChoice_addressesOrRanges, X509v3_addr_get_afi,
X509v3_addr_get_range, ASN1_INTEGER, IANA_AFI_IPV4, IANA_AFI_IPV6,
};
#[cfg(ossl110)]
use foreign_types::{ForeignType, ForeignTypeRef};

#[cfg(ossl110)]
use crate::{
asn1::Asn1IntegerRef,
stack::{Stack, StackRef, Stackable},
util::{ForeignTypeExt, ForeignTypeRefExt},
};

#[cfg(ossl110)]
use super::X509;

#[cfg(ossl110)]
foreign_type_and_impl_send_sync! {
type CType = ffi::ASIdOrRange;
fn drop = ffi::ASIdOrRange_free;
Expand All @@ -24,11 +29,12 @@ foreign_type_and_impl_send_sync! {
/// Reference to `ASIdOrRange`.
pub struct ASIdOrRangeRef;
}

#[cfg(ossl110)]
impl Stackable for ASIdOrRange {
type StackType = ffi::stack_st_ASIdOrRange;
}

#[cfg(ossl110)]
foreign_type_and_impl_send_sync! {
type CType = ffi::ASIdentifiers;
fn drop = ffi::ASIdentifiers_free;
Expand All @@ -39,6 +45,7 @@ foreign_type_and_impl_send_sync! {
pub struct ASIdentifiersRef;
}

#[cfg(ossl110)]
impl ASIdentifiers {
pub fn inherited(&self) -> bool {
unsafe {
Expand Down Expand Up @@ -109,16 +116,19 @@ foreign_type_and_impl_send_sync! {
pub struct IPAddressFamilyRef;
}

#[cfg(ossl110)]
impl Stackable for IPAddressFamily {
type StackType = ffi::stack_st_IPAddressFamily;
}

#[derive(PartialEq, Eq, Debug)]
#[cfg(ossl110)]
pub enum IPVersion {
V4,
V6,
}

#[cfg(ossl110)]
impl IPAddressFamily {
pub fn fam(&self) -> Option<IPVersion> {
let ptr = self.0;
Expand Down Expand Up @@ -180,11 +190,13 @@ impl IPAddressFamily {
}
}

#[cfg(ossl110)]
pub trait ExtractSBGPInfo {
fn asn(&self) -> Option<ASIdentifiers>;
fn ip_addresses(&self) -> Option<Stack<IPAddressFamily>>;
}

#[cfg(ossl110)]
impl ExtractSBGPInfo for X509 {
fn asn(&self) -> Option<ASIdentifiers> {
unsafe {
Expand Down
13 changes: 11 additions & 2 deletions openssl/src/x509/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::cmp::Ordering;
#[cfg(ossl110)]
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
#[cfg(ossl110)]
use std::str::FromStr;

use crate::asn1::{Asn1Object, Asn1OctetString, Asn1Time};
Expand All @@ -12,9 +14,14 @@ use crate::rsa::Rsa;
use crate::ssl::SslFiletype;
use crate::stack::Stack;
use crate::x509::extension::{
AuthorityKeyIdentifier, BasicConstraints, ExtendedKeyUsage, KeyUsage, SbgpAsIdentifier,
SbgpIpAddressIdentifier, SubjectAlternativeName, SubjectKeyIdentifier,
AuthorityKeyIdentifier, BasicConstraints, ExtendedKeyUsage, KeyUsage,
SubjectAlternativeName, SubjectKeyIdentifier,
};
#[cfg(ossl110)]
use crate::x509::extension::{
SbgpAsIdentifier, SbgpIpAddressIdentifier,
};
#[cfg(ossl110)]
use crate::x509::sbgp::ExtractSBGPInfo;
#[cfg(not(boringssl))]
use crate::x509::store::X509Lookup;
Expand Down Expand Up @@ -1182,6 +1189,7 @@ fn test_dist_point_null() {
}

#[test]
#[cfg(ossl110)]
fn test_sbgp_extensions_parsing() {
let cert = include_bytes!("../../test/rfc3779.pem");
let cert = X509::from_pem(cert).unwrap();
Expand Down Expand Up @@ -1210,6 +1218,7 @@ fn test_sbgp_extensions_parsing() {
}

#[test]
#[cfg(ossl110)]
fn test_sbgp_extensions_builder() {
let mut builder = X509Builder::new().unwrap();
let asn_ext = SbgpAsIdentifier::new()
Expand Down

0 comments on commit d759114

Please sign in to comment.