< prev index next >

src/java.base/share/classes/sun/security/ssl/SessionId.java

Print this page

        

@@ -25,10 +25,11 @@
 
 
 package sun.security.ssl;
 
 import java.security.SecureRandom;
+import java.util.Arrays;
 import javax.net.ssl.SSLProtocolException;
 
 /**
  * Encapsulates an SSL session ID.  SSL Session IDs are not reused by
  * servers during the lifetime of any sessions it created.  Sessions may

@@ -89,34 +90,19 @@
 
     /** Returns a value which is the same for session IDs which are equal */
     @Override
     public int hashCode ()
     {
-        int     retval = 0;
-
-        for (int i = 0; i < sessionId.length; i++)
-            retval += sessionId [i];
-        return retval;
+        return Arrays.hashCode(sessionId);
     }
 
     /** Returns true if the parameter is the same session ID */
     @Override
     public boolean equals (Object obj)
     {
-        if (!(obj instanceof SessionId))
-            return false;
-
-        SessionId s = (SessionId) obj;
-        byte[] b = s.getId ();
-
-        if (b.length != sessionId.length)
-            return false;
-        for (int i = 0; i < sessionId.length; i++) {
-            if (b [i] != sessionId [i])
-                return false;
-        }
-        return true;
+        return obj instanceof SessionId &&
+               Arrays.equals(sessionId, ((SessionId)obj).sessionId);
     }
 
     /**
      * Checks the length of the session ID to make sure it sits within
      * the range called out in the specification
< prev index next >