Skip to content

Commit 9968234

Browse files
karesclaude
andcommitted
[refactor] use constant-time comparison in SimpleSecretKey
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b08e16f commit 9968234

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

src/main/java/org/jruby/ext/openssl/SimpleSecretKey.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
***** END LICENSE BLOCK *****/
2828
package org.jruby.ext.openssl;
2929

30+
import java.security.MessageDigest;
3031
import javax.crypto.SecretKey;
3132

3233
/**
@@ -68,12 +69,8 @@ public String getFormat() {
6869

6970
public boolean equals(Object o) {
7071
if ( o instanceof SimpleSecretKey ) {
71-
byte[] ovalue = ((SimpleSecretKey) o).value;
72-
if ( value.length != ovalue.length ) return false;
73-
for ( int i = 0; i < value.length; i++ ) {
74-
if ( value[i] != ovalue[i] ) return false;
75-
}
76-
return algorithm.equals( ((SimpleSecretKey) o).algorithm );
72+
SimpleSecretKey other = (SimpleSecretKey) o;
73+
return algorithm.equals(other.algorithm) && MessageDigest.isEqual(value, other.value);
7774
}
7875
return false;
7976
}

0 commit comments

Comments
 (0)