Botan 3.13.0
Crypto and TLS for C&
ffi_cert_ext.cpp File Reference
#include <botan/ffi.h>
#include <botan/assert.h>
#include <botan/internal/ffi_cert.h>
#include <botan/internal/ffi_util.h>

Go to the source code of this file.

Functions

int botan_x509_ext_as_blocks_get_entry_at (botan_x509_cert_t cert, int asnum, size_t i, uint32_t *min, uint32_t *max)
int botan_x509_ext_as_blocks_get_info (botan_x509_cert_t cert, int asnum, int *present, size_t *count)
int botan_x509_ext_ip_addr_blocks_get_address (botan_x509_cert_t cert, int ipv6, size_t i, size_t entry, uint8_t min_out[], uint8_t max_out[], size_t *out_len)
int botan_x509_ext_ip_addr_blocks_get_counts (botan_x509_cert_t cert, size_t *v4_count, size_t *v6_count)
int botan_x509_ext_ip_addr_blocks_get_family (botan_x509_cert_t cert, int ipv6, size_t i, int *has_safi, uint8_t *safi, int *present, size_t *count)

Function Documentation

◆ botan_x509_ext_as_blocks_get_entry_at()

int botan_x509_ext_as_blocks_get_entry_at ( botan_x509_cert_t cert,
int asnum,
size_t i,
uint32_t * min,
uint32_t * max )

Get a specific entry in the AS Blocks extension from RFC 3779

Parameters
certthe certificate to inspect
asnumSet to 1 to get info about AS numbers, 0 for RDIs (the type)
iThe index of the entry to get
minis set to the min value of the range
maxis set to the max value of the range
Returns
0 on success, negative number on error

If the extension is not present or an error occurs, min and max are not modified

Definition at line 222 of file ffi_cert_ext.cpp.

222 {
223 if(Botan::any_null_pointers(min, max)) {
225 }
226#if defined(BOTAN_HAS_X509_CERTIFICATES)
227 return ffi_guard_thunk(__func__, [=]() -> int {
228 if(asnum != 0 && asnum != 1) {
230 }
231
232 const auto& ext = safe_get(cert).v3_extensions().get_extension_object_as<Botan::Cert_Extension::ASBlocks>();
233 if(Botan::any_null_pointers(ext)) {
235 }
236
237 const auto& asnum_or_rdi = asnum == 1 ? ext->as_identifiers().asnum() : ext->as_identifiers().rdi();
238 if(!asnum_or_rdi.has_value() || !asnum_or_rdi.value().ranges().has_value()) {
240 }
241
242 const auto& range = asnum_or_rdi.value().ranges().value();
243 if(i >= range.size()) {
245 }
246
247 *min = range.at(i).min();
248 *max = range.at(i).max();
249 return BOTAN_FFI_SUCCESS;
250 });
251#else
252 BOTAN_UNUSED(cert, asnum, i);
254#endif
255}
#define BOTAN_UNUSED
Definition assert.h:144
const std::optional< ASIdentifierChoice > & asnum() const
Definition x509_ext.h:1195
const ASIdentifiers & as_identifiers() const
Definition x509_ext.h:1257
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:138
@ BOTAN_FFI_ERROR_OUT_OF_RANGE
Definition ffi.h:136
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:131
@ BOTAN_FFI_SUCCESS
Definition ffi.h:114
@ BOTAN_FFI_ERROR_NO_VALUE
Definition ffi.h:120
@ BOTAN_FFI_ERROR_BAD_PARAMETER
Definition ffi.h:132
T & safe_get(botan_struct< T, M > *p)
Definition ffi_util.h:79
int ffi_guard_thunk(const char *func_name, T thunk)
Definition ffi_util.h:95
bool any_null_pointers(Ptrs... ptr)
Definition mem_utils.h:54

References Botan::any_null_pointers(), Botan::Cert_Extension::ASBlocks::as_identifiers(), Botan::Cert_Extension::ASBlocks::ASIdentifiers::asnum(), BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_ERROR_OUT_OF_RANGE, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

◆ botan_x509_ext_as_blocks_get_info()

int botan_x509_ext_as_blocks_get_info ( botan_x509_cert_t cert,
int asnum,
int * present,
size_t * count )

Get basic info about the AS Blocks extension from RFC 3779

