/protocols/asn/asn-impl/src/main/java/org/mobicents/protocols/asn/Tag.java

http://mobicents.googlecode.com/ · Java · 109 lines · 58 code · 15 blank · 36 comment · 2 complexity · fd18c789ee5758dea93c5b1989a23d6a MD5 · raw file

  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2011, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.mobicents.protocols.asn;
  23. /**
  24. *
  25. * @author amit bhayani
  26. * @author baranowb
  27. */
  28. public class Tag {
  29. /**
  30. * Class of tag used with primitives
  31. */
  32. public static final int CLASS_UNIVERSAL = 0x0;
  33. public static final int CLASS_APPLICATION = 0x1;
  34. public static final int CLASS_CONTEXT_SPECIFIC = 0x2;
  35. public static final int CLASS_PRIVATE = 0x3;
  36. // first two bits encode the class
  37. public static final int CLASS_MASK = 0xC0;
  38. // The next bit (bit six) is called the primitive/constructed (P/C) bit
  39. public static final int PC_MASK = 0x20;
  40. public static final int PC_PRIMITIVITE = 0x0;
  41. public static final int PC_CONSTRUCTED = 0x1;
  42. // The last five bits (bits 5 to 1) encode the number of the tag in tag octet
  43. public static final int TAG_MASK = 0x1F;
  44. // Universal class tag assignments as per X.680-0207, Section 8.4
  45. public static final int BOOLEAN = 0x01;
  46. public static final int INTEGER = 0x02;
  47. public static final int STRING_BIT = 0x03;
  48. public static final int STRING_OCTET = 0x04;
  49. public static final int NULL = 0x05;
  50. public static final int OBJECT_IDENTIFIER = 0x06;
  51. public static final int OBJECT_DESCRIPTOR = 0x07;
  52. public static final int EXTERNAL = 0x08;
  53. public static final int REAL = 0x09;
  54. public static final int ENUMERATED = 0x0A;
  55. public static final int EMBEDDED_PDV = 0x0B;
  56. public static final int STRING_UTF8 = 0x0C;
  57. public static final int RELATIVE_OID = 0x0D;
  58. public static final int SEQUENCE = 0x10;
  59. public static final int SET = 0x11;
  60. public static final int STRING_NUMERIC = 0x12;
  61. public static final int STRING_PRINTABLE = 0x13;
  62. public static final int STRING_TELETEX = 0x14;
  63. public static final int STRING_VIDIOTEX = 0x15;
  64. public static final int STRING_IA5 = 0x16;
  65. public static final int UTCTime = 0x17;
  66. public static final int GeneralizedTime = 0x18;
  67. public static final int STRING_GRAPHIC = 0x19;
  68. public static final int STRING_VISIBLE = 0x1A;
  69. public static final int STRING_GENERAL = 0x1B;
  70. public static final int STRING_UNIVERSAL = 0x1C;
  71. public static final int STRING_CHARACTER = 0x1D;
  72. public static final int STRING_BMP = 0x1E;
  73. //values for ending stream of string for constructed form, see 18.2.6 in ASN.1 Communication between Heterogeneous Systems
  74. public static final int NULL_TAG = 0x00;
  75. public static final int NULL_VALUE = 0x00;
  76. // value of indefinite length for readLength()
  77. public static final int Indefinite_Length = -1;
  78. private Tag() {
  79. super();
  80. }
  81. public static boolean isPrimitive(int tagValue)
  82. {
  83. //no shift needed, since for primitive its '0'
  84. return (tagValue & PC_MASK) == PC_PRIMITIVITE;
  85. }
  86. public static int getSimpleTagValue(int tagValue)
  87. {
  88. return tagValue & TAG_MASK;
  89. }
  90. public static boolean isUniversal(int tagValue)
  91. {
  92. return (tagValue & CLASS_MASK) == CLASS_UNIVERSAL;
  93. }
  94. }