summaryrefslogtreecommitdiff
path: root/lib/Digest
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2003-11-29 16:45:19 +0000
committerNicholas Clark <nick@ccl4.org>2003-11-29 16:45:19 +0000
commitb12d758ccb90fef7a772525595989e740b018ed3 (patch)
tree63edd60e518604380d2a404a64e0464ec2a63076 /lib/Digest
parent2e59c212d7fc05bbdc88de96b76e8edb7b6a2b1d (diff)
downloadperl-b12d758ccb90fef7a772525595989e740b018ed3.tar.gz
Update Digest to 1.03
p4raw-id: //depot/perl@21807
Diffstat (limited to 'lib/Digest')
-rw-r--r--lib/Digest/t/base.t76
-rw-r--r--lib/Digest/t/digest.t23
2 files changed, 99 insertions, 0 deletions
diff --git a/lib/Digest/t/base.t b/lib/Digest/t/base.t
new file mode 100644
index 0000000000..c398346cac
--- /dev/null
+++ b/lib/Digest/t/base.t
@@ -0,0 +1,76 @@
+#!perl -w
+
+use Test qw(plan ok);
+plan tests => 12;
+
+{
+ package LenDigest;
+ require Digest::base;
+ use vars qw(@ISA);
+ @ISA = qw(Digest::base);
+
+ sub new {
+ my $class = shift;
+ my $str = "";
+ bless \$str, $class;
+ }
+
+ sub add {
+ my $self = shift;
+ $$self .= join("", @_);
+ return $self;
+ }
+
+ sub digest {
+ my $self = shift;
+ my $len = length($$self);
+ my $first = ($len > 0) ? substr($$self, 0, 1) : "X";
+ $$self = "";
+ return sprintf "$first%04d", $len;
+ }
+}
+
+my $ctx = LenDigest->new;
+ok($ctx->digest, "X0000");
+ok($ctx->hexdigest, "5830303030");
+ok($ctx->b64digest, "WDAwMDA");
+
+$ctx->add("foo");
+ok($ctx->digest, "f0003");
+
+$ctx->add("foo");
+ok($ctx->hexdigest, "6630303033");
+
+$ctx->add("foo");
+ok($ctx->b64digest, "ZjAwMDM");
+
+open(F, ">xxtest$$") || die;
+binmode(F);
+print F "abc" x 100, "\n";
+close(F) || die;
+
+open(F, "xxtest$$") || die;
+$ctx->addfile(*F);
+close(F);
+unlink("xxtest$$") || warn;
+
+ok($ctx->digest, "a0301");
+
+eval {
+ $ctx->add_bits("1010");
+};
+ok($@ =~ /^Number of bits must be multiple of 8/);
+
+$ctx->add_bits("01010101");
+ok($ctx->digest, "U0001");
+
+eval {
+ $ctx->add_bits("abc", 12);
+};
+ok($@ =~ /^Number of bits must be multiple of 8/);
+
+$ctx->add_bits("abc", 16);
+ok($ctx->digest, "a0002");
+
+$ctx->add_bits("abc", 32);
+ok($ctx->digest, "a0003");
diff --git a/lib/Digest/t/digest.t b/lib/Digest/t/digest.t
new file mode 100644
index 0000000000..fbc2dac805
--- /dev/null
+++ b/lib/Digest/t/digest.t
@@ -0,0 +1,23 @@
+print "1..3\n";
+
+use Digest;
+
+my $hexdigest = "900150983cd24fb0d6963f7d28e17f72"; # ASCII
+
+if (ord('A') == 193) { # EBCDIC
+ $hexdigest = "fe4ea0d98f9cd8d1d27f102a93cb0bb0"; # IBM-1047
+}
+
+print "not " unless Digest->MD5->add("abc")->hexdigest eq $hexdigest;
+print "ok 1\n";
+
+print "not " unless Digest->MD5->add("abc")->hexdigest eq $hexdigest;
+print "ok 2\n";
+
+eval {
+ # Not yet EBCDICified.
+ print "not " unless Digest->new("HMAC-MD5" => "Jefe")->add("what do ya want for nothing?")->hexdigest eq "750c783e6ab0b503eaa86e310a5db738";
+ print "ok 3\n";
+};
+print "ok 3\n" if $@ && $@ =~ /^Can't locate/;
+