You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2020/04/17 15:57:06 UTC

svn commit: r1876669 - in /santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security: encryption/XMLCipher.java keys/keyresolver/KeyResolver.java

Author: coheigea
Date: Fri Apr 17 15:57:06 2020
New Revision: 1876669

URL: http://svn.apache.org/viewvc?rev=1876669&view=rev
Log:
Some minor refactoring

Modified:
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/encryption/XMLCipher.java
    santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/keyresolver/KeyResolver.java

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/encryption/XMLCipher.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/encryption/XMLCipher.java?rev=1876669&r1=1876668&r2=1876669&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/encryption/XMLCipher.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/encryption/XMLCipher.java Fri Apr 17 15:57:06 2020
@@ -1177,14 +1177,9 @@ public class XMLCipher {
                 LOG.debug("Actual cipher.outputSize = "
                              + Integer.toString(encryptedBytes.length));
             }
-        } catch (IllegalStateException ise) {
-            throw new XMLEncryptionException(ise);
-        } catch (IllegalBlockSizeException ibse) {
-            throw new XMLEncryptionException(ibse);
-        } catch (BadPaddingException bpe) {
-            throw new XMLEncryptionException(bpe);
-        } catch (UnsupportedEncodingException uee) {
-            throw new XMLEncryptionException(uee);
+        } catch (IllegalStateException | IllegalBlockSizeException
+                | BadPaddingException | UnsupportedEncodingException e) {
+            throw new XMLEncryptionException(e);
         }
 
         // Get IV from Cipher Object. If this is null (see BouncyCastle issue BJA-473) then use
@@ -1404,11 +1399,7 @@ public class XMLCipher {
                 }
             }
             encryptedBytes = c.wrap(key);
-        } catch (InvalidKeyException ike) {
-            throw new XMLEncryptionException(ike);
-        } catch (IllegalBlockSizeException ibse) {
-            throw new XMLEncryptionException(ibse);
-        } catch (InvalidAlgorithmParameterException e) {
+        } catch (InvalidKeyException | IllegalBlockSizeException | InvalidAlgorithmParameterException e) {
             throw new XMLEncryptionException(e);
         }
 
@@ -1512,11 +1503,7 @@ public class XMLCipher {
                 c.init(Cipher.UNWRAP_MODE, key, oaepParameters);
             }
             ret = c.unwrap(encryptedBytes, jceKeyAlgorithm, Cipher.SECRET_KEY);
-        } catch (InvalidKeyException ike) {
-            throw new XMLEncryptionException(ike);
-        } catch (NoSuchAlgorithmException nsae) {
-            throw new XMLEncryptionException( nsae);
-        } catch (InvalidAlgorithmParameterException e) {
+        } catch (InvalidKeyException | NoSuchAlgorithmException | InvalidAlgorithmParameterException e) {
             throw new XMLEncryptionException(e);
         }
         LOG.debug("Decryption of key type {} OK", algorithm);
@@ -1580,10 +1567,8 @@ public class XMLCipher {
             // Check to see if an RSA OAEP MGF-1 with SHA-1 algorithm was requested
             // Some JDKs don't support RSA/ECB/OAEPPadding
             c = constructCipher(algorithm, digestAlgorithm, nsae);
-        } catch (NoSuchProviderException nspre) {
-            throw new XMLEncryptionException(nspre);
-        } catch (NoSuchPaddingException nspae) {
-            throw new XMLEncryptionException(nspae);
+        } catch (NoSuchProviderException | NoSuchPaddingException e) {
+            throw new XMLEncryptionException(e);
         }
 
         return c;
@@ -1791,12 +1776,8 @@ public class XMLCipher {
             } else {
                 c = Cipher.getInstance(jceAlgorithm, requestedJCEProvider);
             }
-        } catch (NoSuchAlgorithmException nsae) {
-            throw new XMLEncryptionException(nsae);
-        } catch (NoSuchProviderException nspre) {
-            throw new XMLEncryptionException(nspre);
-        } catch (NoSuchPaddingException nspae) {
-            throw new XMLEncryptionException(nspae);
+        } catch (NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException e) {
+            throw new XMLEncryptionException(e);
         }
 
         int ivLen = JCEMapper.getIVLengthFromURI(encMethodAlgorithm) / 8;
@@ -1817,18 +1798,14 @@ public class XMLCipher {
 
         try {
             c.init(cipherMode, key, paramSpec);
-        } catch (InvalidKeyException ike) {
-            throw new XMLEncryptionException(ike);
-        } catch (InvalidAlgorithmParameterException iape) {
-            throw new XMLEncryptionException(iape);
+        } catch (InvalidKeyException | InvalidAlgorithmParameterException e) {
+            throw new XMLEncryptionException(e);
         }
 
         try {
             return c.doFinal(encryptedBytes, ivLen, encryptedBytes.length - ivLen);
-        } catch (IllegalBlockSizeException ibse) {
-            throw new XMLEncryptionException(ibse);
-        } catch (BadPaddingException bpe) {
-            throw new XMLEncryptionException(bpe);
+        } catch (IllegalBlockSizeException | BadPaddingException e) {
+            throw new XMLEncryptionException(e);
         }
     }
 
