/*
* call-seq:
* digest_obj.hexdigest -> string
* digest_obj.hexdigest(string) -> string
*
* If none is given, returns the resulting hash value of the digest in
* a hex-encoded form, keeping the digest's state.
*
* If a _string_ is given, returns the hash value for the given
* _string_ in a hex-encoded form, resetting the digest to the initial
* state before and after the process.
*/
static VALUE
rb_digest_instance_hexdigest(int argc, VALUE *argv, VALUE self)
{
VALUE str, value;
if (rb_scan_args(argc, argv, "01", &str) > 0) {
rb_funcall(self, id_reset, 0);
rb_funcall(self, id_update, 1, str);
value = rb_funcall(self, id_finish, 0);
rb_funcall(self, id_reset, 0);
} else {
VALUE clone = rb_obj_clone(self);
value = rb_funcall(clone, id_finish, 0);
rb_funcall(clone, id_reset, 0);
}
return hexencode_str_new(value);
}