tasn_typ.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2000-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 <openssl/asn1.h>
  11. #include <openssl/asn1t.h>
  12. /* Declarations for string types */
  13. #define IMPLEMENT_ASN1_STRING_FUNCTIONS(sname) \
  14. IMPLEMENT_ASN1_TYPE(sname) \
  15. IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(sname, sname, sname) \
  16. sname *sname##_new(void) \
  17. { \
  18. return ASN1_STRING_type_new(V_##sname); \
  19. } \
  20. void sname##_free(sname *x) \
  21. { \
  22. ASN1_STRING_free(x); \
  23. }
  24. IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_OCTET_STRING)
  25. IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_INTEGER)
  26. IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_ENUMERATED)
  27. IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_BIT_STRING)
  28. IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UTF8STRING)
  29. IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_PRINTABLESTRING)
  30. IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_T61STRING)
  31. IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_IA5STRING)
  32. IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_GENERALSTRING)
  33. IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UTCTIME)
  34. IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_GENERALIZEDTIME)
  35. IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_VISIBLESTRING)
  36. IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UNIVERSALSTRING)
  37. IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_BMPSTRING)
  38. IMPLEMENT_ASN1_TYPE(ASN1_NULL)
  39. IMPLEMENT_ASN1_FUNCTIONS(ASN1_NULL)
  40. IMPLEMENT_ASN1_TYPE(ASN1_OBJECT)
  41. IMPLEMENT_ASN1_TYPE(ASN1_ANY)
  42. /* Just swallow an ASN1_SEQUENCE in an ASN1_STRING */
  43. IMPLEMENT_ASN1_TYPE(ASN1_SEQUENCE)
  44. IMPLEMENT_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
  45. /* Multistring types */
  46. IMPLEMENT_ASN1_MSTRING(ASN1_PRINTABLE, B_ASN1_PRINTABLE)
  47. IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE)
  48. IMPLEMENT_ASN1_MSTRING(DISPLAYTEXT, B_ASN1_DISPLAYTEXT)
  49. IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT)
  50. IMPLEMENT_ASN1_MSTRING(DIRECTORYSTRING, B_ASN1_DIRECTORYSTRING)
  51. IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING)
  52. /* Three separate BOOLEAN type: normal, DEFAULT TRUE and DEFAULT FALSE */
  53. IMPLEMENT_ASN1_TYPE_ex(ASN1_BOOLEAN, ASN1_BOOLEAN, -1)
  54. IMPLEMENT_ASN1_TYPE_ex(ASN1_TBOOLEAN, ASN1_BOOLEAN, 1)
  55. IMPLEMENT_ASN1_TYPE_ex(ASN1_FBOOLEAN, ASN1_BOOLEAN, 0)
  56. /* Special, OCTET STRING with indefinite length constructed support */
  57. IMPLEMENT_ASN1_TYPE_ex(ASN1_OCTET_STRING_NDEF, ASN1_OCTET_STRING, ASN1_TFLG_NDEF)
  58. ASN1_ITEM_TEMPLATE(ASN1_SEQUENCE_ANY) =
  59. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, ASN1_SEQUENCE_ANY, ASN1_ANY)
  60. ASN1_ITEM_TEMPLATE_END(ASN1_SEQUENCE_ANY)
  61. ASN1_ITEM_TEMPLATE(ASN1_SET_ANY) =
  62. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0, ASN1_SET_ANY, ASN1_ANY)
  63. ASN1_ITEM_TEMPLATE_END(ASN1_SET_ANY)
  64. IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(ASN1_SEQUENCE_ANY, ASN1_SEQUENCE_ANY, ASN1_SEQUENCE_ANY)
  65. IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(ASN1_SEQUENCE_ANY, ASN1_SET_ANY, ASN1_SET_ANY)