2
0

x_attrib.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright 1995-2020 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/objects.h>
  12. #include <openssl/asn1t.h>
  13. #include <openssl/x509.h>
  14. #include "x509_local.h"
  15. /*-
  16. * X509_ATTRIBUTE: this has the following form:
  17. *
  18. * typedef struct x509_attributes_st
  19. * {
  20. * ASN1_OBJECT *object;
  21. * STACK_OF(ASN1_TYPE) *set;
  22. * } X509_ATTRIBUTE;
  23. *
  24. */
  25. ASN1_SEQUENCE(X509_ATTRIBUTE) = {
  26. ASN1_SIMPLE(X509_ATTRIBUTE, object, ASN1_OBJECT),
  27. ASN1_SET_OF(X509_ATTRIBUTE, set, ASN1_ANY)
  28. } ASN1_SEQUENCE_END(X509_ATTRIBUTE)
  29. IMPLEMENT_ASN1_FUNCTIONS(X509_ATTRIBUTE)
  30. IMPLEMENT_ASN1_DUP_FUNCTION(X509_ATTRIBUTE)
  31. X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value)
  32. {
  33. X509_ATTRIBUTE *ret = NULL;
  34. ASN1_TYPE *val = NULL;
  35. ASN1_OBJECT *oid;
  36. if ((oid = OBJ_nid2obj(nid)) == NULL)
  37. return NULL;
  38. if ((ret = X509_ATTRIBUTE_new()) == NULL)
  39. return NULL;
  40. ret->object = oid;
  41. if ((val = ASN1_TYPE_new()) == NULL)
  42. goto err;
  43. if (!sk_ASN1_TYPE_push(ret->set, val))
  44. goto err;
  45. ASN1_TYPE_set(val, atrtype, value);
  46. return ret;
  47. err:
  48. X509_ATTRIBUTE_free(ret);
  49. ASN1_TYPE_free(val);
  50. return NULL;
  51. }