1 /* |
1 /* |
2 * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
91 private static Class[] PARAMS = {Boolean.class, Object.class}; |
91 private static Class[] PARAMS = {Boolean.class, Object.class}; |
92 |
92 |
93 // Parse the encoded extension |
93 // Parse the encoded extension |
94 private void parseExtension(Extension ext) throws IOException { |
94 private void parseExtension(Extension ext) throws IOException { |
95 try { |
95 try { |
96 Class extClass = OIDMap.getClass(ext.getExtensionId()); |
96 Class<?> extClass = OIDMap.getClass(ext.getExtensionId()); |
97 if (extClass == null) { // Unsupported extension |
97 if (extClass == null) { // Unsupported extension |
98 if (ext.isCritical()) { |
98 if (ext.isCritical()) { |
99 unsupportedCritExt = true; |
99 unsupportedCritExt = true; |
100 } |
100 } |
101 if (map.put(ext.getExtensionId().toString(), ext) == null) { |
101 if (map.put(ext.getExtensionId().toString(), ext) == null) { |
102 return; |
102 return; |
103 } else { |
103 } else { |
104 throw new IOException("Duplicate extensions not allowed"); |
104 throw new IOException("Duplicate extensions not allowed"); |
105 } |
105 } |
106 } |
106 } |
107 Constructor cons = ((Class<?>)extClass).getConstructor(PARAMS); |
107 Constructor<?> cons = extClass.getConstructor(PARAMS); |
108 |
108 |
109 Object[] passed = new Object[] {Boolean.valueOf(ext.isCritical()), |
109 Object[] passed = new Object[] {Boolean.valueOf(ext.isCritical()), |
110 ext.getExtensionValue()}; |
110 ext.getExtensionValue()}; |
111 CertAttrSet certExt = (CertAttrSet)cons.newInstance(passed); |
111 CertAttrSet<?> certExt = (CertAttrSet<?>) |
|
112 cons.newInstance(passed); |
112 if (map.put(certExt.getName(), (Extension)certExt) != null) { |
113 if (map.put(certExt.getName(), (Extension)certExt) != null) { |
113 throw new IOException("Duplicate extensions not allowed"); |
114 throw new IOException("Duplicate extensions not allowed"); |
114 } |
115 } |
115 } catch (InvocationTargetException invk) { |
116 } catch (InvocationTargetException invk) { |
116 Throwable e = invk.getTargetException(); |
117 Throwable e = invk.getTargetException(); |
130 return; |
131 return; |
131 } |
132 } |
132 if (e instanceof IOException) { |
133 if (e instanceof IOException) { |
133 throw (IOException)e; |
134 throw (IOException)e; |
134 } else { |
135 } else { |
135 throw (IOException)new IOException(e.toString()).initCause(e); |
136 throw new IOException(e); |
136 } |
137 } |
137 } catch (IOException e) { |
138 } catch (IOException e) { |
138 throw e; |
139 throw e; |
139 } catch (Exception e) { |
140 } catch (Exception e) { |
140 throw (IOException)new IOException(e.toString()).initCause(e); |
141 throw new IOException(e); |
141 } |
142 } |
142 } |
143 } |
143 |
144 |
144 /** |
145 /** |
145 * Encode the extensions in DER form to the stream, setting |
146 * Encode the extensions in DER form to the stream, setting |
208 /** |
209 /** |
209 * Get the attribute value. |
210 * Get the attribute value. |
210 * @param name the extension name used in the lookup. |
211 * @param name the extension name used in the lookup. |
211 * @exception IOException if named extension is not found. |
212 * @exception IOException if named extension is not found. |
212 */ |
213 */ |
213 public Object get(String name) throws IOException { |
214 public Extension get(String name) throws IOException { |
214 Object obj = map.get(name); |
215 Extension obj = map.get(name); |
215 if (obj == null) { |
216 if (obj == null) { |
216 throw new IOException("No extension found with name " + name); |
217 throw new IOException("No extension found with name " + name); |
217 } |
218 } |
218 return (obj); |
219 return (obj); |
219 } |
220 } |
351 public UnparseableExtension(Extension ext, Throwable why) { |
352 public UnparseableExtension(Extension ext, Throwable why) { |
352 super(ext); |
353 super(ext); |
353 |
354 |
354 name = ""; |
355 name = ""; |
355 try { |
356 try { |
356 Class extClass = OIDMap.getClass(ext.getExtensionId()); |
357 Class<?> extClass = OIDMap.getClass(ext.getExtensionId()); |
357 if (extClass != null) { |
358 if (extClass != null) { |
358 Field field = extClass.getDeclaredField("NAME"); |
359 Field field = extClass.getDeclaredField("NAME"); |
359 name = (String)(field.get(null)) + " "; |
360 name = (String)(field.get(null)) + " "; |
360 } |
361 } |
361 } catch (Exception e) { |
362 } catch (Exception e) { |