summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/a_bitstr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/asn1/a_bitstr.c')
-rw-r--r--src/lib/libcrypto/asn1/a_bitstr.c53
1 files changed, 52 insertions, 1 deletions
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c
index f217f13d27..68cefee4a2 100644
--- a/src/lib/libcrypto/asn1/a_bitstr.c
+++ b/src/lib/libcrypto/asn1/a_bitstr.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_bitstr.c,v 1.30 2020/09/03 17:19:27 tb Exp $ */ 1/* $OpenBSD: a_bitstr.c,v 1.31 2021/12/15 18:00:31 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -60,7 +60,9 @@
60#include <string.h> 60#include <string.h>
61 61
62#include <openssl/asn1.h> 62#include <openssl/asn1.h>
63#include <openssl/conf.h>
63#include <openssl/err.h> 64#include <openssl/err.h>
65#include <openssl/x509v3.h>
64 66
65int 67int
66ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len) 68ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len)
@@ -262,3 +264,52 @@ ASN1_BIT_STRING_check(const ASN1_BIT_STRING *a, const unsigned char *flags,
262 } 264 }
263 return ok; 265 return ok;
264} 266}
267
268int
269ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
270 BIT_STRING_BITNAME *tbl, int indent)
271{
272 BIT_STRING_BITNAME *bnam;
273 char first = 1;
274
275 BIO_printf(out, "%*s", indent, "");
276 for (bnam = tbl; bnam->lname; bnam++) {
277 if (ASN1_BIT_STRING_get_bit(bs, bnam->bitnum)) {
278 if (!first)
279 BIO_puts(out, ", ");
280 BIO_puts(out, bnam->lname);
281 first = 0;
282 }
283 }
284 BIO_puts(out, "\n");
285 return 1;
286}
287
288int
289ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, const char *name, int value,
290 BIT_STRING_BITNAME *tbl)
291{
292 int bitnum;
293
294 bitnum = ASN1_BIT_STRING_num_asc(name, tbl);
295 if (bitnum < 0)
296 return 0;
297 if (bs) {
298 if (!ASN1_BIT_STRING_set_bit(bs, bitnum, value))
299 return 0;
300 }
301 return 1;
302}
303
304int
305ASN1_BIT_STRING_num_asc(const char *name, BIT_STRING_BITNAME *tbl)
306{
307 BIT_STRING_BITNAME *bnam;
308
309 for (bnam = tbl; bnam->lname; bnam++) {
310 if (!strcmp(bnam->sname, name) ||
311 !strcmp(bnam->lname, name))
312 return bnam->bitnum;
313 }
314 return -1;
315}