Class: Digest::Class

Inherits:
Object
  • Object
show all
Includes:
Instance
Defined in:
digest.c,
lib/digest.rb

Overview

This module stands as a base class for digest implementation classes.

Direct Known Subclasses

Base, HMAC, SHA2

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Instance

#<<, #==, #base64digest, #base64digest!, #block_length, #bubblebabble, #digest, #digest!, #digest_length, #file, #hexdigest, #hexdigest!, #inspect, #length, #new, #reset, #size, #to_s, #update

Constructor Details

- (Object) initialize

:nodoc:



466
467
468
469
470
# File 'digest.c', line 466

static VALUE
rb_digest_class_init(VALUE self)
{
    return self;
}

Class Method Details

+ (Object) base64digest(str, *args)

Returns the base64 encoded hash value of a given string. The return value is properly padded with '=' and contains no line feeds.



35
36
37
# File 'lib/digest.rb', line 35

def self.base64digest(str, *args)
  [digest(str, *args)].pack('m0')
end

+ (Object) Digest::Class.bubblebabble(string, ...)

Returns the BubbleBabble encoded hash value of a given string.



99
100
101
102
103
# File 'bubblebabble/bubblebabble.c', line 99

static VALUE
rb_digest_class_s_bubblebabble(int argc, VALUE *argv, VALUE klass)
{
    return bubblebabble_str_new(rb_funcall2(klass, id_digest, argc, argv));
}

+ (Object) Digest::Class.digest(string, *parameters)

Returns the hash value of a given string. This is equivalent to Digest::Class.new(*parameters).digest(string), where extra parameters, if any, are passed through to the constructor and the string is passed to #digest().



430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
# File 'digest.c', line 430

static VALUE
rb_digest_class_s_digest(int argc, VALUE *argv, VALUE klass)
{
    VALUE str;
    volatile VALUE obj;

    if (argc < 1) {
        rb_raise(rb_eArgError, "no data given");
    }

    str = *argv++;
    argc--;

    StringValue(str);

    obj = rb_obj_alloc(klass);
    rb_obj_call_init(obj, argc, argv);

    return rb_funcall(obj, id_digest, 1, str);
}

+ (Object) file(name)

creates a digest object and reads a given file, name.

p Digest::SHA256.file("X11R6.8.2-src.tar.bz2").hexdigest
# => "f02e3c85572dc9ad7cb77c2a638e3be24cc1b5bea9fdbb0b0299c9668475c534"


28
29
30
# File 'lib/digest.rb', line 28

def self.file(name)
  new.file(name)
end

+ (Object) Digest::Class.hexdigest(string[, ...])

Returns the hex-encoded hash value of a given string. This is almost equivalent to Digest.hexencode(Digest::Class.new(*parameters).digest(string)).



459
460
461
462
463
# File 'digest.c', line 459

static VALUE
rb_digest_class_s_hexdigest(int argc, VALUE *argv, VALUE klass)
{
    return hexencode_str_new(rb_funcall2(klass, id_digest, argc, argv));
}