diff options
author | Siep Kroonenberg <siepo@cybercomm.nl> | 2022-03-14 10:08:50 +0000 |
---|---|---|
committer | Siep Kroonenberg <siepo@cybercomm.nl> | 2022-03-14 10:08:50 +0000 |
commit | 49b9d8ffc05bf0c271287eb1390cabad28c6a47a (patch) | |
tree | e2e1779b1d4795d6b2c3bf92a4e2e4154d82124b /Master/tlpkg/tlperl/lib/Digest.pm | |
parent | f03a75ebd3b935ecde4dde32687fbe86161c30ed (diff) |
New tlperl 5.34
git-svn-id: svn://tug.org/texlive/trunk@62701 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/tlperl/lib/Digest.pm')
-rw-r--r-- | Master/tlpkg/tlperl/lib/Digest.pm | 77 |
1 files changed, 44 insertions, 33 deletions
diff --git a/Master/tlpkg/tlperl/lib/Digest.pm b/Master/tlpkg/tlperl/lib/Digest.pm index 16dae9d16e5..97f55d048a1 100644 --- a/Master/tlpkg/tlperl/lib/Digest.pm +++ b/Master/tlpkg/tlperl/lib/Digest.pm @@ -1,41 +1,44 @@ package Digest; use strict; -use vars qw($VERSION %MMAP $AUTOLOAD); - -$VERSION = "1.17_01"; - -%MMAP = ( - "SHA-1" => [["Digest::SHA", 1], "Digest::SHA1", ["Digest::SHA2", 1]], - "SHA-224" => [["Digest::SHA", 224]], - "SHA-256" => [["Digest::SHA", 256], ["Digest::SHA2", 256]], - "SHA-384" => [["Digest::SHA", 384], ["Digest::SHA2", 384]], - "SHA-512" => [["Digest::SHA", 512], ["Digest::SHA2", 512]], - "HMAC-MD5" => "Digest::HMAC_MD5", - "HMAC-SHA-1" => "Digest::HMAC_SHA1", - "CRC-16" => [["Digest::CRC", type => "crc16"]], - "CRC-32" => [["Digest::CRC", type => "crc32"]], - "CRC-CCITT" => [["Digest::CRC", type => "crcccitt"]], - "RIPEMD-160" => "Crypt::RIPEMD160", +use warnings; + +our $VERSION = "1.19"; + +our %MMAP = ( + "SHA-1" => [ [ "Digest::SHA", 1 ], "Digest::SHA1", [ "Digest::SHA2", 1 ] ], + "SHA-224" => [ [ "Digest::SHA", 224 ] ], + "SHA-256" => [ [ "Digest::SHA", 256 ], [ "Digest::SHA2", 256 ] ], + "SHA-384" => [ [ "Digest::SHA", 384 ], [ "Digest::SHA2", 384 ] ], + "SHA-512" => [ [ "Digest::SHA", 512 ], [ "Digest::SHA2", 512 ] ], + "SHA3-224" => [ [ "Digest::SHA3", 224 ] ], + "SHA3-256" => [ [ "Digest::SHA3", 256 ] ], + "SHA3-384" => [ [ "Digest::SHA3", 384 ] ], + "SHA3-512" => [ [ "Digest::SHA3", 512 ] ], + "HMAC-MD5" => "Digest::HMAC_MD5", + "HMAC-SHA-1" => "Digest::HMAC_SHA1", + "CRC-16" => [ [ "Digest::CRC", type => "crc16" ] ], + "CRC-32" => [ [ "Digest::CRC", type => "crc32" ] ], + "CRC-CCITT" => [ [ "Digest::CRC", type => "crcccitt" ] ], + "RIPEMD-160" => "Crypt::RIPEMD160", ); -sub new -{ - shift; # class ignored +sub new { + shift; # class ignored my $algorithm = shift; - my $impl = $MMAP{$algorithm} || do { + my $impl = $MMAP{$algorithm} || do { $algorithm =~ s/\W+//g; "Digest::$algorithm"; }; $impl = [$impl] unless ref($impl); - local $@; # don't clobber it for our caller + local $@; # don't clobber it for our caller my $err; - for (@$impl) { + for (@$impl) { my $class = $_; my @args; - ($class, @args) = @$class if ref($class); + ( $class, @args ) = @$class if ref($class); no strict 'refs'; - unless (exists ${"$class\::"}{"VERSION"}) { + unless ( exists ${"$class\::"}{"VERSION"} ) { my $pm_file = $class . ".pm"; $pm_file =~ s{::}{/}g; eval { @@ -48,16 +51,17 @@ sub new next; } } - return $class->new(@args, @_); + return $class->new( @args, @_ ); } die $err; } -sub AUTOLOAD -{ - my $class = shift; - my $algorithm = substr($AUTOLOAD, rindex($AUTOLOAD, '::')+2); - $class->new($algorithm, @_); +our $AUTOLOAD; + +sub AUTOLOAD { + my $class = shift; + my $algorithm = substr( $AUTOLOAD, rindex( $AUTOLOAD, '::' ) + 2 ); + $class->new( $algorithm, @_ ); } 1; @@ -161,6 +165,9 @@ algorithm names which contains letters which are not legal perl identifiers, e.g. "SHA-1". If no implementation for the given algorithm can be found, then an exception is raised. +To know what arguments (if any) the constructor takes (the C<$args,...> above) +consult the docs for the specific digest implementation. + If new() is called as an instance method (i.e. $ctx->new) it will just reset the state the object to the state of a newly created object. No new object is created in this case, and the return value is the @@ -216,9 +223,8 @@ In most cases you want to make sure that the $io_handle is in =item $ctx->add_bits( $bitstring ) The add_bits() method is an alternative to add() that allow partial -bytes to be appended to the message. Most users should just ignore -this method as partial bytes is very unlikely to be of any practical -use. +bytes to be appended to the message. Most users can just ignore +this method since typical applications involve only whole-byte data. The two argument form of add_bits() will add the first $nbits bits from $data. For the last potentially partial byte only the high order @@ -258,6 +264,11 @@ Same as $ctx->digest, but will return the digest in hexadecimal form. =item $ctx->b64digest Same as $ctx->digest, but will return the digest as a base64 encoded +string without padding. + +=item $ctx->base64_padded_digest + +Same as $ctx->digest, but will return the digest as a base64 encoded string. =back |