harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smish...@apache.org
Subject svn commit: r391558 - in /incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto: ./ spec/
Date Wed, 05 Apr 2006 07:52:02 GMT
Author: smishura
Date: Wed Apr  5 00:51:58 2006
New Revision: 391558

URL: http://svn.apache.org/viewcvs?rev=391558&view=rev
Log:
Apply patch HARMONY-261 (Static initialization of an exception must not be used)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/CipherSpi.java
    incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/SealedObject.java
    incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/DESKeySpec.java
    incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/DESedeKeySpec.java
    incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/PBEKeySpec.java
    incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/RC2ParameterSpec.java
    incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/RC5ParameterSpec.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/CipherSpi.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/CipherSpi.java?rev=391558&r1=391557&r2=391558&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/CipherSpi.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/CipherSpi.java
Wed Apr  5 00:51:58 2006
@@ -37,13 +37,6 @@
 
 public abstract class CipherSpi {
 
-    // This is exception which will be thrown by
-    // engineUpdate(ByteBuffer input,ByteBuffer output) and
-    // engineDoFinal(ByteBuffer input,ByteBuffer output) methods when
-    // there is no enough space in output byte buffer to store result
-    private static final ShortBufferException SHORTOUTPUT = new ShortBufferException(
-            "Output is small");
-
     /**
      * @com.intel.drl.spec_ref
      *  
@@ -157,7 +150,7 @@
             bOutput = engineUpdate(bInput, 0, limit - position);
         }
         if (output.remaining() < bOutput.length) {
-            throw SHORTOUTPUT;
+            throw new ShortBufferException("Output is small");
         }
         try {
             output.put(bOutput);
@@ -216,7 +209,7 @@
             bOutput = engineDoFinal(bInput, 0, limit - position);
         }
         if (output.remaining() < bOutput.length) {
-            throw SHORTOUTPUT;
+            throw new ShortBufferException("Output is small");
         }
         try {
             output.put(bOutput);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/SealedObject.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/SealedObject.java?rev=391558&r1=391557&r2=391558&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/SealedObject.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/SealedObject.java
Wed Apr  5 00:51:58 2006
@@ -47,9 +47,6 @@
      */
     private static final long serialVersionUID = 4482838265551344752L;
 
-    private static final NullPointerException NULLCIPHER_EXC =
-            new NullPointerException("Cipher is null!");
-
     /**
      * @com.intel.drl.spec_ref
      */
@@ -72,8 +69,7 @@
     public SealedObject(Serializable object, Cipher c)
                 throws IOException, IllegalBlockSizeException {
         if (c == null) {
-            throw NULLCIPHER_EXC;
-            //throw new NullPointerException("Cipher is null!");
+            throw new NullPointerException("Cipher is null!");
         }
         try {
             ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -162,8 +158,7 @@
                 throws IOException, ClassNotFoundException,
                        IllegalBlockSizeException, BadPaddingException {
         if (c == null) {
-            throw NULLCIPHER_EXC;
-            //throw new NullPointerException("Cipher is null.");
+            throw new NullPointerException("Cipher is null.");
         }
         byte[] serialized = c.doFinal(encryptedContent);
         ObjectInputStream ois =

Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/DESKeySpec.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/DESKeySpec.java?rev=391558&r1=391557&r2=391558&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/DESKeySpec.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/DESKeySpec.java
Wed Apr  5 00:51:58 2006
@@ -93,9 +93,6 @@
 
                 };
 
-    private static final InvalidKeyException INCORRECT_KEY_EXCEPTION =
-            new InvalidKeyException("The specified key material is incorrect.");
-
     /**
      * @com.intel.drl.spec_ref
      */
@@ -112,9 +109,8 @@
             throw new NullPointerException("Key material is null.");
         }
         if (key.length - offset < DES_KEY_LEN) {
-            throw INCORRECT_KEY_EXCEPTION;
-            //new InvalidKeyException(
-            //        "The key material is shorter than 8 bytes");
+            throw new InvalidKeyException(
+                    "The key material is shorter than 8 bytes");
         }
         this.key = new byte[DES_KEY_LEN];
         System.arraycopy(key, offset, this.key, 0, DES_KEY_LEN);
@@ -134,9 +130,12 @@
      */
     public static boolean isParityAdjusted(byte[] key, int offset)
                 throws InvalidKeyException {
-        if (key == null || key.length - offset < DES_KEY_LEN) {
-            throw INCORRECT_KEY_EXCEPTION;
-            //throw new InvalidKeyException("Incorrect key material.");
+        if (key == null) {
+            throw new InvalidKeyException("Key material is null.");
+        }
+        if (key.length - offset < DES_KEY_LEN) {
+            throw new InvalidKeyException(
+                    "The key material is shorter than 8 bytes");
         }
         for (int i=offset; i<DES_KEY_LEN+offset; i++) {
             int b = key[i];
@@ -154,9 +153,12 @@
      */
     public static boolean isWeak(byte[] key, int offset)
               throws InvalidKeyException {
-        if (key == null || key.length - offset < DES_KEY_LEN) {
-            throw INCORRECT_KEY_EXCEPTION;
-            //throw new InvalidKeyException("Incorrect key material.");
+        if (key == null) {
+            throw new InvalidKeyException("Key material is null.");
+        }
+        if (key.length - offset < DES_KEY_LEN) {
+            throw new InvalidKeyException(
+                    "The key material is shorter than 8 bytes");
         }
         I:
         for (int i=0; i<SEMIWEAKS.length; i++) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/DESedeKeySpec.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/DESedeKeySpec.java?rev=391558&r1=391557&r2=391558&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/DESedeKeySpec.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/DESedeKeySpec.java
Wed Apr  5 00:51:58 2006
@@ -35,23 +35,17 @@
 
     private final byte[] key;
 
-    private static final NullPointerException NULL_KEY_EXC =
-        new NullPointerException("Specified key material is null.");
-    private static final InvalidKeyException INVALID_KEY_EXC =
-        new InvalidKeyException("The key material is shorter than 24 bytes.");
-
     /**
      * @com.intel.drl.spec_ref
      */
     public DESedeKeySpec(byte[] key)
                 throws InvalidKeyException {
         if (key == null) {
-            throw NULL_KEY_EXC;
+            throw new NullPointerException("Specified key material is null.");
         }
         if (key.length < DES_EDE_KEY_LEN) {
-            throw INVALID_KEY_EXC;
-            //throw new InvalidKeyException(
-            //        "The key material is shorter than 24 bytes.");
+            throw new InvalidKeyException(
+                    "The key material is shorter than 24 bytes.");
         }
         this.key = new byte[DES_EDE_KEY_LEN];
         System.arraycopy(key, 0, this.key, 0, DES_EDE_KEY_LEN);
@@ -63,12 +57,11 @@
     public DESedeKeySpec(byte[] key, int offset)
                 throws InvalidKeyException {
         if (key == null) {
-            throw NULL_KEY_EXC;
+            throw new NullPointerException("Specified key material is null.");
         }
         if (key.length - offset < DES_EDE_KEY_LEN) {
-            throw INVALID_KEY_EXC;
-            //throw new InvalidKeyException(
-            //        "The key material is shorter than 24 bytes.");
+            throw new InvalidKeyException(
+                    "The key material is shorter than 24 bytes.");
         }
         this.key = new byte[DES_EDE_KEY_LEN];
         System.arraycopy(key, offset, this.key, 0, DES_EDE_KEY_LEN);
@@ -89,9 +82,8 @@
     public static boolean isParityAdjusted(byte[] key, int offset)
                 throws InvalidKeyException {
         if (key.length - offset < DES_EDE_KEY_LEN) {
-            throw INVALID_KEY_EXC;
-            //throw new InvalidKeyException(
-            //        "The key material is shorter than 24 bytes.");
+            throw new InvalidKeyException(
+                    "The key material is shorter than 24 bytes.");
         }
         for (int i=offset; i<DES_EDE_KEY_LEN+offset; i++) {
             int b = key[i];

Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/PBEKeySpec.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/PBEKeySpec.java?rev=391558&r1=391557&r2=391558&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/PBEKeySpec.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/PBEKeySpec.java
Wed Apr  5 00:51:58 2006
@@ -29,11 +29,6 @@
  */
 public class PBEKeySpec implements KeySpec {
 
-    private static final NullPointerException NULLSALT_EXC =
-        new NullPointerException("Salt is null.");
-    private static final IllegalArgumentException BADPARAMS_EXC =
-        new IllegalArgumentException("Bad initialization parameters.");
-
     private char[] password;
     private final byte[] salt;
     private final int iterationCount;
@@ -60,13 +55,18 @@
     public PBEKeySpec(char[] password, byte[] salt, int iterationCount,
                       int keyLength) {
         if (salt == null) {
-            throw NULLSALT_EXC;
+            throw new NullPointerException("Salt is null.");
+        }
+        if (salt.length == 0) {
+            throw new IllegalArgumentException("salt is empty");
+        }
+        if (iterationCount < 0) {
+            throw new IllegalArgumentException("iterationCount < 0");
         }
-        if ((salt.length == 0) || (iterationCount < 0) || (keyLength < 0)) {
-            throw BADPARAMS_EXC;
-            //throw new IllegalArgumentException(
-            //        "salt is empty or iterationCount < 0 or keyLength < 0");
+        if (keyLength < 0) {
+            throw new IllegalArgumentException("keyLength < 0");
         }
+
         if (password == null) {
             this.password = new char[0];
         } else {
@@ -84,13 +84,15 @@
      */
     public PBEKeySpec(char[] password, byte[] salt, int iterationCount) {
         if (salt == null) {
-            throw NULLSALT_EXC;
+            throw new NullPointerException("Salt is null.");
+        }
+        if (salt.length == 0) {
+            throw new IllegalArgumentException("salt is empty");
         }
-        if ((salt.length == 0) || (iterationCount < 0)) {
-            throw BADPARAMS_EXC;
-            //throw new IllegalArgumentException(
-            //        "salt is empty or iterationCount < 0");
+        if (iterationCount < 0) {
+            throw new IllegalArgumentException("iterationCount < 0");
         }
+
         if (password == null) {
             this.password = new char[0];
         } else {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/RC2ParameterSpec.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/RC2ParameterSpec.java?rev=391558&r1=391557&r2=391558&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/RC2ParameterSpec.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/RC2ParameterSpec.java
Wed Apr  5 00:51:58 2006
@@ -32,9 +32,6 @@
     private final int effectiveKeyBits;
     private final byte[] iv;
 
-    private static final IllegalArgumentException INCORRECTIV_EXC =
-            new IllegalArgumentException("iv is null or shorter than 8 bytes.");
-
     /**
      * @com.intel.drl.spec_ref
      */
@@ -47,8 +44,11 @@
      * @com.intel.drl.spec_ref
      */
     public RC2ParameterSpec(int effectiveKeyBits, byte[] iv) {
-        if ((iv == null) || (iv.length < 8)) {
-            throw INCORRECTIV_EXC;
+        if (iv == null) {
+            throw new IllegalArgumentException("iv is null");
+        }
+        if (iv.length < 8) {
+            throw new IllegalArgumentException("iv is shorter than 8 bytes");
         }
         this.effectiveKeyBits = effectiveKeyBits;
         this.iv = new byte[8];
@@ -59,8 +59,11 @@
      * @com.intel.drl.spec_ref
      */
     public RC2ParameterSpec(int effectiveKeyBits, byte[] iv, int offset) {
-        if ((iv == null) || (iv.length - offset < 8)) {
-            throw INCORRECTIV_EXC;
+        if (iv == null) {
+            throw new IllegalArgumentException("iv is null");
+        }
+        if (iv.length - offset < 8) {
+            throw new IllegalArgumentException("iv is shorter than 8 bytes");
         }
         this.effectiveKeyBits = effectiveKeyBits;
         this.iv = new byte[8];

Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/RC5ParameterSpec.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/RC5ParameterSpec.java?rev=391558&r1=391557&r2=391558&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/RC5ParameterSpec.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/RC5ParameterSpec.java
Wed Apr  5 00:51:58 2006
@@ -34,9 +34,6 @@
     private final int wordSize;
     private final byte[] iv;
 
-    private static final IllegalArgumentException BADPARAMS_EXC = 
-            new IllegalArgumentException(
-                    "IV is null or (iv.length - offset < 2 * (wordSize / 8)).");
     /**
      * @com.intel.drl.spec_ref
      */
@@ -51,10 +48,12 @@
      * @com.intel.drl.spec_ref
      */
     public RC5ParameterSpec(int version, int rounds, int wordSize, byte[] iv) {
-        if ((iv == null) || (iv.length < 2 * (wordSize / 8))) {
-            throw BADPARAMS_EXC;
-            //throw new IllegalArgumentException(
-            //        "iv is null or (iv.length < 2 * (wordSize / 8)).");
+        if (iv == null) {
+            throw new IllegalArgumentException("iv is null");
+        }
+        if (iv.length < 2 * (wordSize / 8)) {
+            throw new IllegalArgumentException(
+                    "iv.length < 2 * (wordSize / 8)");
         }
         this.version = version;
         this.rounds = rounds;
@@ -68,10 +67,12 @@
      */
     public RC5ParameterSpec(int version, int rounds,
                                 int wordSize, byte[] iv, int offset) {
-        if ((iv == null) || (iv.length - offset < 2 * (wordSize / 8))) {
-            throw BADPARAMS_EXC;
-            //throw new IllegalArgumentException(
-            //    "iv is null or (iv.length - offset < 2 * (wordSize / 8)).");
+        if (iv == null) {
+            throw new IllegalArgumentException("iv is null");
+        }
+        if (iv.length - offset < 2 * (wordSize / 8)) {
+            throw new IllegalArgumentException(
+                    "iv.length - offset < 2 * (wordSize / 8)");
         }
         this.version = version;
         this.rounds = rounds;



Mime
View raw message