Upgrade to Perl 5.8.8
[msysgit/kusma.git] / lib / perl5 / 5.8.8 / Digest / base.pm
blobcb336c2cf61520b7db1f9e592600abe4be4034d7
1 package Digest::base;
3 use strict;
4 use vars qw($VERSION);
5 $VERSION = "1.00";
7 # subclass is supposed to implement at least these
8 sub new;
9 sub clone;
10 sub add;
11 sub digest;
13 sub reset {
14 my $self = shift;
15 $self->new(@_); # ugly
18 sub addfile {
19 my ($self, $handle) = @_;
21 my $n;
22 my $buf = "";
24 while (($n = read($handle, $buf, 4*1024))) {
25 $self->add($buf);
27 unless (defined $n) {
28 require Carp;
29 Carp::croak("Read failed: $!");
32 $self;
35 sub add_bits {
36 my $self = shift;
37 my $bits;
38 my $nbits;
39 if (@_ == 1) {
40 my $arg = shift;
41 $bits = pack("B*", $arg);
42 $nbits = length($arg);
44 else {
45 ($bits, $nbits) = @_;
47 if (($nbits % 8) != 0) {
48 require Carp;
49 Carp::croak("Number of bits must be multiple of 8 for this algorithm");
51 return $self->add(substr($bits, 0, $nbits/8));
54 sub hexdigest {
55 my $self = shift;
56 return unpack("H*", $self->digest(@_));
59 sub b64digest {
60 my $self = shift;
61 require MIME::Base64;
62 my $b64 = MIME::Base64::encode($self->digest(@_), "");
63 $b64 =~ s/=+$//;
64 return $b64;
69 __END__
71 =head1 NAME
73 Digest::base - Digest base class
75 =head1 SYNOPSIS
77 package Digest::Foo;
78 use base 'Digest::base';
80 =head1 DESCRIPTION
82 The C<Digest::base> class provide implementations of the methods
83 C<addfile> and C<add_bits> in terms of C<add>, and of the methods
84 C<hexdigest> and C<b64digest> in terms of C<digest>.
86 Digest implementations might want to inherit from this class to get
87 this implementations of the alternative I<add> and I<digest> methods.
88 A minimal subclass needs to implement the following methods by itself:
90 new
91 clone
92 add
93 digest
95 The arguments and expected behaviour of these methods are described in
96 L<Digest>.
98 =head1 SEE ALSO
100 L<Digest>