Skip to content

Commit 39d7205

Browse files
committed
[refactor] do some less byte copy-ing
1 parent 48aaa21 commit 39d7205

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.math.BigInteger;
3232

3333
import java.security.GeneralSecurityException;
34+
import java.security.MessageDigest;
3435

3536
import org.bouncycastle.asn1.*;
3637
import org.bouncycastle.asn1.x500.X500Name;
@@ -430,7 +431,7 @@ private byte[] publicKeyIdentifier(final ThreadContext context) {
430431
der = ASN1.decode(context, ASN1._ASN1(runtime), pkey.callMethod(context, "to_der"));
431432
der = der.callMethod(context, "value").callMethod(context, "[]", runtime.newFixnum(1)).callMethod(context, "value");
432433
}
433-
return getSHA1Digest(runtime, der.asString().getBytes());
434+
return getSHA1Digest(runtime, der.asString().getByteList());
434435
}
435436

436437
private IRubyObject getPublicKey(final ThreadContext context) {
@@ -466,9 +467,11 @@ private BigInteger getIssuerSerialNumber(final ThreadContext context) {
466467
return serial.isNil() ? null : ((BN) serial).getValue();
467468
}
468469

469-
private static byte[] getSHA1Digest(Ruby runtime, byte[] bytes) {
470+
private static byte[] getSHA1Digest(Ruby runtime, ByteList bytes) {
470471
try {
471-
return SecurityHelper.getMessageDigest("SHA-1").digest(bytes);
472+
MessageDigest sha1 = SecurityHelper.getMessageDigest("SHA-1");
473+
sha1.update(bytes.unsafeBytes(), bytes.getBegin(), bytes.getRealSize());
474+
return sha1.digest();
472475
}
473476
catch (GeneralSecurityException e) {
474477
throw newExtensionError(runtime, e.getMessage());

0 commit comments

Comments
 (0)