source: trunk/essentials/dev-lang/perl/lib/Digest.pm

Last change on this file was 3181, checked in by bird, 19 years ago

perl 5.8.8

File size: 9.0 KB
Line 
1package Digest;
2
3use strict;
4use vars qw($VERSION %MMAP $AUTOLOAD);
5
6$VERSION = "1.14";
7
8%MMAP = (
9 "SHA-1" => ["Digest::SHA1", ["Digest::SHA", 1], ["Digest::SHA2", 1]],
10 "SHA-224" => [["Digest::SHA", 224]],
11 "SHA-256" => [["Digest::SHA", 256], ["Digest::SHA2", 256]],
12 "SHA-384" => [["Digest::SHA", 384], ["Digest::SHA2", 384]],
13 "SHA-512" => [["Digest::SHA", 512], ["Digest::SHA2", 512]],
14 "HMAC-MD5" => "Digest::HMAC_MD5",
15 "HMAC-SHA-1" => "Digest::HMAC_SHA1",
16 "CRC-16" => [["Digest::CRC", type => "crc16"]],
17 "CRC-32" => [["Digest::CRC", type => "crc32"]],
18 "CRC-CCITT" => [["Digest::CRC", type => "crcccitt"]],
19);
20
21sub new
22{
23 shift; # class ignored
24 my $algorithm = shift;
25 my $impl = $MMAP{$algorithm} || do {
26 $algorithm =~ s/\W+//;
27 "Digest::$algorithm";
28 };
29 $impl = [$impl] unless ref($impl);
30 my $err;
31 for (@$impl) {
32 my $class = $_;
33 my @args;
34 ($class, @args) = @$class if ref($class);
35 no strict 'refs';
36 unless (exists ${"$class\::"}{"VERSION"}) {
37 eval "require $class";
38 if ($@) {
39 $err ||= $@;
40 next;
41 }
42 }
43 return $class->new(@args, @_);
44 }
45 die $err;
46}
47
48sub AUTOLOAD
49{
50 my $class = shift;
51 my $algorithm = substr($AUTOLOAD, rindex($AUTOLOAD, '::')+2);
52 $class->new($algorithm, @_);
53}
54
551;
56