blautenb 2004/03/06 03:36:34
Modified: src/org/apache/xml/security/encryption XMLCipher.java
Log:
Clean up exception handling when algorithms not available
Revision Changes Path
1.22 +30 -11
xml-security/src/org/apache/xml/security/encryption/XMLCipher.java
Index: XMLCipher.java
===================================================================
RCS file:
/home/cvs/xml-security/src/org/apache/xml/security/encryption/XMLCipher.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- XMLCipher.java 4 Mar 2004 10:55:53 -0000 1.21
+++ XMLCipher.java 6 Mar 2004 11:36:33 -0000 1.22
@@ -272,12 +272,22 @@
throw new XMLEncryptionException("empty", ice);
}
- try {
- String jceAlgorithm =
-
JCEMapper.translateURItoJCEID(transformation).getAlgorithmID();
+ String jceAlgorithm;
+ JCEMapper.ProviderIdClass provId =
+ JCEMapper.translateURItoJCEID(transformation);
- instance._contextCipher = Cipher.getInstance(jceAlgorithm);
+ if (provId != null)
+ jceAlgorithm = provId.getAlgorithmID();
+ else {
+ Object exArgs[] =
+ { transformation,
+ "No provider found that supports this
algorithm" };
+ throw new
XMLEncryptionException("algorithms.NoSuchAlgorithm",
+
exArgs);
+ }
+ try {
+ instance._contextCipher = Cipher.getInstance(jceAlgorithm);
logger.debug("cihper.algoritm = " +
instance._contextCipher.getAlgorithm());
} catch (NoSuchAlgorithmException nsae) {
@@ -1262,12 +1272,20 @@
byte [] encryptedBytes = cipherInput.getBytes();
String provider;
- if (_requestedJCEProvider == null)
- provider =
- JCEMapper
- .translateURItoJCEID(
-
encryptedKey.getEncryptionMethod().getAlgorithm())
- .getProviderId();
+ if (_requestedJCEProvider == null) {
+ JCEMapper.ProviderIdClass provId =
+ JCEMapper.translateURItoJCEID(
+
encryptedKey.getEncryptionMethod().getAlgorithm());
+ if (provId != null)
+ provider = provId.getProviderId();
+ else {
+ Object exArgs[] =
+ {
encryptedKey.getEncryptionMethod().getAlgorithm(),
+ "No provider found that supports this
algorithm" };
+ throw new
XMLEncryptionException("algorithms.NoSuchAlgorithm",
+
exArgs);
+ }
+ }
else
provider = _requestedJCEProvider;
@@ -1457,7 +1475,8 @@
if (_key == null) {
logger.error("XMLCipher::decryptElement called
without a key and unable to resolve");
- throw new XMLEncryptionException("Unable to
decrypt without a key");
+
+ throw new
XMLEncryptionException("encryption.nokey");
}
}