1 2 package com.ca.commons.security.asn1; 3 4 10 public class Context extends ASN1Object implements java.io.Serializable 11 { 12 13 private ASN1Object value; 14 private boolean implicit; private int tag; 17 20 public Context() 21 {} 22 23 32 public Context(int t, boolean imp, ASN1Object o) 33 { 34 asn1Type = ASN1Type.ContextSpecific; 35 byteArray = null; 36 tag = t; 37 implicit = imp; 38 39 if (o instanceof Primitive) 40 { 41 value = o; 42 } 43 else if (o instanceof Sequence) 44 { 45 value = o; 46 } 47 else if (o instanceof Context) 48 { 49 value = o; 50 } 51 else 52 { 53 throw new IllegalArgumentException ("invalid ContextSpecific"+ 54 " underlying object"); 55 } 56 } 57 58 61 public void init(ASN1Type type) 62 { 63 asn1Type = type; 64 byteArray = null; 65 implicit = false; 66 tag = 0; 67 value = null; 68 } 69 70 76 public void setValue(Object o) 77 { 78 if (o instanceof Context) 79 { 80 Context obj = (Context) o; 81 tag = obj.getTag(); 82 value = (ASN1Object) (obj.getValue()); 83 implicit = obj.implicit(); 84 } 85 else 86 { 87 throw new IllegalArgumentException ("incompatible type"); 88 } 89 } 90 91 94 public Object getValue() 95 { 96 return value; 97 } 98 99 102 public int getTag() 103 { 104 return tag; 105 } 106 107 111 public boolean implicit() 112 { 113 return implicit; 114 } 115 116 137 138 141 public String toString() 142 { 143 String s = super.toString(); 144 s += "\n\tcontext specific tag [" + tag + "] implicit? " + implicit; 145 s += "\n\tunderlying type: " + value.toString(); 146 return s; 147 } 148 } 149 | Popular Tags |