dslinux/user/perl/lib/Digest Changes base.pm file.pm
cayenne
dslinux_cayenne at user.in-berlin.de
Tue Dec 5 05:27:07 CET 2006
Update of /cvsroot/dslinux/dslinux/user/perl/lib/Digest
In directory antilope:/tmp/cvs-serv7729/lib/Digest
Added Files:
Changes base.pm file.pm
Log Message:
Adding fresh perl source to HEAD to branch from
--- NEW FILE: base.pm ---
package Digest::base;
use strict;
use vars qw($VERSION);
$VERSION = "1.00";
# subclass is supposed to implement at least these
sub new;
sub clone;
sub add;
sub digest;
sub reset {
my $self = shift;
$self->new(@_); # ugly
}
sub addfile {
my ($self, $handle) = @_;
my $n;
my $buf = "";
while (($n = read($handle, $buf, 4*1024))) {
$self->add($buf);
}
unless (defined $n) {
require Carp;
Carp::croak("Read failed: $!");
}
$self;
}
sub add_bits {
my $self = shift;
my $bits;
my $nbits;
if (@_ == 1) {
my $arg = shift;
$bits = pack("B*", $arg);
$nbits = length($arg);
}
else {
($bits, $nbits) = @_;
}
if (($nbits % 8) != 0) {
require Carp;
Carp::croak("Number of bits must be multiple of 8 for this algorithm");
}
return $self->add(substr($bits, 0, $nbits/8));
}
sub hexdigest {
my $self = shift;
return unpack("H*", $self->digest(@_));
}
sub b64digest {
my $self = shift;
require MIME::Base64;
my $b64 = MIME::Base64::encode($self->digest(@_), "");
$b64 =~ s/=+$//;
return $b64;
}
1;
__END__
=head1 NAME
Digest::base - Digest base class
=head1 SYNOPSIS
package Digest::Foo;
use base 'Digest::base';
=head1 DESCRIPTION
The C<Digest::base> class provide implementations of the methods
C<addfile> and C<add_bits> in terms of C<add>, and of the methods
C<hexdigest> and C<b64digest> in terms of C<digest>.
Digest implementations might want to inherit from this class to get
this implementations of the alternative I<add> and I<digest> methods.
A minimal subclass needs to implement the following methods by itself:
new
clone
add
digest
The arguments and expected behaviour of these methods are described in
L<Digest>.
=head1 SEE ALSO
L<Digest>
--- NEW FILE: file.pm ---
package Digest::file;
use strict;
use Exporter ();
use Carp qw(croak);
use Digest ();
use vars qw($VERSION @ISA @EXPORT_OK);
$VERSION = "1.00";
@ISA = qw(Exporter);
@EXPORT_OK = qw(digest_file_ctx digest_file digest_file_hex digest_file_base64);
sub digest_file_ctx {
my $file = shift;
croak("No digest algorithm specified") unless @_;
local *F;
open(F, $file) || croak("Can't open '$file': $!");
binmode(F);
my $ctx = Digest->new(@_);
$ctx->addfile(*F);
close(F);
return $ctx;
}
sub digest_file {
digest_file_ctx(@_)->digest;
}
sub digest_file_hex {
digest_file_ctx(@_)->hexdigest;
}
sub digest_file_base64 {
digest_file_ctx(@_)->b64digest;
}
1;
__END__
=head1 NAME
Digest::file - Calculate digests of files
=head1 SYNOPSIS
# Poor mans "md5sum" command
use Digest::file qw(digest_file_hex);
for (@ARGV) {
print digest_file_hex($_, "MD5"), " $_\n";
}
=head1 DESCRIPTION
This module provide 3 convenience functions to calculate the digest
of files. The following functions are provided:
=over
=item digest_file( $file, $algorithm, [$arg,...] )
This function will calculate and return the binary digest of the bytes
of the given file. The function will croak if it fails to open or
read the file.
The $algorithm is a string like "MD2", "MD5", "SHA-1", "SHA-512".
Additional arguments are passed to the constructor for the
implementation of the given algorithm.
=item digest_file_hex( $file, $algorithm, [$arg,...] )
Same as digest_file(), but return the digest in hex form.
=item digest_file_base64( $file, $algorithm, [$arg,...] )
Same as digest_file(), but return the digest as a base64 encoded
string.
=back
=head1 SEE ALSO
L<Digest>
--- NEW FILE: Changes ---
2005-11-26 Gisle Aas <gisle at ActiveState.com>
Release 1.14
Documentation tweaks.
2005-10-18 Gisle Aas <gisle at ActiveState.com>
Release 1.13
Fixed documentation typo.
2005-09-29 Gisle Aas <gisle at ActiveState.com>
Release 1.12
Fix documentation typo. Patch by <steve at fisharerojo.org>.
2005-09-11 Gisle Aas <gisle at ActiveState.com>
Release 1.11
Make Digest->new("SHA-224") work. Patch by Mark Shelor
<shelor at cpan.org>.
2004-11-08 Gisle Aas <gisle at ActiveState.com>
Release 1.10
Added Digest::file module which provide convenience functions
that calculate digests of files.
2004-11-05 Gisle Aas <gisle at ActiveState.com>
Release 1.09
Fix trivial documentation typo.
2004-04-29 Gisle Aas <gisle at ActiveState.com>
Release 1.08
Make Digest->new("CRC-16"), Digest->new("CRC-32") and
Digest->new("CRC-CCITT") work.
Patch by Oliver Maul <oliver at maul.tv>.
2004-04-25 Gisle Aas <gisle at ActiveState.com>
Release 1.07
Updated benchmark.
2004-04-01 Gisle Aas <gisle at ActiveState.com>
Release 1.06
Added MIME::Base64 dependency.
Minor doc tweak.
2003-12-01 Gisle Aas <gisle at ActiveState.com>
Release 1.05
Drop Digest::MD5 dependency. Avoids circular dependency
now that Digest::MD5 depend on this package to inherit
Digest::base.
Included a section about digest speed with benchmark
results for some implementations of this API.
2003-11-29 Gisle Aas <gisle at ActiveState.com>
Release 1.04
Doc tweaks to unconfuse search.cpan.org.
2003-11-28 Gisle Aas <gisle at ActiveState.com>
Release 1.03
Added add_bits() method as requested by the
Digest::SHA author Mark Shelor.
Added Digest::base class that Digest implementations
can use to get default implementations of addfile(),
add_bits(), hexdigest() and b64digest().
Digest->new("SHA-256") and similar should work now
given that you have either Digest::SHA or Digest::SHA2
installed.
2003-01-18 Gisle Aas <gisle at ActiveState.com>
Release 1.02
Sync up with version bundled with perl-5.8.
Patch by Jarkko Hietaniemi <jhi at iki.fi>.
Override INSTALLDIRS for 5.8 as suggested by
Guido Ostkamp <Guido.Ostkamp at t-online.de>.
2003-01-04 Gisle Aas <gisle at ActiveState.com>
Release 1.01
Document the clone() method.
2001-03-13 Gisle Aas <gisle at ActiveState.com>
Release 1.00
Broken out of the Digest-MD5-2.12 distribution and made into
a separate dist.
More information about the dslinux-commit
mailing list