OCTET_STRING.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*-
  2. * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
  3. * Redistribution and modifications are permitted subject to BSD license.
  4. */
  5. #ifndef _OCTET_STRING_H_
  6. #define _OCTET_STRING_H_
  7. #include <asn_application.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. typedef struct OCTET_STRING {
  12. uint8_t *buf; /* Buffer with consecutive OCTET_STRING bits */
  13. size_t size; /* Size of the buffer */
  14. asn_struct_ctx_t _asn_ctx; /* Parsing across buffer boundaries */
  15. } OCTET_STRING_t;
  16. extern asn_TYPE_descriptor_t asn_DEF_OCTET_STRING;
  17. extern asn_TYPE_operation_t asn_OP_OCTET_STRING;
  18. asn_struct_free_f OCTET_STRING_free;
  19. asn_struct_print_f OCTET_STRING_print;
  20. asn_struct_print_f OCTET_STRING_print_utf8;
  21. asn_struct_compare_f OCTET_STRING_compare;
  22. ber_type_decoder_f OCTET_STRING_decode_ber;
  23. der_type_encoder_f OCTET_STRING_encode_der;
  24. xer_type_decoder_f OCTET_STRING_decode_xer_hex; /* Hexadecimal */
  25. xer_type_decoder_f OCTET_STRING_decode_xer_binary; /* 01010111010 */
  26. xer_type_decoder_f OCTET_STRING_decode_xer_utf8; /* ASCII/UTF-8 */
  27. xer_type_encoder_f OCTET_STRING_encode_xer;
  28. xer_type_encoder_f OCTET_STRING_encode_xer_utf8;
  29. oer_type_decoder_f OCTET_STRING_decode_oer;
  30. oer_type_encoder_f OCTET_STRING_encode_oer;
  31. per_type_decoder_f OCTET_STRING_decode_uper;
  32. per_type_encoder_f OCTET_STRING_encode_uper;
  33. asn_random_fill_f OCTET_STRING_random_fill;
  34. #define OCTET_STRING_constraint asn_generic_no_constraint
  35. #define OCTET_STRING_decode_xer OCTET_STRING_decode_xer_hex
  36. /******************************
  37. * Handy conversion routines. *
  38. ******************************/
  39. /*
  40. * This function clears the previous value of the OCTET STRING (if any)
  41. * and then allocates a new memory with the specified content (str/size).
  42. * If size = -1, the size of the original string will be determined
  43. * using strlen(str).
  44. * If str equals to NULL, the function will silently clear the
  45. * current contents of the OCTET STRING.
  46. * Returns 0 if it was possible to perform operation, -1 otherwise.
  47. */
  48. int OCTET_STRING_fromBuf(OCTET_STRING_t *s, const char *str, int size);
  49. /* Handy conversion from the C string into the OCTET STRING. */
  50. #define OCTET_STRING_fromString(s, str) OCTET_STRING_fromBuf(s, str, -1)
  51. /*
  52. * Allocate and fill the new OCTET STRING and return a pointer to the newly
  53. * allocated object. NULL is permitted in str: the function will just allocate
  54. * empty OCTET STRING.
  55. */
  56. OCTET_STRING_t *OCTET_STRING_new_fromBuf(const asn_TYPE_descriptor_t *td,
  57. const char *str, int size);
  58. /****************************
  59. * Internally useful stuff. *
  60. ****************************/
  61. typedef struct asn_OCTET_STRING_specifics_s {
  62. /*
  63. * Target structure description.
  64. */
  65. unsigned struct_size; /* Size of the structure */
  66. unsigned ctx_offset; /* Offset of the asn_struct_ctx_t member */
  67. enum asn_OS_Subvariant {
  68. ASN_OSUBV_ANY, /* The open type (ANY) */
  69. ASN_OSUBV_BIT, /* BIT STRING */
  70. ASN_OSUBV_STR, /* String types, not {BMP,Universal}String */
  71. ASN_OSUBV_U16, /* 16-bit character (BMPString) */
  72. ASN_OSUBV_U32 /* 32-bit character (UniversalString) */
  73. } subvariant;
  74. } asn_OCTET_STRING_specifics_t;
  75. extern asn_OCTET_STRING_specifics_t asn_SPC_OCTET_STRING_specs;
  76. size_t OCTET_STRING_random_length_constrained(
  77. const asn_TYPE_descriptor_t *, const asn_encoding_constraints_t *,
  78. size_t max_length);
  79. #ifdef __cplusplus
  80. }
  81. #endif
  82. #endif /* _OCTET_STRING_H_ */