Skip to content

Commit 65c4ce0

Browse files
committed
digest: remove optional parameter from OpenSSL::Digest#finish
OpenSSL::Digest#finish overrides Digest::Instance#finish and is called from the Digest::Class framework in the digest library. This method is not supposed to take any arguments, as suggested by the RDoc comment for Digest::Instance#finish. It is a private method and not exposed to users. Let's remove it. This optional parameter has been there since r15602 in Ruby trunk, which converted OpenSSL::Digest to the current state, a subclass of Digest::Class.
1 parent 9cc8a83 commit 65c4ce0

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

ext/openssl/ossl_digest.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -218,24 +218,15 @@ ossl_digest_update(VALUE self, VALUE data)
218218
*
219219
*/
220220
static VALUE
221-
ossl_digest_finish(int argc, VALUE *argv, VALUE self)
221+
ossl_digest_finish(VALUE self)
222222
{
223223
EVP_MD_CTX *ctx;
224224
VALUE str;
225-
int out_len;
226225

227226
GetDigest(self, ctx);
228227
rb_scan_args(argc, argv, "01", &str);
229-
out_len = EVP_MD_CTX_size(ctx);
230-
231-
if (NIL_P(str)) {
232-
str = rb_str_new(NULL, out_len);
233-
} else {
234-
StringValue(str);
235-
rb_str_modify(str);
236-
rb_str_resize(str, out_len);
237-
}
238228

229+
str = rb_str_new(NULL, EVP_MD_CTX_size(ctx));
239230
if (!EVP_DigestFinal_ex(ctx, (unsigned char *)RSTRING_PTR(str), NULL))
240231
ossl_raise(eDigestError, "EVP_DigestFinal_ex");
241232

@@ -418,7 +409,7 @@ Init_ossl_digest(void)
418409
rb_define_method(cDigest, "reset", ossl_digest_reset, 0);
419410
rb_define_method(cDigest, "update", ossl_digest_update, 1);
420411
rb_define_alias(cDigest, "<<", "update");
421-
rb_define_private_method(cDigest, "finish", ossl_digest_finish, -1);
412+
rb_define_private_method(cDigest, "finish", ossl_digest_finish, 0);
422413
rb_define_method(cDigest, "digest_length", ossl_digest_size, 0);
423414
rb_define_method(cDigest, "block_length", ossl_digest_block_length, 0);
424415

0 commit comments

Comments
 (0)