@@ -2209,12 +2186,8 @@ public class XMLCipher {
                 LOG.debug("Creating a DSIG based Transforms element");
                 try {
                     result.setTransforms(new TransformsImpl(transformsElement));
-                } catch (XMLSignatureException xse) {
-                    throw new XMLEncryptionException(xse);
-                } catch (InvalidTransformException ite) {
-                    throw new XMLEncryptionException(ite);
-                } catch (XMLSecurityException xse) {
-                    throw new XMLEncryptionException(xse);
+                } catch (XMLSecurityException e) {
+                    throw new XMLEncryptionException(e);
                 }
             }
 
@@ -2554,7 +2527,7 @@ public class XMLCipher {
                     tmpAlgorithm = new URI(algorithm);
                 } catch (URISyntaxException ex) {
                     throw (IllegalArgumentException)
-                    new IllegalArgumentException().initCause(ex);
+                            new IllegalArgumentException().initCause(ex);
                 }
                 algorithmURI = tmpAlgorithm.toString();
             }
@@ -2970,7 +2943,7 @@ public class XMLCipher {
                         tmpType = new URI(type);
                     } catch (URISyntaxException ex) {
                         throw (IllegalArgumentException)
-                        new IllegalArgumentException().initCause(ex);
+                                new IllegalArgumentException().initCause(ex);
                     }
                     this.type = tmpType.toString();
                 }
@@ -3012,7 +2985,7 @@ public class XMLCipher {
                         tmpEncoding = new URI(encoding);
                     } catch (URISyntaxException ex) {
                         throw (IllegalArgumentException)
-                        new IllegalArgumentException().initCause(ex);
+                                new IllegalArgumentException().initCause(ex);
                     }
                     this.encoding = tmpEncoding.toString();
                 }
@@ -3093,7 +3066,7 @@ public class XMLCipher {
                     tmpAlgorithm = new URI(algorithm);
                 } catch (URISyntaxException ex) {
                     throw (IllegalArgumentException)
-                    new IllegalArgumentException().initCause(ex);
+                            new IllegalArgumentException().initCause(ex);
                 }
                 this.algorithm = tmpAlgorithm.toString();
                 encryptionMethodInformation = new LinkedList<>();
@@ -3300,7 +3273,7 @@ public class XMLCipher {
                         tmpTarget = new URI(target);
                     } catch (URISyntaxException ex) {
                         throw (IllegalArgumentException)
-                        new IllegalArgumentException().initCause(ex);
+                                new IllegalArgumentException().initCause(ex);
                     }
                     this.target = tmpTarget.toString();
                 }

Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/keyresolver/KeyResolver.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/keyresolver/KeyResolver.java?rev=1876669&r1=1876668&r2=1876669&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/keyresolver/KeyResolver.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/keyresolver/KeyResolver.java Fri Apr 17 15:57:06 2020
@@ -83,9 +83,9 @@ public class KeyResolver {
         for (KeyResolverSpi resolver : resolverList) {
             if (resolver == null) {
                 Object[] exArgs = {
-                                   element != null
-                                       && element.getNodeType() == Node.ELEMENT_NODE
-                                       ? element.getTagName() : "null"
+                        element != null
+                                && element.getNodeType() == Node.ELEMENT_NODE
+                                ? element.getTagName() : "null"
                 };
 
                 throw new KeyResolverException("utils.resolver.noClass", exArgs);
@@ -99,9 +99,9 @@ public class KeyResolver {
         }
 
         Object[] exArgs = {
-                           element != null && element.getNodeType() == Node.ELEMENT_NODE
-                           ? element.getTagName() : "null"
-                          };
+                element != null && element.getNodeType() == Node.ELEMENT_NODE
+                        ? element.getTagName() : "null"
+        };
 
         throw new KeyResolverException("utils.resolver.noClass", exArgs);
     }
@@ -123,9 +123,9 @@ public class KeyResolver {
         for (KeyResolverSpi resolver : resolverList) {
             if (resolver == null) {
                 Object[] exArgs = {
-                                   element != null
-                                       && element.getNodeType() == Node.ELEMENT_NODE
-                                       ? element.getTagName() : "null"
+                        element != null
+                                && element.getNodeType() == Node.ELEMENT_NODE
+                                ? element.getTagName() : "null"
                 };
 
                 throw new KeyResolverException("utils.resolver.noClass", exArgs);
@@ -139,9 +139,9 @@ public class KeyResolver {
         }
 
         Object[] exArgs = {
-                           element != null && element.getNodeType() == Node.ELEMENT_NODE
-                           ? element.getTagName() : "null"
-                          };
+                element != null && element.getNodeType() == Node.ELEMENT_NODE
+                        ? element.getTagName() : "null"
+        };
 
         throw new KeyResolverException("utils.resolver.noClass", exArgs);
     }
@@ -190,17 +190,13 @@ public class KeyResolver {
         try {
             keyResolverSpi = (KeyResolverSpi) ClassLoaderUtils.loadClass(className, KeyResolver.class).newInstance();
             register(keyResolverSpi, true);
-        } catch (ClassNotFoundException e) {
-            ex = e;
-        } catch (IllegalAccessException e) {
-            ex = e;
-        } catch (InstantiationException e) {
+        } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
             ex = e;
         }
 
         if (ex != null) {
             throw (IllegalArgumentException) new
-            IllegalArgumentException("Invalid KeyResolver class name").initCause(ex);
+                    IllegalArgumentException("Invalid KeyResolver class name").initCause(ex);
         }
     }