1 /* |
1 /* |
2 * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved |
2 * Copyright (c) 1996, 2016, 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 |
140 throws Exception { |
140 throws Exception { |
141 if (ctrParamClz == null) { |
141 if (ctrParamClz == null) { |
142 Constructor<?> con = clazz.getConstructor(); |
142 Constructor<?> con = clazz.getConstructor(); |
143 return con.newInstance(); |
143 return con.newInstance(); |
144 } else { |
144 } else { |
145 Constructor<?> con = clazz.getConstructor(ctrParamClz); |
145 // Looking for the constructor with a params first and fallback |
146 return con.newInstance(ctorParamObj); |
146 // to one without if not found. This is to support the enhanced |
|
147 // SecureRandom where both styles of constructors are supported. |
|
148 // Before jdk9, there was no params support (only getInstance(alg)) |
|
149 // and an impl only had the params-less constructor. Since jdk9, |
|
150 // there is getInstance(alg,params) and an impl can contain |
|
151 // an Impl(params) constructor. |
|
152 try { |
|
153 Constructor<?> con = clazz.getConstructor(ctrParamClz); |
|
154 return con.newInstance(ctorParamObj); |
|
155 } catch (NoSuchMethodException nsme) { |
|
156 // For pre-jdk9 SecureRandom implementations, they only |
|
157 // have params-less constructors which still works when |
|
158 // the input ctorParamObj is null. |
|
159 // |
|
160 // For other primitives using params, ctorParamObj should not |
|
161 // be null and nsme is thrown, just like before. |
|
162 if (ctorParamObj == null) { |
|
163 try { |
|
164 Constructor<?> con = clazz.getConstructor(); |
|
165 return con.newInstance(); |
|
166 } catch (NoSuchMethodException nsme2) { |
|
167 nsme.addSuppressed(nsme2); |
|
168 throw nsme; |
|
169 } |
|
170 } else { |
|
171 throw nsme; |
|
172 } |
|
173 } |
147 } |
174 } |
148 } |
175 } |
149 |
176 |
150 /** |
177 /** |
151 * Constructs a provider with the specified name, version number, |
178 * Constructs a provider with the specified name, version number, |
1382 addEngine("AlgorithmParameters", false, null); |
1409 addEngine("AlgorithmParameters", false, null); |
1383 addEngine("KeyFactory", false, null); |
1410 addEngine("KeyFactory", false, null); |
1384 addEngine("KeyPairGenerator", false, null); |
1411 addEngine("KeyPairGenerator", false, null); |
1385 addEngine("KeyStore", false, null); |
1412 addEngine("KeyStore", false, null); |
1386 addEngine("MessageDigest", false, null); |
1413 addEngine("MessageDigest", false, null); |
1387 addEngine("SecureRandom", false, null); |
1414 addEngine("SecureRandom", false, |
|
1415 "java.security.SecureRandomParameters"); |
1388 addEngine("Signature", true, null); |
1416 addEngine("Signature", true, null); |
1389 addEngine("CertificateFactory", false, null); |
1417 addEngine("CertificateFactory", false, null); |
1390 addEngine("CertPathBuilder", false, null); |
1418 addEngine("CertPathBuilder", false, null); |
1391 addEngine("CertPathValidator", false, null); |
1419 addEngine("CertPathValidator", false, null); |
1392 addEngine("CertStore", false, |
1420 addEngine("CertStore", false, |
1676 + " for engine type " + type); |
1704 + " for engine type " + type); |
1677 } |
1705 } |
1678 } |
1706 } |
1679 } |
1707 } |
1680 } |
1708 } |
|
1709 // constructorParameter can be null if not provided |
1681 return newInstanceUtil(getImplClass(), ctrParamClz, constructorParameter); |
1710 return newInstanceUtil(getImplClass(), ctrParamClz, constructorParameter); |
1682 } catch (NoSuchAlgorithmException e) { |
1711 } catch (NoSuchAlgorithmException e) { |
1683 throw e; |
1712 throw e; |
1684 } catch (InvocationTargetException e) { |
1713 } catch (InvocationTargetException e) { |
1685 throw new NoSuchAlgorithmException |
1714 throw new NoSuchAlgorithmException |