pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/jruby/jruby-openssl/commit/1bf4bb52f6a06ef968adeb02f29528f206c4f9c1

ssorigen="anonymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/global-9c8f61f9f58ad7b2.css" /> Use ByteList instead of StringBuilder. Fixes #33 · jruby/jruby-openssl@1bf4bb5 · GitHub
Skip to content

Commit 1bf4bb5

Browse files
author
Sumit Vij
committed
Use ByteList instead of StringBuilder. Fixes #33
StringBuilder append method causes rubystring conversion to java string
1 parent 87fbbc8 commit 1bf4bb5

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public HMAC(Ruby runtime, RubyClass type) {
129129

130130
private Mac mac;
131131
private byte[] key;
132-
private final StringBuilder data = new StringBuilder(64);
132+
private ByteList data = new ByteList(64);
133133

134134
@JRubyMethod(visibility = Visibility.PRIVATE)
135135
public IRubyObject initialize(IRubyObject key, IRubyObject digest) {
@@ -171,21 +171,20 @@ public IRubyObject initialize_copy(final IRubyObject obj) {
171171
throw getRuntime().newNotImplementedError(e.getMessage());
172172
}
173173

174-
data.setLength(0);
175-
data.append( that.data );
174+
data = new ByteList(that.data);
176175

177176
return this;
178177
}
179178

180179
@JRubyMethod(name = { "update", "<<" })
181180
public IRubyObject update(final IRubyObject obj) {
182-
data.append(obj);
181+
data.append(obj.asString().getByteList());
183182
return this;
184183
}
185184

186185
@JRubyMethod
187186
public IRubyObject reset() {
188-
data.setLength(0);
187+
data = new ByteList(64);
189188
return this;
190189
}
191190

@@ -205,7 +204,8 @@ String getAlgorithm() {
205204

206205
private byte[] getSignatureBytes() {
207206
mac.reset();
208-
return mac.doFinal( data.toString().getBytes() );
207+
mac.update(data.getUnsafeBytes(), data.getBegin(), data.getRealSize());
208+
return mac.doFinal();
209209
}
210210

211211
private static String getDigestAlgorithmName(final IRubyObject digest) {

src/test/ruby/test_hmac.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# coding: US-ASCII
21
require File.expand_path('test_helper', File.dirname(__FILE__))
32

43
class TestHMAC < TestCase
@@ -32,6 +31,8 @@ def test_correct_digest
3231
assert_equal('c17c7b655b11574fea8d676a1fdc0ca8', @h2.hexdigest) # calculated on MRI
3332
@h2.update('DATA')
3433
assert_equal('9e50596c0fa1197f8587443a942d8afc', @h2.hexdigest) # calculated on MRI
34+
@h2.reset
35+
@h2.update("\xFF") # invalid utf-8 char
36+
assert_equal('0770623462e782b51bb0689a8ba4f3f1', @h2.hexdigest) # calcualted on MRI
3537
end
36-
3738
end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy