File tree Expand file tree Collapse file tree
main/java/org/jruby/ext/openssl Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff line change 1- # coding: US-ASCII
21require File . expand_path ( 'test_helper' , File . dirname ( __FILE__ ) )
32
43class 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-
3738end
You can’t perform that action at this time.
0 commit comments