jdk/src/share/classes/com/sun/security/sasl/digest/DigestMD5Base.java
changeset 10336 0bb1999251f8
parent 5506 202f599c92aa
child 14340 e150cbaf584e
--- a/jdk/src/share/classes/com/sun/security/sasl/digest/DigestMD5Base.java	Mon Aug 15 12:56:01 2011 -0700
+++ b/jdk/src/share/classes/com/sun/security/sasl/digest/DigestMD5Base.java	Mon Aug 15 11:48:20 2011 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,21 +28,15 @@
 import java.util.Map;
 import java.util.Arrays;
 import java.util.List;
-import java.util.Set;
-import java.util.logging.Logger;
 import java.util.logging.Level;
 import java.math.BigInteger;
 import java.util.Random;
-import java.security.Provider;
 
-import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.UnsupportedEncodingException;
 import java.io.IOException;
 
 import java.security.MessageDigest;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
 import java.security.NoSuchAlgorithmException;
 import java.security.InvalidKeyException;
 import java.security.spec.KeySpec;
@@ -53,7 +47,6 @@
 import javax.crypto.SecretKey;
 import javax.crypto.Mac;
 import javax.crypto.SecretKeyFactory;
-import javax.crypto.BadPaddingException;
 import javax.crypto.NoSuchPaddingException;
 import javax.crypto.IllegalBlockSizeException;
 import javax.crypto.spec.IvParameterSpec;
@@ -175,8 +168,9 @@
      *
      * @throws SaslException If invalid value found in props.
      */
-    protected DigestMD5Base(Map props, String className, int firstStep,
-        String digestUri, CallbackHandler cbh) throws SaslException {
+    protected DigestMD5Base(Map<String, ?> props, String className,
+        int firstStep, String digestUri, CallbackHandler cbh)
+        throws SaslException {
         super(props, className); // sets QOP, STENGTH and BUFFER_SIZE
 
         step = firstStep;
@@ -791,7 +785,7 @@
                     }
                 } else if (realmChoices != null && i == realmIndex) {
                     // > 1 realm specified
-                    if (realmChoices.size() == 0) {
+                    if (realmChoices.isEmpty()) {
                         realmChoices.add(valueTable[i]); // add existing one
                     }
                     realmChoices.add(value);  // add new one
@@ -1585,47 +1579,45 @@
         KeySpec spec = null;
         SecretKeyFactory desFactory =
             SecretKeyFactory.getInstance(desStrength);
-
-        if (desStrength.equals("des")) {
-            spec = new DESKeySpec(subkey1, 0);
-            if (logger.isLoggable(Level.FINEST)) {
-                traceOutput(DP_CLASS_NAME, "makeDesKeys",
-                    "DIGEST42:DES key input: ", input);
-                traceOutput(DP_CLASS_NAME, "makeDesKeys",
-                    "DIGEST43:DES key parity-adjusted: ", subkey1);
-                traceOutput(DP_CLASS_NAME, "makeDesKeys",
-                    "DIGEST44:DES key material: ", ((DESKeySpec)spec).getKey());
-                logger.log(Level.FINEST, "DIGEST45: is parity-adjusted? {0}",
-                    Boolean.valueOf(DESKeySpec.isParityAdjusted(subkey1, 0)));
-            }
-
-        } else if (desStrength.equals("desede")) {
-
-            // Generate second subkey using second 7 bytes
-            byte[] subkey2 = addDesParity(input, 7, 7);
-
-            // Construct 24-byte encryption-decryption-encryption sequence
-            byte[] ede = new byte[subkey1.length*2+subkey2.length];
-            System.arraycopy(subkey1, 0, ede, 0, subkey1.length);
-            System.arraycopy(subkey2, 0, ede, subkey1.length, subkey2.length);
-            System.arraycopy(subkey1, 0, ede, subkey1.length+subkey2.length,
-                subkey1.length);
-
-            spec = new DESedeKeySpec(ede, 0);
-            if (logger.isLoggable(Level.FINEST)) {
-                traceOutput(DP_CLASS_NAME, "makeDesKeys",
-                    "DIGEST46:3DES key input: ", input);
-                traceOutput(DP_CLASS_NAME, "makeDesKeys",
-                    "DIGEST47:3DES key ede: ", ede);
-                traceOutput(DP_CLASS_NAME, "makeDesKeys",
-                    "DIGEST48:3DES key material: ",
-                    ((DESedeKeySpec)spec).getKey());
-                logger.log(Level.FINEST, "DIGEST49: is parity-adjusted? ",
-                    Boolean.valueOf(DESedeKeySpec.isParityAdjusted(ede, 0)));
-            }
-        } else {
-            throw new IllegalArgumentException("Invalid DES strength:" +
-                desStrength);
+        switch (desStrength) {
+            case "des":
+                spec = new DESKeySpec(subkey1, 0);
+                if (logger.isLoggable(Level.FINEST)) {
+                    traceOutput(DP_CLASS_NAME, "makeDesKeys",
+                        "DIGEST42:DES key input: ", input);
+                    traceOutput(DP_CLASS_NAME, "makeDesKeys",
+                        "DIGEST43:DES key parity-adjusted: ", subkey1);
+                    traceOutput(DP_CLASS_NAME, "makeDesKeys",
+                        "DIGEST44:DES key material: ", ((DESKeySpec)spec).getKey());
+                    logger.log(Level.FINEST, "DIGEST45: is parity-adjusted? {0}",
+                        Boolean.valueOf(DESKeySpec.isParityAdjusted(subkey1, 0)));
+                }
+                break;
+            case "desede":
+                // Generate second subkey using second 7 bytes
+                byte[] subkey2 = addDesParity(input, 7, 7);
+                // Construct 24-byte encryption-decryption-encryption sequence
+                byte[] ede = new byte[subkey1.length*2+subkey2.length];
+                System.arraycopy(subkey1, 0, ede, 0, subkey1.length);
+                System.arraycopy(subkey2, 0, ede, subkey1.length, subkey2.length);
+                System.arraycopy(subkey1, 0, ede, subkey1.length+subkey2.length,
+                    subkey1.length);
+                spec = new DESedeKeySpec(ede, 0);
+                if (logger.isLoggable(Level.FINEST)) {
+                    traceOutput(DP_CLASS_NAME, "makeDesKeys",
+                        "DIGEST46:3DES key input: ", input);
+                    traceOutput(DP_CLASS_NAME, "makeDesKeys",
+                        "DIGEST47:3DES key ede: ", ede);
+                    traceOutput(DP_CLASS_NAME, "makeDesKeys",
+                        "DIGEST48:3DES key material: ",
+                        ((DESedeKeySpec)spec).getKey());
+                    logger.log(Level.FINEST, "DIGEST49: is parity-adjusted? ",
+                        Boolean.valueOf(DESedeKeySpec.isParityAdjusted(ede, 0)));
+                }
+                break;
+            default:
+                throw new IllegalArgumentException("Invalid DES strength:" +
+                    desStrength);
         }
         return desFactory.generateSecret(spec);
     }