Module: Digest::KangarooTwelve
- Defined in:
- ext/digest/kangarootwelve/ext.c,
lib/digest/kangarootwelve/version.rb,
ext/digest/kangarootwelve/ext.c
Overview
The Digest::KangarooTwelve module is the main component of the KangarooTwelve extension for Ruby.
It contains singleton methods that can be used to create implementation classes. These implementation classes can then be used to create instances for producing hashes.
Example:
Digest::KangarooTwelve[32].new.update("one").update("two").digest
The implementation classes can also be used to directly produce hashes.
Example:
Digest::KangarooTwelve[32].hexdigest("1234")
The produced implementation classes and their instances can be used just like any other classes and instances in the Digest namespace that’s based on Digest::Base.
Defined Under Namespace
Constant Summary collapse
- VERSION =
"0.5.0"
- BLOCK_LENGTH =
8192 bytes
INT2FIX(KT_BLOCK_LENGTH)
- DEFAULT_DIGEST_LENGTH =
64 bytes (512 bits)
INT2FIX(KT_DEFAULT_DIGEST_LENGTH)
Class Method Summary collapse
-
.Digest::KangarooTwelve ⇒ Object
Creates an implementation class with specified digest length.
-
.Digest::KangarooTwelve.default ⇒ Object
Returns the default implementation class which has a digest length of 64 bytes, and doesn’t have a customization string.
-
.Digest::KangarooTwelve.implement(**opts) ⇒ Object
The Digest::KangarooTwelve::implement method is more configurable than the Digest::KangarooTwelve::[] method, and can implement classes with customization strings, a custom block length, and a different or anonymous name.
Class Method Details
.Digest::KangarooTwelve ⇒ Object
Creates an implementation class with specified digest length. This method is the simpler form of Digest::KangarooTwelve.implement.
The class is generated in the name form of Digest::KangarooTwelve_<digest_length>, and can be directly referenced after this method is called.
446 447 448 449 |
# File 'ext/digest/kangarootwelve/ext.c', line 446
static VALUE _Digest_KangarooTwelve_singleton_implement_simple(VALUE self, VALUE digest_length)
{
return implement(ID2SYM(_id_auto), digest_length, Qnil);
}
|
.Digest::KangarooTwelve.default ⇒ Object
Returns the default implementation class which has a digest length of 64 bytes, and doesn’t have a customization string.
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'ext/digest/kangarootwelve/ext.c', line 332
static VALUE _Digest_KangarooTwelve_singleton_default(VALUE self)
{
VALUE default_ = Qnil;
if (rb_ivar_defined(self, _id_default) == Qtrue)
default_ = rb_ivar_get(self, _id_default);
if (NIL_P(default_)) {
default_ = implement(ID2SYM(_id_auto), INT2FIX(KT_DEFAULT_DIGEST_LENGTH), Qnil);
rb_ivar_set(self, _id_default, default_);
}
Check_Type(default_, T_CLASS);
return default_;
}
|
.Digest::KangarooTwelve.implement(**opts) ⇒ Object
The Digest::KangarooTwelve::implement method is more configurable than the Digest::KangarooTwelve::[] method, and can implement classes with customization strings, a custom block length, and a different or anonymous name.
The method can be called with the following options:
- :n, :name
-
Specifies the name of the class, which would be placed in the Digest module.
The default value for this option is
:auto
, and it implies automatic generation of the name. The generated name is in the form of Digest::KangarooTwelve_<digest_length> if a customization string is not specified.If a customization string is specified, the format would be Digest::KangarooTwelve_<digest_length>_<cust_str_hex>.
Specifying a string would make the method produce Digest::<string>.
Specifying
nil
would produce an anonymous class. I.e., a class not assigned to any constant, and has no name returned with Class#name, butnil
. - :d, :digest_length
-
Specifies the digest length.
See Digest::KangarooTwelve::DEFAULT_DIGEST_LENGTH for the default value.
- :c, :customization
-
Specifies the customization string. Adding a customization string changes the resulting digest of every input.
- :ch, :customization_hex
-
Specifies the customization string in hex mode.
Calling the method with no argument is the same as calling the Digest::KangarooTwelve::default method.
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
# File 'ext/digest/kangarootwelve/ext.c', line 391
static VALUE _Digest_KangarooTwelve_singleton_implement(int argc, VALUE *argv, VALUE self)
{
VALUE opts, name, digest_length, customization;
rb_scan_args(argc, argv, "0:", &opts);
if (NIL_P(opts)) {
name = ID2SYM(_id_auto);
digest_length = customization = Qnil;
} else {
name = rb_hash_lookup2(opts, ID2SYM(_id_n), Qundef);
if (name == Qundef)
name = rb_hash_lookup2(opts, ID2SYM(_id_name), ID2SYM(_id_auto));
digest_length = rb_hash_lookup2(opts, ID2SYM(_id_d), Qundef);
if (digest_length == Qundef)
digest_length = rb_hash_lookup2(opts, ID2SYM(_id_digest_length), Qnil);
customization = rb_hash_lookup2(opts, ID2SYM(_id_c), Qundef);
if (customization == Qundef)
customization = rb_hash_lookup2(opts, ID2SYM(_id_customization), Qundef);
if (customization == Qundef) {
VALUE customization_hex = rb_hash_lookup2(opts, ID2SYM(_id_customization_hex), Qundef);
if (customization_hex == Qundef)
customization_hex = rb_hash_lookup2(opts, ID2SYM(_id_ch), Qundef);
if (customization_hex == Qundef) {
customization = Qnil;
} else {
if (TYPE(customization_hex) != T_STRING)
rb_raise(rb_eTypeError, "Customization argument not a string.");
customization = hex_decode_str(customization_hex);
}
}
}
return implement(name, digest_length, customization);
}
|