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 @@ -168,7 +168,7 @@ public IRubyObject initialize_copy(final IRubyObject obj) {
168168
169169 @ JRubyMethod (name = { "update" , "<<" })
170170 public IRubyObject update (final IRubyObject obj ) {
171- data .append (obj .asString ().getByteList ());
171+ data .append (obj .convertToString ().getByteList ());
172172 return this ;
173173 }
174174
@@ -188,10 +188,6 @@ public IRubyObject hexdigest() {
188188 return getRuntime ().newString ( toHEX (getSignatureBytes ()) );
189189 }
190190
191- String getAlgorithm () {
192- return mac .getAlgorithm ();
193- }
194-
195191 private byte [] getSignatureBytes () {
196192 mac .reset ();
197193 mac .update (data .getUnsafeBytes (), data .getBegin (), data .getRealSize ());
Original file line number Diff line number Diff line change @@ -41,4 +41,20 @@ def test_hexdigest_with_empty_key
4141 assert_equal "4acb10ca3965a14a080297db0921950c" , result
4242 end
4343
44+ def test_update_string_coercion
45+ h1 = OpenSSL ::HMAC . new ( "KEY" , "SHA256" )
46+ h2 = OpenSSL ::HMAC . new ( "KEY" , "SHA256" )
47+
48+ str_like = Object . new
49+ def str_like . to_str
50+ "DATA"
51+ end
52+
53+ h1 . update ( str_like )
54+ h2 . update ( "DATA" )
55+ assert_equal h2 . digest , h1 . digest
56+
57+ assert_raise ( TypeError ) { h1 . update ( 1 ) }
58+ end
59+
4460end
You can’t perform that action at this time.
0 commit comments