2
0

t_bitst.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <stdio.h>
  10. #include "internal/cryptlib.h"
  11. #include <openssl/conf.h>
  12. #include <openssl/x509v3.h>
  13. int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
  14. BIT_STRING_BITNAME *tbl, int indent)
  15. {
  16. BIT_STRING_BITNAME *bnam;
  17. char first = 1;
  18. BIO_printf(out, "%*s", indent, "");
  19. for (bnam = tbl; bnam->lname; bnam++) {
  20. if (ASN1_BIT_STRING_get_bit(bs, bnam->bitnum)) {
  21. if (!first)
  22. BIO_puts(out, ", ");
  23. BIO_puts(out, bnam->lname);
  24. first = 0;
  25. }
  26. }
  27. BIO_puts(out, "\n");
  28. return 1;
  29. }
  30. int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, const char *name, int value,
  31. BIT_STRING_BITNAME *tbl)
  32. {
  33. int bitnum;
  34. bitnum = ASN1_BIT_STRING_num_asc(name, tbl);
  35. if (bitnum < 0)
  36. return 0;
  37. if (bs) {
  38. if (!ASN1_BIT_STRING_set_bit(bs, bitnum, value))
  39. return 0;
  40. }
  41. return 1;
  42. }
  43. int ASN1_BIT_STRING_num_asc(const char *name, BIT_STRING_BITNAME *tbl)
  44. {
  45. BIT_STRING_BITNAME *bnam;
  46. for (bnam = tbl; bnam->lname; bnam++) {
  47. if ((strcmp(bnam->sname, name) == 0)
  48. || (strcmp(bnam->lname, name) == 0))
  49. return bnam->bitnum;
  50. }
  51. return -1;
  52. }