/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 4508341 7055362
* @library ../../../java/security/testlibrary
* @summary Test the error conditions of
* EncryptedPrivateKeyInfo.getKeySpec(...) methods.
* @author Valerie Peng
*/
public class GetKeySpecException {
static {
try {
// should never happen
BAD_PARAMS = null;
GOOD_PARAMS = null;
}
}
}
boolean done = false;
while (!done) {
try {
Provider p = c.getProvider();
} catch (NoSuchAlgorithmException nsae) {
done = true;
} catch (NoSuchPaddingException nspe) {
// should never happen
}
}
}
}
}
try {
} finally {
}
}
throw new Exception("Static parameter generation failed");
}
// use random data
byte[] encryptedData = new byte[30];
// generate encrypted data and EncryptedPrivateKeyInfo objects
// TEST#1: getKeySpec(Cipher)
try {
throwException("Should throw NPE for null Cipher!");
} catch (NullPointerException npe) {
}
// TEST#2: getKeySpec(Key)
try {
throwException("Should throw NPE for null Key!");
} catch (NullPointerException npe) {
}
try {
throwException("Should throw IKE for invalid Key!");
} catch (InvalidKeyException ikse) {
}
try {
throwException("Should throw IKE for corrupted epki!");
} catch (InvalidKeyException ike) {
}
try {
throwException("Should throw NSAE if no matching impl!");
} catch (NoSuchAlgorithmException nsae) {
}
// TEST#3: getKeySpec(Key, String)
try {
throwException("Should throw NPE for null Key!");
} catch (NullPointerException npe) {
}
try {
throwException("Should throw NPE for null String!");
} catch (NullPointerException npe) {
}
try {
throwException("Should throw IKE for invalid Key!");
} catch (InvalidKeyException ikse) {
}
try {
throwException("Should throw IKE for corrupted epki!");
} catch (InvalidKeyException ike) {
}
try {
throwException("Should throw NSAE for provider without " +
"matching implementation!");
} catch (NoSuchAlgorithmException nsae) {
}
try {
throwException("Should throw NSPE for unconfigured provider!");
} catch (NoSuchProviderException nspe) {
}
// TEST#4: getKeySpec(Key, Provider)
try {
throwException("Should throw NPE for null Key!");
} catch (NullPointerException npe) {
}
try {
throwException("Should throw NPE for null Provider!");
} catch (NullPointerException npe) {
}
try {
throwException("Should throw IKE for invalid Key!");
} catch (InvalidKeyException ikse) {
}
try {
throwException("Should throw IKE for corrupted epki!");
} catch (InvalidKeyException ike) {
}
}
}