| Module | Digest::Instance |
| In: |
digest/digest.c
digest/lib/digest.rb |
Updates the digest using a given string and returns self.
The update() method and the left-shift operator are overridden by each implementation subclass. (One should be an alias for the other)
/*
* call-seq:
* digest_obj.update(string) -> digest_obj
* digest_obj << string -> digest_obj
*
* Updates the digest using a given _string_ and returns self.
*
* The update() method and the left-shift operator are overridden by
* each implementation subclass. (One should be an alias for the
* other)
*/
static VALUE
rb_digest_instance_update(VALUE self, VALUE str)
{
rb_raise(rb_eRuntimeError, "%s does not implement update()", RSTRING_PTR(rb_inspect(self)));
}
If a string is given, checks whether it is equal to the hex-encoded hash value of the digest object. If another digest instance is given, checks whether they have the same hash value. Otherwise returns false.
/*
* call-seq:
* digest_obj == another_digest_obj -> boolean
* digest_obj == string -> boolean
*
* If a string is given, checks whether it is equal to the hex-encoded
* hash value of the digest object. If another digest instance is
* given, checks whether they have the same hash value. Otherwise
* returns false.
*/
static VALUE
rb_digest_instance_equal(VALUE self, VALUE other)
{
VALUE str1, str2;
if (rb_obj_is_kind_of(other, rb_mDigest_Instance) == Qtrue) {
str1 = rb_digest_instance_digest(0, 0, self);
str2 = rb_digest_instance_digest(0, 0, other);
} else {
str1 = rb_digest_instance_to_s(self);
str2 = other;
}
/* never blindly assume that subclass methods return strings */
StringValue(str1);
StringValue(str2);
if (RSTRING_LEN(str1) == RSTRING_LEN(str2) &&
rb_str_cmp(str1, str2) == 0) {
return Qtrue;
}
return Qfalse;
}
Returns the block length of the digest.
This method is overridden by each implementation subclass.
/*
* call-seq:
* digest_obj.block_length -> integer
*
* Returns the block length of the digest.
*
* This method is overridden by each implementation subclass.
*/
static VALUE
rb_digest_instance_block_length(VALUE self)
{
rb_raise(rb_eRuntimeError, "%s does not implement block_length()", RSTRING_PTR(rb_inspect(self)));
}
If none is given, returns the resulting hash value of the digest, keeping the digest‘s state.
If a string is given, returns the hash value for the given string, resetting the digest to the initial state before and after the process.
/*
* call-seq:
* digest_obj.digest -> string
* digest_obj.digest(string) -> string
*
* If none is given, returns the resulting hash value of the digest,
* keeping the digest's state.
*
* If a _string_ is given, returns the hash value for the given
* _string_, resetting the digest to the initial state before and
* after the process.
*/
static VALUE
rb_digest_instance_digest(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 value;
}
Returns the resulting hash value and resets the digest to the initial state.
/*
* call-seq:
* digest_obj.digest! -> string
*
* Returns the resulting hash value and resets the digest to the
* initial state.
*/
static VALUE
rb_digest_instance_digest_bang(VALUE self)
{
VALUE value = rb_funcall(self, id_finish, 0);
rb_funcall(self, id_reset, 0);
return value;
}
Returns the length of the hash value of the digest.
This method should be overridden by each implementation subclass. If not, digest_obj.digest().length() is returned.
/*
* call-seq:
* digest_obj.digest_length -> integer
*
* Returns the length of the hash value of the digest.
*
* This method should be overridden by each implementation subclass.
* If not, digest_obj.digest().length() is returned.
*/
static VALUE
rb_digest_instance_digest_length(VALUE self)
{
/* subclasses really should redefine this method */
VALUE digest = rb_digest_instance_digest(0, 0, self);
/* never blindly assume that #digest() returns a string */
StringValue(digest);
return INT2NUM(RSTRING_LEN(digest));
}
Finishes the digest and returns the resulting hash value.
This method is overridden by each implementation subclass and often made private, because some of those subclasses may leave internal data uninitialized. Do not call this method from outside. Use digest!() instead, which ensures that internal data be reset for security reasons.
/*
* call-seq:
* digest_obj.instance_eval { finish } -> digest_obj
*
* Finishes the digest and returns the resulting hash value.
*
* This method is overridden by each implementation subclass and often
* made private, because some of those subclasses may leave internal
* data uninitialized. Do not call this method from outside. Use
* #digest!() instead, which ensures that internal data be reset for
* security reasons.
*/
static VALUE
rb_digest_instance_finish(VALUE self)
{
rb_raise(rb_eRuntimeError, "%s does not implement finish()", RSTRING_PTR(rb_inspect(self)));
}
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.
/*
* 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);
}
Returns the resulting hash value and resets the digest to the initial state.
/*
* call-seq:
* digest_obj.hexdigest! -> string
*
* Returns the resulting hash value and resets the digest to the
* initial state.
*/
static VALUE
rb_digest_instance_hexdigest_bang(VALUE self)
{
VALUE value = rb_funcall(self, id_finish, 0);
rb_funcall(self, id_reset, 0);
return hexencode_str_new(value);
}
Creates a printable version of the digest object.
/*
* call-seq:
* digest_obj.inspect -> string
*
* Creates a printable version of the digest object.
*/
static VALUE
rb_digest_instance_inspect(VALUE self)
{
VALUE str;
size_t digest_len = 32; /* about this size at least */
char *cname;
cname = rb_obj_classname(self);
/* #<Digest::ClassName: xxxxx...xxxx> */
str = rb_str_buf_new(2 + strlen(cname) + 2 + digest_len * 2 + 1);
rb_str_buf_cat2(str, "#<");
rb_str_buf_cat2(str, cname);
rb_str_buf_cat2(str, ": ");
rb_str_buf_append(str, rb_digest_instance_hexdigest(0, 0, self));
rb_str_buf_cat2(str, ">");
return str;
}
Returns digest_obj.digest_length().
/*
* call-seq:
* digest_obj.length -> integer
* digest_obj.size -> integer
*
* Returns digest_obj.digest_length().
*/
static VALUE
rb_digest_instance_length(VALUE self)
{
return rb_funcall(self, id_digest_length, 0);
}
Returns a new, initialized copy of the digest object. Equivalent to digest_obj.clone().reset().
/*
* call-seq:
* digest_obj.new -> another_digest_obj
*
* Returns a new, initialized copy of the digest object. Equivalent
* to digest_obj.clone().reset().
*/
static VALUE
rb_digest_instance_new(VALUE self)
{
VALUE clone = rb_obj_clone(self);
rb_funcall(clone, id_reset, 0);
return clone;
}
Resets the digest to the initial state and returns self.
This method is overridden by each implementation subclass.
/*
* call-seq:
* digest_obj.reset -> digest_obj
*
* Resets the digest to the initial state and returns self.
*
* This method is overridden by each implementation subclass.
*/
static VALUE
rb_digest_instance_reset(VALUE self)
{
rb_raise(rb_eRuntimeError, "%s does not implement reset()", RSTRING_PTR(rb_inspect(self)));
}
Returns digest_obj.digest_length().
/*
* call-seq:
* digest_obj.length -> integer
* digest_obj.size -> integer
*
* Returns digest_obj.digest_length().
*/
static VALUE
rb_digest_instance_length(VALUE self)
{
return rb_funcall(self, id_digest_length, 0);
}
Returns digest_obj.hexdigest().
/*
* call-seq:
* digest_obj.to_s -> string
*
* Returns digest_obj.hexdigest().
*/
static VALUE
rb_digest_instance_to_s(VALUE self)
{
return rb_funcall(self, id_hexdigest, 0);
}
Updates the digest using a given string and returns self.
The update() method and the left-shift operator are overridden by each implementation subclass. (One should be an alias for the other)
/*
* call-seq:
* digest_obj.update(string) -> digest_obj
* digest_obj << string -> digest_obj
*
* Updates the digest using a given _string_ and returns self.
*
* The update() method and the left-shift operator are overridden by
* each implementation subclass. (One should be an alias for the
* other)
*/
static VALUE
rb_digest_instance_update(VALUE self, VALUE str)
{
rb_raise(rb_eRuntimeError, "%s does not implement update()", RSTRING_PTR(rb_inspect(self)));
}
ruby-doc.org is a community service provided by Happy Camper Studios, a Phoenix, Arizona, Ruby application development company.
Documentation content on ruby-doc.org is provided by remarkable members of the Ruby community.
For more information on the Ruby programming language, visit ruby-lang.org.
Want to help improve Ruby's API docs? See Ruby Documentation Guidelines.