1 7 8 package org.ietf.jgss; 9 10 import java.io.InputStream ; 11 import java.io.IOException ; 12 import sun.security.util.DerValue; 13 import sun.security.util.DerOutputStream; 14 import sun.security.util.ObjectIdentifier; 15 16 34 public class Oid { 35 36 private ObjectIdentifier oid; 37 private byte[] derEncoding; 38 39 48 public Oid(String strOid) throws GSSException { 49 50 try { 51 oid = new ObjectIdentifier(strOid); 52 derEncoding = null; 53 } catch (Exception e) { 54 throw new GSSException (GSSException.FAILURE, 55 "Improperly formatted Object Identifier String - " 56 + strOid); 57 } 58 } 59 60 70 public Oid(InputStream derOid) throws GSSException { 71 try { 72 DerValue derVal = new DerValue(derOid); 73 derEncoding = derVal.toByteArray(); 74 oid = derVal.getOID(); 75 } catch (IOException e) { 76 throw new GSSException (GSSException.FAILURE, 77 "Improperly formatted ASN.1 DER encoding for Oid"); 78 } 79 } 80 81 82 92 public Oid(byte [] data) throws GSSException { 93 try { 94 DerValue derVal = new DerValue(data); 95 derEncoding = derVal.toByteArray(); 96 oid = derVal.getOID(); 97 } catch (IOException e) { 98 throw new GSSException (GSSException.FAILURE, 99 "Improperly formatted ASN.1 DER encoding for Oid"); 100 } 101 } 102 103 108 static Oid getInstance(String strOid) { 109 Oid retVal = null; 110 try { 111 retVal = new Oid (strOid); 112 } catch (GSSException e) { 113 } 115 return retVal; 116 } 117 118 124 public String toString() { 125 return oid.toString(); 126 } 127 128 136 public boolean equals(Object other) { 137 138 if (this == other) 140 return (true); 141 142 if (other instanceof Oid ) 143 return this.oid.equals(((Oid ) other).oid); 144 else if (other instanceof ObjectIdentifier) 145 return this.oid.equals(other); 146 else 147 return false; 148 } 149 150 151 158 public byte[] getDER() throws GSSException { 159 160 if (derEncoding == null) { 161 DerOutputStream dout = new DerOutputStream(); 162 try { 163 dout.putOID(oid); 164 } catch (IOException e) { 165 throw new GSSException (GSSException.FAILURE, e.getMessage()); 166 } 167 derEncoding = dout.toByteArray(); 168 } 169 170 return derEncoding; 171 } 172 173 180 public boolean containedIn(Oid [] oids) { 181 182 for (int i = 0; i < oids.length; i++) { 183 if (oids[i].equals(this)) 184 return (true); 185 } 186 187 return (false); 188 } 189 190 191 196 public int hashCode() { 197 return oid.hashCode(); 198 } 199 } 200 | Popular Tags |