You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by mu...@apache.org on 2009/09/17 22:12:16 UTC

svn commit: r816365 - in /xml/security/trunk/src/org/apache/xml/security/keys/content/x509: XMLX509Certificate.java XMLX509IssuerSerial.java XMLX509SKI.java XMLX509SubjectName.java

Author: mullan
Date: Thu Sep 17 20:12:16 2009
New Revision: 816365

URL: http://svn.apache.org/viewvc?rev=816365&view=rev
Log:
Partial fix for bug 47863: Fix findbug warnings in equals method. Also improve h
ashCode method.


Modified:
    xml/security/trunk/src/org/apache/xml/security/keys/content/x509/XMLX509Certificate.java
    xml/security/trunk/src/org/apache/xml/security/keys/content/x509/XMLX509IssuerSerial.java
    xml/security/trunk/src/org/apache/xml/security/keys/content/x509/XMLX509SKI.java
    xml/security/trunk/src/org/apache/xml/security/keys/content/x509/XMLX509SubjectName.java

Modified: xml/security/trunk/src/org/apache/xml/security/keys/content/x509/XMLX509Certificate.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/apache/xml/security/keys/content/x509/XMLX509Certificate.java?rev=816365&r1=816364&r2=816365&view=diff
==============================================================================
--- xml/security/trunk/src/org/apache/xml/security/keys/content/x509/XMLX509Certificate.java (original)
+++ xml/security/trunk/src/org/apache/xml/security/keys/content/x509/XMLX509Certificate.java Thu Sep 17 20:12:16 2009
@@ -1,5 +1,5 @@
 /*
- * Copyright  1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2009 The Apache Software Foundation.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
 import java.security.cert.CertificateException;
 import java.security.cert.CertificateFactory;
 import java.security.cert.X509Certificate;
+import java.util.Arrays;
 
 import org.apache.xml.security.exceptions.XMLSecurityException;
 import org.apache.xml.security.utils.Constants;
@@ -138,17 +139,12 @@
     /** @inheritDoc */
     public boolean equals(Object obj) {
 
-        if (obj == null) {
-	    return false;
-        }
-        if (!this.getClass().getName().equals(obj.getClass().getName())) {
+        if (!(obj instanceof XMLX509Certificate)) {
             return false;
         }
         XMLX509Certificate other = (XMLX509Certificate) obj;
         try {
-
-            /** $todo$ or should be create X509Certificates and use the equals() from the Certs */
-            return java.security.MessageDigest.isEqual
+            return Arrays.equals
 		(other.getCertificateBytes(), this.getCertificateBytes());
         } catch (XMLSecurityException ex) {
             return false;
@@ -156,9 +152,14 @@
     }
 
     public int hashCode() {
-	// Uncomment when JDK 1.4 is required
-	// assert false : "hashCode not designed";
-	return 72;
+	int result = 17;
+        try {
+            byte[] bytes = getCertificateBytes();
+            for (int i = 0; i < bytes.length; i++) {
+                result = 31 * result + bytes[i];
+            }
+        } catch (XMLSecurityException e) {}
+        return result;
     }
 
    /** @inheritDoc */

Modified: xml/security/trunk/src/org/apache/xml/security/keys/content/x509/XMLX509IssuerSerial.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/apache/xml/security/keys/content/x509/XMLX509IssuerSerial.java?rev=816365&r1=816364&r2=816365&view=diff
==============================================================================
--- xml/security/trunk/src/org/apache/xml/security/keys/content/x509/XMLX509IssuerSerial.java (original)
+++ xml/security/trunk/src/org/apache/xml/security/keys/content/x509/XMLX509IssuerSerial.java Thu Sep 17 20:12:16 2009
@@ -1,5 +1,5 @@
 /*
- * Copyright  1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2009 The Apache Software Foundation.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -145,10 +145,7 @@
     /** @inheritDoc */
     public boolean equals(Object obj) {
 
-	if (obj == null) {
-	    return false;
-	}
-        if (!this.getClass().getName().equals(obj.getClass().getName())) {
+        if (!(obj instanceof XMLX509IssuerSerial)) {
             return false;
         }
 
@@ -159,9 +156,10 @@
     }
 
     public int hashCode() {
-	// uncomment when JDK 1.4 is required
-	// assert false : "hashCode not designed";
-	return 82;
+        int result = 17;
+        result = 31 * result + getSerialNumber().hashCode();
+        result = 31 * result + getIssuerName().hashCode();
+        return result;
     }
 
     /** @inheritDoc */

Modified: xml/security/trunk/src/org/apache/xml/security/keys/content/x509/XMLX509SKI.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/apache/xml/security/keys/content/x509/XMLX509SKI.java?rev=816365&r1=816364&r2=816365&view=diff
==============================================================================
--- xml/security/trunk/src/org/apache/xml/security/keys/content/x509/XMLX509SKI.java (original)
+++ xml/security/trunk/src/org/apache/xml/security/keys/content/x509/XMLX509SKI.java Thu Sep 17 20:12:16 2009
@@ -1,5 +1,5 @@
 /*
- * Copyright  1999-2009 The Apache Software Foundation.
+ * Copyright 1999-2009 The Apache Software Foundation.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
 package org.apache.xml.security.keys.content.x509;
 
 import java.security.cert.X509Certificate;
+import java.util.Arrays;
 
 import org.apache.xml.security.exceptions.XMLSecurityException;
 import org.apache.xml.security.utils.Base64;
@@ -143,27 +144,29 @@
 
     /** @inheritDoc */
     public boolean equals(Object obj) {
-	if (obj == null) {
-	    return false;
-	}
-        if (!this.getClass().getName().equals(obj.getClass().getName())) {
+        if (!(obj instanceof XMLX509SKI)) {
             return false;
         }
 
         XMLX509SKI other = (XMLX509SKI) obj;
 
         try {
-            return java.security.MessageDigest.isEqual(other.getSKIBytes(),
-                                        this.getSKIBytes());
+            return Arrays.equals(other.getSKIBytes(), this.getSKIBytes());
         } catch (XMLSecurityException ex) {
             return false;
         }
     }
 
     public int hashCode() {
-	// uncomment when JDK 1.4 is required
-	// assert false : "hashCode not designed";
-	return 92;
+        int result = 17;
+        try {
+            byte[] bytes = getSKIBytes();
+            for (int i = 0; i < bytes.length; i++) {
+                result = 31 * result + bytes[i];
+            }
+        } catch (XMLSecurityException e) {}
+        return result;
+
     }
 
     /** @inheritDoc */

Modified: xml/security/trunk/src/org/apache/xml/security/keys/content/x509/XMLX509SubjectName.java
URL: http://svn.apache.org/viewvc/xml/security/trunk/src/org/apache/xml/security/keys/content/x509/XMLX509SubjectName.java?rev=816365&r1=816364&r2=816365&view=diff
==============================================================================
--- xml/security/trunk/src/org/apache/xml/security/keys/content/x509/XMLX509SubjectName.java (original)
+++ xml/security/trunk/src/org/apache/xml/security/keys/content/x509/XMLX509SubjectName.java Thu Sep 17 20:12:16 2009
@@ -80,11 +80,7 @@
 
     /** @inheritDoc */
     public boolean equals(Object obj) {
-	if (obj == null) {
-	    return false;
-	}
-
-        if (!this.getClass().getName().equals(obj.getClass().getName())) {
+        if (!(obj instanceof XMLX509SubjectName)) {
             return false;
         }
 
@@ -96,9 +92,9 @@
    }
 
     public int hashCode() {
-	// uncomment when JDK 1.4 is required
-	// assert false : "hashCode not designed";
-	return 52;
+        int result = 17;
+        result = 31 * result + this.getSubjectName().hashCode();
+        return result;
     }
    
    /** @inheritDoc */