Parameters
certthe certificate to inspect
asnummust be set to 1 to get info about AS numbers, 0 for RDIs (the type)
presentis set to 1 if the extension contains entries for the type, 0 if it is marked as "inherit"
countis set to number of entries for this type, if it was present, otherwise count is not modified
Returns
0 on success, negative number on error

If the extension is not present or an error occurs, present and count are not modified

Definition at line 183 of file ffi_cert_ext.cpp.

183 {
184 if(Botan::any_null_pointers(present, count)) {
186 }
187#if defined(BOTAN_HAS_X509_CERTIFICATES)
188 return ffi_guard_thunk(__func__, [=]() -> int {
189 if(asnum != 0 && asnum != 1) {
191 }
192
193 const auto& ext = safe_get(cert).v3_extensions().get_extension_object_as<Botan::Cert_Extension::ASBlocks>();
194 if(Botan::any_null_pointers(ext)) {
196 }
197
198 const auto& asnum_or_rdi = asnum == 1 ? ext->as_identifiers().asnum() : ext->as_identifiers().rdi();
199
200 if(!asnum_or_rdi.has_value()) {
202 }
203
204 const auto& ranges = asnum_or_rdi.value().ranges();
205
206 if(!ranges.has_value()) {
207 *present = 0;
208 return BOTAN_FFI_SUCCESS;
209 }
210
211 *present = 1;
212 *count = ranges.value().size();
213
214 return BOTAN_FFI_SUCCESS;
215 });
216#else
217 BOTAN_UNUSED(cert, asnum);
219#endif
220}

References Botan::any_null_pointers(), Botan::Cert_Extension::ASBlocks::as_identifiers(), Botan::Cert_Extension::ASBlocks::ASIdentifiers::asnum(), BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::safe_get().

◆ botan_x509_ext_ip_addr_blocks_get_address()

int botan_x509_ext_ip_addr_blocks_get_address ( botan_x509_cert_t cert,
int ipv6,
size_t i,
size_t entry,
uint8_t min_out[],
uint8_t max_out[],
size_t * out_len )

Get info about a specific range in the IP Address Blocks extension from RFC 3779

Parameters
certthe certificate to inspect
ipv6must be set to 1 if the family is an IPv6 family, 0 for IPv4 families
iis the (local) index of the family, see botan_x509_ext_ip_addr_blocks_get_family
entryis the index of the range
min_outis set to the lower address of the range
max_outis set to the upper address of the range
out_lenis set to the length of the addresses (4 for IPv4, 16 for IPv6)
Returns
0 on success, negative number on error

The output parameters min_out, max_out and out_len may be modified even if the extension is not present or some other error occurs. In this event, the value of each output parameter after the call returns is undefined.

Definition at line 142 of file ffi_cert_ext.cpp.

143 {
144 if(out_len == nullptr) {
146 }
147#if defined(BOTAN_HAS_X509_CERTIFICATES)
148 return ffi_guard_thunk(__func__, [=]() -> int {
149 if(ipv6 != 0 && ipv6 != 1) {
151 }
152
153 const auto& ext =
154 safe_get(cert).v3_extensions().get_extension_object_as<Botan::Cert_Extension::IPAddressBlocks>();
155 if(Botan::any_null_pointers(ext)) {
157 }
158
159 const size_t limit = ipv6 == 0 ? ext->v4_count() : ext->v6_count();
160 if(i >= limit) {
162 }
163
164 const size_t index = ipv6 == 0 ? i : ext->v4_count() + i;
165 const auto& addr_blocks = ext->addr_blocks();
166 const auto& addr_choice = addr_blocks.at(index).addr_choice();
167
168 if(ipv6 == 0) {
169 return ip_addr_blocks_get_address<Botan::Cert_Extension::IPAddressBlocks::Version::IPv4>(
170 addr_choice, entry, min_out, max_out, out_len);
171 } else {
172 return ip_addr_blocks_get_address<Botan::Cert_Extension::IPAddressBlocks::Version::IPv6>(
173 addr_choice, entry, min_out, max_out, out_len);
174 }
175 });
176#else
177 BOTAN_UNUSED(cert, ipv6, i, entry, min_out, max_out);
179#endif
180}
size_t v4_count() const
The number of IPv4 families contained in the extension.
Definition x509_ext.h:1109

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_ERROR_OUT_OF_RANGE, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), and Botan::Cert_Extension::IPAddressBlocks::v4_count().

