1 2 package com.ca.commons.security.asn1; 3 4 import java.util.Hashtable ; 5 6 10 public class ASN1Type implements java.io.Serializable 11 { 12 13 private int tag; 14 private String name; 15 16 private static Hashtable asn1Types = new Hashtable (27); 17 18 19 20 public static final ASN1Type BOOLEAN = new ASN1Type(1, 21 "BOOLEAN"); 22 public static final ASN1Type INTEGER = new ASN1Type(2, 23 "INTEGER"); 24 public static final ASN1Type BIT_STRING = new ASN1Type(3, 25 "BIT STRING"); 26 public static final ASN1Type OCTET_STRING = new ASN1Type(4, 27 "OCTET STRING"); 28 public static final ASN1Type NULL = new ASN1Type(5, 29 "NULL"); 30 public static final ASN1Type OBJECT_ID = new ASN1Type(6, 31 "OBJECT IDENTIFIER"); 32 public static final ASN1Type ENUMERATED = new ASN1Type(10, 33 "ENUMERATED"); 34 public static final ASN1Type PrintableString = new ASN1Type(19, 35 "PrintableString"); 36 public static final ASN1Type T61String = new ASN1Type(20, 37 "T61String"); 38 public static final ASN1Type IA5String = new ASN1Type(22, 39 "IA5String"); 40 public static final ASN1Type UTCTime = new ASN1Type(23, 41 "UTCTime"); 42 public static final ASN1Type GENERALIZEDTIME = new ASN1Type(24, 43 "GeneralizedTime"); 44 public static final ASN1Type UniversalString = new ASN1Type(28, 45 "UniversalString"); 46 public static final ASN1Type BMPString = new ASN1Type(30, 47 "BMPString"); 48 public static final ASN1Type SEQUENCE = new ASN1Type(48, 49 "SEQUENCE"); 50 public static final ASN1Type SET = new ASN1Type(49, 51 "SET"); 52 public static final ASN1Type ContextSpecific = new ASN1Type(128, 53 "ContextSpecific"); 54 55 60 public ASN1Type(int t, String n) 61 { 62 tag = t; 63 name = n; 64 asn1Types.put(new Integer (tag), name); 65 } 66 67 70 public ASN1Type(int t) 71 { 72 tag = t; 73 name = asn1Name(t); 74 } 75 76 79 public String getName() 80 { 81 return name; 82 } 83 84 87 public int getTag() 88 { 89 return tag; 90 } 91 92 95 public int hashCode() 96 { 97 return tag; 98 } 99 100 104 public boolean equals(Object o) 105 { 106 if (!(o instanceof ASN1Type)) 107 { 108 return false; 109 } 110 ASN1Type a = (ASN1Type) o; 111 if (a.tag == this.tag) 112 { 113 return true; 114 } 115 else 116 { 117 return false; 118 } 119 } 120 121 124 public String toString() 125 { 126 return "ASN.1 type " + name + " (" + asn1Name(tag) + ") [" + 127 tag + "] "; 128 } 129 130 133 public static String asn1Name(int t) 134 { 135 String n = (String ) asn1Types.get(new Integer (t)); 136 if (n == null) 137 { 138 return "Unknown"; 139 } 140 else 141 { 142 return n; 143 } 144 } 145 } 146 | Popular Tags |