Re: [PR] Adding hashcode to DOMKeyValue [santuario-xml-sec urity-java]

seanjmullan (via GitHub) <[email protected]>
Newsgroups gmane.text.xml.security.devel
Message-ID <PR_kwDOD7oF986WsRGx-564f03f7-a3f8-40cd-a387-9517e2004021@gitbox.apache.org>
seanjmullan commented on code in PR #476:
URL: https://github.com/apache/santuario-xml-security-java/pull/476#discussion_r2096114319


##########
src/main/java/org/apache/jcp/xml/dsig/internal/dom/DOMKeyValue.java:
##########
@@ -264,6 +264,22 @@ public boolean equals(Object obj) {
                 return false;
             }
         }
+
+        @Override
+        public int hashCode() {
+            int result = 17;
+            try {
+                if (getPublicKey() != null) {
+                    RSAPublicKey rsaKey = (RSAPublicKey)getPublicKey();
+                    result = 31 * result + rsaKey.getPublicExponent().hashCode();
+                    result = 31 * result + rsaKey.getModulus().hashCode();
+                }
+            } catch (KeyException ke) {
+                // no key available

Review Comment:
   I would probably return `super.hashCode(`) here and also change line 264 to return `super.equals()` so if the key can't be extracted only an exact match of the same object will equal.
   
   We should probably add equals/hashCode methods for the other *KeyValue subclasses, though we could do that in another PR. Note that the XMLDSig API does not require implementations to override equals/hashCode. However, it is useful for testing purposes.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.