◆ botan_x509_ext_ip_addr_blocks_get_counts()

int botan_x509_ext_ip_addr_blocks_get_counts ( botan_x509_cert_t cert,
size_t * v4_count,
size_t * v6_count )

Get info about the IP Address Blocks extension from RFC 3779

Parameters
certthe certificate to inspect
v4_countis set to the number of v4 families contained in the extension
v6_countis set to the number of v6 families
Returns
0 on success, negative number on error

If the extension is not present or an error occurs, v4_count and v6_count are not modified

Definition at line 73 of file ffi_cert_ext.cpp.

73 {
74 if(Botan::any_null_pointers(v4_count, v6_count)) {
76 }
77#if defined(BOTAN_HAS_X509_CERTIFICATES)
78 return ffi_guard_thunk(__func__, [=]() -> int {
79 const auto& ext =
80 safe_get(cert).v3_extensions().get_extension_object_as<Botan::Cert_Extension::IPAddressBlocks>();
83 }
84
85 *v4_count = ext->v4_count();
86 *v6_count = ext->v6_count();
87
88 return BOTAN_FFI_SUCCESS;
89 });
90#else
91 BOTAN_UNUSED(cert);
93#endif
94}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), and Botan::Cert_Extension::IPAddressBlocks::v4_count().

◆ botan_x509_ext_ip_addr_blocks_get_family()

int botan_x509_ext_ip_addr_blocks_get_family ( botan_x509_cert_t cert,
int ipv6,
size_t i,
int * has_safi,
uint8_t * safi,
int * present,
size_t * count )

Get info about a specific family in the IP Address Blocks extension from RFC 3779

Parameters
certthe certificate to inspect
ipv6must be set to 1 if the family is an IPv6 family, 0 for IPv4 families
iis the (local) index for this family kind (the first v4 family is at i = 0, ipv6 = 0; the first v6 family is at i = 0, ipv6 = 1)
has_safiwill be set to 1 if the family has an associated SAFI
safiwill be set to the families' SAFI, if it has one, otherwise safi is not modified
presentis set to 1 if the family contains values (ranges), 0 if it is marked as "inherit"
countis set to the number of values (ranges), if they were present, otherwise count is not modified
Returns
0 on success, negative number on error

The output parameters has_safi, safi, present and count may be modified even if the extension is not present or some other error occurs. In this event, the value of each output parameter after the call returns is undefined.

Definition at line 96 of file ffi_cert_ext.cpp.

97 {
98 if(Botan::any_null_pointers(has_safi, safi, present, count)) {
100 }
101#if defined(BOTAN_HAS_X509_CERTIFICATES)
102 return ffi_guard_thunk(__func__, [=]() -> int {
103 if(ipv6 != 0 && ipv6 != 1) {
105 }
106
107 const auto& ext =
108 safe_get(cert).v3_extensions().get_extension_object_as<Botan::Cert_Extension::IPAddressBlocks>();
109 if(Botan::any_null_pointers(ext)) {
111 }
112
113 const size_t limit = ipv6 == 0 ? ext->v4_count() : ext->v6_count();
114 if(i >= limit) {
116 }
117
118 const size_t index = ipv6 == 0 ? i : ext->v4_count() + i;
119 const auto& addr_blocks = ext->addr_blocks();
120 const auto& family = addr_blocks.at(index);
121 if(family.safi().has_value()) {
122 *has_safi = 1;
123 *safi = family.safi().value();
124 } else {
125 *has_safi = 0;
126 }
127
128 if(ipv6 == 0) {
129 return ip_addr_blocks_get_family<Botan::Cert_Extension::IPAddressBlocks::Version::IPv4>(
130 family, present, count);
131 } else {
132 return ip_addr_blocks_get_family<Botan::Cert_Extension::IPAddressBlocks::Version::IPv6>(
133 family, present, count);
134 }
135 });
136#else
137 BOTAN_UNUSED(cert, ipv6, i);
139#endif
140}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NO_VALUE, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_ERROR_OUT_OF_RANGE, BOTAN_UNUSED, Botan_FFI::ffi_guard_thunk(), Botan_FFI::safe_get(), Botan::Cert_Extension::IPAddressBlocks::IPAddressFamily::safi(), and Botan::Cert_Extension::IPAddressBlocks::v4_count().