PageRenderTime 49ms CodeModel.GetById 21ms app.highlight 21ms RepoModel.GetById 2ms app.codeStats 0ms

/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
 23package org.mobicents.protocols.asn;
 24
 25/**
 26 * 
 27 * @author amit bhayani
 28 * @author baranowb
 29 */
 30public class Tag {
 31	
 32	/**
 33	 * Class of tag used with primitives
 34	 */
 35	public static final int CLASS_UNIVERSAL = 0x0;
 36	public static final int CLASS_APPLICATION = 0x1;
 37	public static final int CLASS_CONTEXT_SPECIFIC = 0x2;
 38	public static final int CLASS_PRIVATE = 0x3;
 39
 40	// first two bits encode the class
 41	public static final int CLASS_MASK = 0xC0;
 42
 43	// The next bit (bit six) is called the primitive/constructed (P/C) bit
 44	public static final int PC_MASK = 0x20;
 45	public static final int PC_PRIMITIVITE = 0x0;
 46	public static final int PC_CONSTRUCTED = 0x1;
 47
 48	// The last five bits (bits 5 to 1) encode the number of the tag in tag octet
 49	public static final int TAG_MASK = 0x1F;
 50
 51	// Universal class tag assignments as per X.680-0207, Section 8.4
 52	public static final int BOOLEAN = 0x01;
 53	public static final int INTEGER = 0x02;
 54	public static final int STRING_BIT = 0x03;
 55	public static final int STRING_OCTET = 0x04;
 56	public static final int NULL = 0x05;
 57    public static final int OBJECT_IDENTIFIER = 0x06;
 58	public static final int OBJECT_DESCRIPTOR = 0x07;
 59    public static final int EXTERNAL = 0x08;
 60	public static final int REAL = 0x09;
 61	public static final int ENUMERATED = 0x0A;
 62	public static final int EMBEDDED_PDV = 0x0B;
 63	public static final int STRING_UTF8 = 0x0C;
 64	public static final int RELATIVE_OID = 0x0D;
 65	public static final int SEQUENCE = 0x10; 
 66	public static final int SET = 0x11; 
 67	public static final int STRING_NUMERIC = 0x12; 
 68	public static final int STRING_PRINTABLE = 0x13; 
 69	public static final int STRING_TELETEX = 0x14; 
 70	public static final int STRING_VIDIOTEX = 0x15; 
 71	public static final int STRING_IA5 = 0x16;
 72	public static final int UTCTime = 0x17; 
 73	public static final int GeneralizedTime = 0x18; 
 74	public static final int STRING_GRAPHIC = 0x19;
 75	public static final int STRING_VISIBLE = 0x1A; 
 76	public static final int STRING_GENERAL = 0x1B; 
 77	public static final int STRING_UNIVERSAL = 0x1C; 
 78	public static final int STRING_CHARACTER = 0x1D; 
 79	public static final int STRING_BMP = 0x1E; 
 80	
 81	//values for ending stream of string for constructed form, see 18.2.6 in ASN.1 Communication between Heterogeneous Systems
 82	public static final int NULL_TAG = 0x00;
 83	public static final int NULL_VALUE = 0x00;
 84
 85	// value of indefinite length for readLength()
 86	public static final int Indefinite_Length  = -1;
 87
 88
 89	private Tag() {
 90		super();
 91	
 92	}
 93
 94
 95	public static boolean isPrimitive(int tagValue)
 96	{
 97		//no shift needed, since for primitive its '0'
 98		return (tagValue & PC_MASK) == PC_PRIMITIVITE;
 99	}
100
101	public static int getSimpleTagValue(int tagValue)
102	{
103		return tagValue & TAG_MASK;
104	}
105	public static boolean isUniversal(int tagValue)
106	{
107		return (tagValue & CLASS_MASK) == CLASS_UNIVERSAL;
108	}
109}