asn1_ber_bytecode.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* ASN.1 BER/DER/CER parsing state machine internal definitions
  2. *
  3. * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #ifndef _LINUX_ASN1_BER_BYTECODE_H
  12. #define _LINUX_ASN1_BER_BYTECODE_H
  13. #ifdef __KERNEL__
  14. #include <linux/types.h>
  15. #endif
  16. #include <linux/asn1.h>
  17. typedef int (*asn1_action_t)(void *context,
  18. size_t hdrlen, /* In case of ANY type */
  19. unsigned char tag, /* In case of ANY type */
  20. const void *value, size_t vlen);
  21. struct asn1_decoder {
  22. const unsigned char *machine;
  23. size_t machlen;
  24. const asn1_action_t *actions;
  25. };
  26. enum asn1_opcode {
  27. /* The tag-matching ops come first and the odd-numbered slots
  28. * are for OR_SKIP ops.
  29. */
  30. #define ASN1_OP_MATCH__SKIP 0x01
  31. #define ASN1_OP_MATCH__ACT 0x02
  32. #define ASN1_OP_MATCH__JUMP 0x04
  33. #define ASN1_OP_MATCH__ANY 0x08
  34. #define ASN1_OP_MATCH__COND 0x10
  35. ASN1_OP_MATCH = 0x00,
  36. ASN1_OP_MATCH_OR_SKIP = 0x01,
  37. ASN1_OP_MATCH_ACT = 0x02,
  38. ASN1_OP_MATCH_ACT_OR_SKIP = 0x03,
  39. ASN1_OP_MATCH_JUMP = 0x04,
  40. ASN1_OP_MATCH_JUMP_OR_SKIP = 0x05,
  41. ASN1_OP_MATCH_ANY = 0x08,
  42. ASN1_OP_MATCH_ANY_OR_SKIP = 0x09,
  43. ASN1_OP_MATCH_ANY_ACT = 0x0a,
  44. ASN1_OP_MATCH_ANY_ACT_OR_SKIP = 0x0b,
  45. /* Everything before here matches unconditionally */
  46. ASN1_OP_COND_MATCH_OR_SKIP = 0x11,
  47. ASN1_OP_COND_MATCH_ACT_OR_SKIP = 0x13,
  48. ASN1_OP_COND_MATCH_JUMP_OR_SKIP = 0x15,
  49. ASN1_OP_COND_MATCH_ANY = 0x18,
  50. ASN1_OP_COND_MATCH_ANY_OR_SKIP = 0x19,
  51. ASN1_OP_COND_MATCH_ANY_ACT = 0x1a,
  52. ASN1_OP_COND_MATCH_ANY_ACT_OR_SKIP = 0x1b,
  53. /* Everything before here will want a tag from the data */
  54. #define ASN1_OP__MATCHES_TAG ASN1_OP_COND_MATCH_ANY_ACT_OR_SKIP
  55. /* These are here to help fill up space */
  56. ASN1_OP_COND_FAIL = 0x1c,
  57. ASN1_OP_COMPLETE = 0x1d,
  58. ASN1_OP_ACT = 0x1e,
  59. ASN1_OP_MAYBE_ACT = 0x1f,
  60. /* The following eight have bit 0 -> SET, 1 -> OF, 2 -> ACT */
  61. ASN1_OP_END_SEQ = 0x20,
  62. ASN1_OP_END_SET = 0x21,
  63. ASN1_OP_END_SEQ_OF = 0x22,
  64. ASN1_OP_END_SET_OF = 0x23,
  65. ASN1_OP_END_SEQ_ACT = 0x24,
  66. ASN1_OP_END_SET_ACT = 0x25,
  67. ASN1_OP_END_SEQ_OF_ACT = 0x26,
  68. ASN1_OP_END_SET_OF_ACT = 0x27,
  69. #define ASN1_OP_END__SET 0x01
  70. #define ASN1_OP_END__OF 0x02
  71. #define ASN1_OP_END__ACT 0x04
  72. ASN1_OP_RETURN = 0x28,
  73. ASN1_OP__NR
  74. };
  75. #define _tag(CLASS, CP, TAG) ((ASN1_##CLASS << 6) | (ASN1_##CP << 5) | ASN1_##TAG)
  76. #define _tagn(CLASS, CP, TAG) ((ASN1_##CLASS << 6) | (ASN1_##CP << 5) | TAG)
  77. #define _jump_target(N) (N)
  78. #define _action(N) (N)
  79. #endif /* _LINUX_ASN1_BER_BYTECODE_H */