VisibleString.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*-
  2. * Copyright (c) 2003, 2006 Lev Walkin <vlm@lionet.info>. All rights reserved.
  3. * Redistribution and modifications are permitted subject to BSD license.
  4. */
  5. #include <asn_internal.h>
  6. #include <VisibleString.h>
  7. /*
  8. * VisibleString basic type description.
  9. */
  10. static const ber_tlv_tag_t asn_DEF_VisibleString_tags[] = {
  11. (ASN_TAG_CLASS_UNIVERSAL | (26 << 2)), /* [UNIVERSAL 26] IMPLICIT ...*/
  12. (ASN_TAG_CLASS_UNIVERSAL | (4 << 2)) /* ... OCTET STRING */
  13. };
  14. static asn_per_constraints_t asn_DEF_VisibleString_constraints = {
  15. { APC_CONSTRAINED, 7, 7, 0x20, 0x7e }, /* Value */
  16. { APC_SEMI_CONSTRAINED, -1, -1, 0, 0 }, /* Size */
  17. 0, 0
  18. };
  19. asn_TYPE_operation_t asn_OP_VisibleString = {
  20. OCTET_STRING_free,
  21. OCTET_STRING_print_utf8, /* ASCII subset */
  22. OCTET_STRING_compare,
  23. OCTET_STRING_decode_ber, /* Implemented in terms of OCTET STRING */
  24. OCTET_STRING_encode_der,
  25. OCTET_STRING_decode_xer_utf8,
  26. OCTET_STRING_encode_xer_utf8,
  27. #ifdef ASN_DISABLE_OER_SUPPORT
  28. 0,
  29. 0,
  30. #else
  31. OCTET_STRING_decode_oer,
  32. OCTET_STRING_encode_oer,
  33. #endif /* ASN_DISABLE_OER_SUPPORT */
  34. #ifdef ASN_DISABLE_PER_SUPPORT
  35. 0,
  36. 0,
  37. #else
  38. OCTET_STRING_decode_uper,
  39. OCTET_STRING_encode_uper,
  40. #endif /* ASN_DISABLE_PER_SUPPORT */
  41. OCTET_STRING_random_fill,
  42. 0 /* Use generic outmost tag fetcher */
  43. };
  44. asn_TYPE_descriptor_t asn_DEF_VisibleString = {
  45. "VisibleString",
  46. "VisibleString",
  47. &asn_OP_VisibleString,
  48. asn_DEF_VisibleString_tags,
  49. sizeof(asn_DEF_VisibleString_tags)
  50. / sizeof(asn_DEF_VisibleString_tags[0]) - 1,
  51. asn_DEF_VisibleString_tags,
  52. sizeof(asn_DEF_VisibleString_tags)
  53. / sizeof(asn_DEF_VisibleString_tags[0]),
  54. { 0, &asn_DEF_VisibleString_constraints, VisibleString_constraint },
  55. 0, 0, /* No members */
  56. 0 /* No specifics */
  57. };
  58. int
  59. VisibleString_constraint(const asn_TYPE_descriptor_t *td, const void *sptr,
  60. asn_app_constraint_failed_f *ctfailcb, void *app_key) {
  61. const VisibleString_t *st = (const VisibleString_t *)sptr;
  62. if(st && st->buf) {
  63. uint8_t *buf = st->buf;
  64. uint8_t *end = buf + st->size;
  65. /*
  66. * Check the alphabet of the VisibleString.
  67. * ISO646, ISOReg#6
  68. * The alphabet is a subset of ASCII between the space
  69. * and "~" (tilde).
  70. */
  71. for(; buf < end; buf++) {
  72. if(*buf < 0x20 || *buf > 0x7e) {
  73. ASN__CTFAIL(app_key, td, sptr,
  74. "%s: value byte %ld (%d) "
  75. "not in VisibleString alphabet (%s:%d)",
  76. td->name,
  77. (long)((buf - st->buf) + 1),
  78. *buf,
  79. __FILE__, __LINE__);
  80. return -1;
  81. }
  82. }
  83. } else {
  84. ASN__CTFAIL(app_key, td, sptr,
  85. "%s: value not given (%s:%d)",
  86. td->name, __FILE__, __LINE__);
  87. return -1;
  88. }
  89. return 0;
  90. }