Class: Digest::Base

Inherits:
Class
  • Object
show all
Defined in:
digest.c,
digest.c

Overview

This abstract class provides a common interface to message digest implementation classes written in C.

Direct Known Subclasses

MD5, RMD160, SHA1

Instance Method Summary collapse

Methods inherited from Class

base64digest, bubblebabble, digest, file, hexdigest, #initialize

Methods included from Instance

#==, #base64digest, #base64digest!, #bubblebabble, #digest, #digest!, #file, #hexdigest, #hexdigest!, #inspect, #length, #new, #size, #to_s

Constructor Details

This class inherits a constructor from Digest::Class

Instance Method Details

#<<(str) ⇒ Object

:nodoc:



615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
# File 'digest.c', line 615

static VALUE
rb_digest_base_update(VALUE self, VALUE str)
{
    rb_digest_metadata_t *algo;
    void *pctx;

    algo = get_digest_base_metadata(rb_obj_class(self));

    TypedData_Get_Struct(self, void, &digest_type, pctx);

    StringValue(str);
    algo->update_func(pctx, (unsigned char *)RSTRING_PTR(str), RSTRING_LEN(str));

    return self;
}

#block_lengthObject

:nodoc:



664
665
666
667
668
669
670
671
672
# File 'digest.c', line 664

static VALUE
rb_digest_base_block_length(VALUE self)
{
    rb_digest_metadata_t *algo;

    algo = get_digest_base_metadata(rb_obj_class(self));

    return INT2NUM(algo->block_len);
}

#digest_lengthObject

:nodoc:



653
654
655
656
657
658
659
660
661
# File 'digest.c', line 653

static VALUE
rb_digest_base_digest_length(VALUE self)
{
    rb_digest_metadata_t *algo;

    algo = get_digest_base_metadata(rb_obj_class(self));

    return INT2NUM(algo->digest_len);
}

#initialize_copy(obj) ⇒ Object

:nodoc:



577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
# File 'digest.c', line 577

static VALUE
rb_digest_base_copy(VALUE copy, VALUE obj)
{
    rb_digest_metadata_t *algo;
    void *pctx1, *pctx2;

    if (copy == obj) return copy;

    rb_check_frozen(copy);

    algo = get_digest_base_metadata(rb_obj_class(copy));
    if (algo != get_digest_base_metadata(rb_obj_class(obj)))
	rb_raise(rb_eTypeError, "different algorithms");

    TypedData_Get_Struct(obj, void, &digest_type, pctx1);
    TypedData_Get_Struct(copy, void, &digest_type, pctx2);
    memcpy(pctx2, pctx1, algo->ctx_size);

    return copy;
}

#resetObject

:nodoc:



599
600
601
602
603
604
605
606
607
608
609
610
611
612
# File 'digest.c', line 599

static VALUE
rb_digest_base_reset(VALUE self)
{
    rb_digest_metadata_t *algo;
    void *pctx;

    algo = get_digest_base_metadata(rb_obj_class(self));

    TypedData_Get_Struct(self, void, &digest_type, pctx);

    algo_init(algo, pctx);

    return self;
}

#update(str) ⇒ Object

:nodoc:



615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
# File 'digest.c', line 615

static VALUE
rb_digest_base_update(VALUE self, VALUE str)
{
    rb_digest_metadata_t *algo;
    void *pctx;

    algo = get_digest_base_metadata(rb_obj_class(self));

    TypedData_Get_Struct(self, void, &digest_type, pctx);

    StringValue(str);
    algo->update_func(pctx, (unsigned char *)RSTRING_PTR(str), RSTRING_LEN(str));

    return self;
}