1 7 8 9 package org.enhydra.oyster.der; 10 11 import org.enhydra.oyster.exception.SMIMEException; 12 import org.enhydra.oyster.exception.ErrorStorage; 13 14 15 22 public class DERObjectIdentifier extends DERObject { 23 24 37 public DERObjectIdentifier (String id0, String typeConstruction0) throws SMIMEException 38 { 39 super(6); 40 byte[] contentID; if (typeConstruction0.equalsIgnoreCase("DOT_SEPARATED_ARRAY")) { 43 int[] temp; 44 int[] dotPosition; 45 int j = -1, i = 0; 46 do { 48 j = id0.indexOf('.', j + 1); 49 i++; 50 } while (j != -1); 51 if (i == 1) 52 throw new SMIMEException(this, 1008); 53 temp = new int[i]; 54 dotPosition = new int[i - 1]; 55 i = 0; 56 j = -1; 57 do { 59 j = id0.indexOf('.', j + 1); 60 if (j != -1) 61 dotPosition[i] = j; 62 i++; 63 } while (j != -1); 64 temp[0] = Integer.decode(id0.substring(0, dotPosition[0])).intValue(); temp[temp.length - 1] = Integer.decode(id0.substring(dotPosition[dotPosition.length - 1] + 1)).intValue(); for (i = 1; i != temp.length - 1; i++) 67 temp[i] = Integer.decode(id0.substring(dotPosition[i - 1] + 1, dotPosition[i])).intValue(); contentID = formatID(temp); 69 super.addContent(contentID); } 71 else if (typeConstruction0.equalsIgnoreCase("NAME_STRING")) { 72 contentID = formatID(IdentifierStorage.getID(id0.toUpperCase())); 73 super.addContent(contentID); } 75 else 76 throw new SMIMEException(this, 1009); 77 } 78 79 88 public DERObjectIdentifier (int[] arrayID0) throws SMIMEException 89 { 90 super(6); 91 super.addContent(formatID(arrayID0)); 92 } 93 94 104 private byte[] formatID (int[] id0) throws SMIMEException { 105 int[] temp = new int[id0.length - 1]; 106 String s = new String (); 107 byte[] returnByteArray = null; 108 if (id0[0] == -1) 109 throw new SMIMEException(this, 1010); 110 temp[0] = 40*id0[0] + id0[1]; for (int i = 2; i != id0.length; i++) 112 temp[i - 1] = id0[i]; 113 try { 114 for (int i = 0; i != temp.length; i++) { 115 int j = 1; for (int a = 1; (a*2) <= temp[i]; j++) a = a*2; 118 j = (int)Math.ceil((double)j/7); byte[] tempElement = new byte[j]; 120 for (j = tempElement.length - 1; j >= 0; j--) { 121 tempElement[j] = (byte)((temp[i] >> (7*(tempElement.length - 1 - j))) & 0x7F); 122 if (j != (tempElement.length - 1)) 123 tempElement[j] = (byte)(tempElement[j] | (0x80)); 124 } 125 s = s.concat(new String (tempElement, "ISO-8859-1")); 126 } 127 returnByteArray = s.getBytes("ISO-8859-1"); 128 } 129 catch(Exception e) { 130 throw SMIMEException.getInstance(this, e, "formatID" ); 131 } 132 return returnByteArray; 133 } 134 } 135 136 137 138 | Popular Tags |