x_attrib.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. DEFINE_STACK_OF(ASN1_TYPE)
  16. /*-
  17. * X509_ATTRIBUTE: this has the following form:
  18. *
  19. * typedef struct x509_attributes_st
  20. * {
  21. * ASN1_OBJECT *object;
  22. * STACK_OF(ASN1_TYPE) *set;
  23. * } X509_ATTRIBUTE;
  24. *
  25. */
  26. ASN1_SEQUENCE(X509_ATTRIBUTE) = {
  27. ASN1_SIMPLE(X509_ATTRIBUTE, object, ASN1_OBJECT),
  28. ASN1_SET_OF(X509_ATTRIBUTE, set, ASN1_ANY)
  29. } ASN1_SEQUENCE_END(X509_ATTRIBUTE)
  30. IMPLEMENT_ASN1_FUNCTIONS(X509_ATTRIBUTE)
  31. IMPLEMENT_ASN1_DUP_FUNCTION(X509_ATTRIBUTE)
  32. X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value)
  33. {
  34. X509_ATTRIBUTE *ret = NULL;
  35. ASN1_TYPE *val = NULL;
  36. if ((ret = X509_ATTRIBUTE_new()) == NULL)
  37. return NULL;
  38. ret->object = OBJ_nid2obj(nid);
  39. if ((val = ASN1_TYPE_new()) == NULL)
  40. goto err;
  41. if (!sk_ASN1_TYPE_push(ret->set, val))
  42. goto err;
  43. ASN1_TYPE_set(val, atrtype, value);
  44. return ret;
  45. err:
  46. X509_ATTRIBUTE_free(ret);
  47. ASN1_TYPE_free(val);
  48. return NULL;
  49. }