]> Sergey Matveev's repositories - public-inbox.git/commitdiff
use Net::SSLeay (OpenSSL) for SHA-(1|256) if installed
authorEric Wong <e@80x24.org>
Sun, 29 Jan 2023 10:30:41 +0000 (10:30 +0000)
committerEric Wong <e@80x24.org>
Mon, 30 Jan 2023 06:42:31 +0000 (06:42 +0000)
On my x86-64 machine, OpenSSL SHA-256 is nearly twice as fast as
the Digest::SHA implementation from Perl, most likely due to an
optimized assembly implementation.  SHA-1 is a few percent
faster, too.

25 files changed:
MANIFEST
lib/PublicInbox/ContentDigestDbg.pm
lib/PublicInbox/ContentHash.pm
lib/PublicInbox/Fetch.pm
lib/PublicInbox/Git.pm
lib/PublicInbox/LeiDedupe.pm
lib/PublicInbox/LeiMirror.pm
lib/PublicInbox/LeiSavedSearch.pm
lib/PublicInbox/LeiSucks.pm
lib/PublicInbox/Linkify.pm
lib/PublicInbox/MID.pm
lib/PublicInbox/MdirReader.pm
lib/PublicInbox/NNTP.pm
lib/PublicInbox/SHA.pm [new file with mode: 0644]
lib/PublicInbox/WwwAtomStream.pm
t/clone-coderepo.t
t/httpd-corner.psgi
t/httpd-corner.t
t/ipc.t
t/nntpd.t
t/sha.t [new file with mode: 0644]
t/www_listing.t
xt/git_async_cmp.t
xt/imapd-validate.t
xt/nntpd-validate.t

index c494d6f7a148d4c26c74da241fb25bb5447d93b5..f22f60aa217fa6b95825830a81cf0bfc64e6b47c 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -312,6 +312,7 @@ lib/PublicInbox/Reply.pm
 lib/PublicInbox/RepoAtom.pm
 lib/PublicInbox/RepoSnapshot.pm
 lib/PublicInbox/RepoTree.pm
+lib/PublicInbox/SHA.pm
 lib/PublicInbox/SaPlugin/ListMirror.pm
 lib/PublicInbox/SaPlugin/ListMirror.pod
 lib/PublicInbox/Search.pm
@@ -559,6 +560,7 @@ t/run.perl
 t/search-amsg.eml
 t/search-thr-index.t
 t/search.t
+t/sha.t
 t/shared_kv.t
 t/sigfd.t
 t/solve/0001-simple-mod.patch
index 425e85899a6ccf8542f57a0b9ccaf23f0b7e14fd..899afbbe6f0ed30a1e5ee5c6a62875f0dc9b0389 100644 (file)
@@ -3,9 +3,9 @@
 package PublicInbox::ContentDigestDbg; # cf. PublicInbox::ContentDigest
 use v5.12;
 use Data::Dumper;
-use Digest::SHA;
+use PublicInbox::SHA;
 
-sub new { bless { dig => Digest::SHA->new(256), fh => $_[1] }, __PACKAGE__ }
+sub new { bless { dig => PublicInbox::SHA->new(256), fh => $_[1] }, __PACKAGE__ }
 
 sub add {
        $_[0]->{dig}->add($_[1]);
index 1afbb413a697b99e6ae23b6ef20c1d488526613e..d3ff146aa96e91ef3ada23c29689de0a33f6b2e0 100644 (file)
@@ -15,7 +15,8 @@ use PublicInbox::MID qw(mids references);
 use PublicInbox::MsgIter;
 
 # not sure if less-widely supported hash families are worth bothering with
-use Digest::SHA;
+use PublicInbox::SHA; # faster, but no ->clone
+use Digest::SHA; # we still need this for ->clone
 
 sub digest_addr ($$$) {
        my ($dig, $h, $v) = @_;
@@ -93,15 +94,15 @@ sub content_digest ($;$) {
 }
 
 sub content_hash ($) {
-       content_digest($_[0])->digest;
+       content_digest($_[0], PublicInbox::SHA->new(256))->digest;
 }
 
+# don't clone the result of this
 sub git_sha ($$) {
        my ($n, $eml) = @_;
-       my $dig = Digest::SHA->new($n);
+       my $dig = PublicInbox::SHA->new($n);
        my $bref = ref($eml) eq 'SCALAR' ? $eml : \($eml->as_string);
-       $dig->add('blob '.length($$bref)."\0");
-       $dig->add($$bref);
+       $dig->add('blob '.length($$bref)."\0", $$bref);
        $dig;
 }
 
index 198e2a605a0940b7299aa95d6cee6e117e6e8b48..f93eeebeae29f85c0fd20374f42724f0a0941447 100644 (file)
@@ -92,9 +92,9 @@ sub do_manifest ($$$) {
 
 sub get_fingerprint2 {
        my ($git_dir) = @_;
-       require Digest::SHA;
+       require PublicInbox::SHA;
        my $rd = popen_rd([qw(git show-ref)], undef, { -C => $git_dir });
-       Digest::SHA::sha256(do { local $/; <$rd> });
+       PublicInbox::SHA::sha256(do { local $/; <$rd> });
 }
 
 sub writable_dir ($) {
index 3e2b435c923b57db78848f8d9b88919241e44466..fd7a03823d7b5d2faeaa0cad3b02f525220f2275 100644 (file)
@@ -20,7 +20,7 @@ use PublicInbox::Spawn qw(popen_rd which);
 use PublicInbox::Tmpfile;
 use IO::Poll qw(POLLIN);
 use Carp qw(croak carp);
-use Digest::SHA ();
+use PublicInbox::SHA ();
 use PublicInbox::DS qw(awaitpid);
 our @EXPORT_OK = qw(git_unquote git_quote);
 our $PIPE_BUFSIZ = 65536; # Linux default
@@ -630,7 +630,7 @@ sub cloneurl {
 sub manifest_entry {
        my ($self, $epoch, $default_desc) = @_;
        my $fh = $self->popen('show-ref');
-       my $dig = Digest::SHA->new(1);
+       my $dig = PublicInbox::SHA->new(1);
        while (read($fh, my $buf, 65536)) {
                $dig->add($buf);
        }
index 32f99cd0a30c3eafeed64940c7a0bd21940861ad..22864508b84e180adbadc262159bcb9d120b317c 100644 (file)
@@ -1,10 +1,10 @@
-# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 package PublicInbox::LeiDedupe;
 use strict;
 use v5.10.1;
 use PublicInbox::ContentHash qw(content_hash git_sha);
-use Digest::SHA ();
+use PublicInbox::SHA ();
 
 # n.b. mutt sets most of these headers not sure about Bytes
 our @OID_IGNORE = qw(Status X-Status Content-Length Lines Bytes);
@@ -30,7 +30,7 @@ sub _oidbin ($) { defined($_[0]) ? pack('H*', $_[0]) : undef }
 
 sub smsg_hash ($) {
        my ($smsg) = @_;
-       my $dig = Digest::SHA->new(256);
+       my $dig = PublicInbox::SHA->new(256);
        my $x = join("\0", @$smsg{qw(from to cc ds subject references mid)});
        utf8::encode($x);
        $dig->add($x);
index abf663159855e3818f1e484d6d7ffe7060680102..3101336002378ce2ffe1d848b08daa311621a3cc 100644 (file)
@@ -18,7 +18,7 @@ use PublicInbox::Config;
 use PublicInbox::Inbox;
 use PublicInbox::LeiCurl;
 use PublicInbox::OnDestroy;
-use Digest::SHA qw(sha256_hex sha1_hex);
+use PublicInbox::SHA qw(sha256_hex sha1_hex);
 use POSIX qw(strftime);
 
 our $LIVE; # pid => callback
index ed92bfd11fe1c4b0a80342a702bdece58cde1b46..e53963420edde6f2e36665855c6c57781a822448 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # pretends to be like LeiDedupe and also PublicInbox::Inbox
@@ -13,7 +13,7 @@ use PublicInbox::Config;
 use PublicInbox::Spawn qw(run_die);
 use PublicInbox::ContentHash qw(git_sha);
 use PublicInbox::MID qw(mids_for_index);
-use Digest::SHA qw(sha256_hex);
+use PublicInbox::SHA qw(sha256_hex);
 our $LOCAL_PFX = qr!\A(?:maildir|mh|mbox.+|mmdf|v2):!i; # TODO: put in LeiToMail?
 
 # move this to PublicInbox::Config if other things use it:
index 8e866fc96655a9dd5a6342de43217da0a57e14f5..35d0a8de5dc51c0710d67ddc8ca5613745140756 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # Undocumented hidden command somebody might discover if they're
@@ -7,7 +7,7 @@
 package PublicInbox::LeiSucks;
 use strict;
 use v5.10.1;
-use Digest::SHA ();
+use PublicInbox::SHA qw(sha1_hex);
 use Config;
 use POSIX ();
 use PublicInbox::Config;
@@ -54,13 +54,13 @@ sub lei_sucks {
        } else {
                push @out, "Xapian not available: $@\n";
        }
-       my $dig = Digest::SHA->new(1);
        push @out, "public-inbox blob OIDs of loaded features:\n";
        for my $m (grep(m{^PublicInbox/}, sort keys %INC)) {
                my $f = $INC{$m} // next; # lazy require failed (missing dep)
-               $dig->add('blob '.(-s $f)."\0");
-               $dig->addfile($f);
-               push @out, '  '.$dig->hexdigest.' '.$m."\n";
+               open my $fh, '<', $f or do { warn "open($f): $!"; next };
+               my $hex = sha1_hex('blob '.(-s $fh)."\0".
+                               (do { local $/; <$fh> } // die("read: $!")));
+               push @out, '  '.$hex.' '.$m."\n";
        }
        push @out, <<'EOM';
 Let us know how it sucks!  Please include the above and any other
index 9fc3128fdc2d6842d5f021da71cb7c6423277e31..306a57e77c73d03b99a4ddfd99f98f6119e457db 100644 (file)
@@ -12,7 +12,7 @@
 package PublicInbox::Linkify;
 use strict;
 use v5.10.1;
-use Digest::SHA qw/sha1_hex/;
+use PublicInbox::SHA qw(sha1_hex);
 use PublicInbox::Hval qw(ascii_html mid_href);
 use PublicInbox::MID qw($MID_EXTRACT);
 
index 35b517e09f5d12ff264bcd0bd8afe77f1b96e69d..4819cc256f575f7463ddf030569ef07c8ae6c6a4 100644 (file)
@@ -1,15 +1,15 @@
-# Copyright (C) 2015-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 #
 # Various Message-ID-related functions.
 package PublicInbox::MID;
 use strict;
-use warnings;
-use base qw/Exporter/;
+use v5.10.1; # TODO: check unicode_strings compat for v5.12
+use parent qw(Exporter);
 our @EXPORT_OK = qw(mid_clean id_compress mid2path mid_escape MID_ESC
        mids references mids_for_index mids_in $MID_EXTRACT);
 use URI::Escape qw(uri_escape_utf8);
-use Digest::SHA qw/sha1_hex/;
+use PublicInbox::SHA qw(sha1_hex);
 require PublicInbox::Address;
 use constant {
        ID_MAX => 40, # SHA-1 hex length for HTML id anchors
index dbb74d6d9772f85afb5b9b0fc4b4b07e1b61ac60..db5f4545125f051510ae3b6df2a0db923b014602 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # Maildirs for now, MH eventually
@@ -8,7 +8,7 @@ package PublicInbox::MdirReader;
 use strict;
 use v5.10.1;
 use PublicInbox::InboxWritable qw(eml_from_path);
-use Digest::SHA qw(sha256_hex);
+use PublicInbox::SHA qw(sha256_hex);
 
 # returns Maildir flags from a basename ('' for no flags, undef for invalid)
 sub maildir_basename_flags {
index dd33a232fa6b95d69ef013b5dc7863c1be043a45..7a91e7ebfe49d158080d3a3bbabc0c630b5997da 100644 (file)
@@ -15,7 +15,7 @@ use PublicInbox::MID qw(mid_escape $MID_EXTRACT);
 use PublicInbox::Eml;
 use POSIX qw(strftime);
 use PublicInbox::DS qw(now);
-use Digest::SHA qw(sha1_hex);
+use PublicInbox::SHA qw(sha1_hex);
 use Time::Local qw(timegm timelocal);
 use PublicInbox::GitAsyncCat;
 use PublicInbox::Address;
diff --git a/lib/PublicInbox/SHA.pm b/lib/PublicInbox/SHA.pm
new file mode 100644 (file)
index 0000000..da70bee
--- /dev/null
@@ -0,0 +1,58 @@
+# Copyright (C) all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+# OpenSSL exception added in commit 22711f81f4e79da6b796820e37803a05cae14645
+# (README: add OpenSSL exception, 2015-10-05)
+
+# Replaces most uses of Digest::SHA with OpenSSL via Net::SSLeay if
+# possible.  OpenSSL SHA-256 is nearly twice as fast as Digest::SHA on
+# x86-64, and SHA-1 is a bit faster as well.
+# I don't think we can implement Digest::SHA->clone with what Net::SSLeay
+# gives us...  (maybe EVP_MD_CTX_copy+EVP_MD_CTX_copy_ex need to be added
+# to Net::SSLeay?)
+package PublicInbox::SHA;
+use v5.12;
+require Exporter;
+our @EXPORT_OK = qw(sha1_hex sha256_hex sha256);
+our @ISA;
+
+BEGIN {
+       push @ISA, 'Exporter';
+       unless (eval(<<'EOM')) {
+use Net::SSLeay 1.43;
+my %SHA = (
+       1 => Net::SSLeay::EVP_get_digestbyname('sha1'),
+       256 => Net::SSLeay::EVP_get_digestbyname('sha256'),
+);
+
+sub new {
+       my ($cls, $n) = @_;
+       my $mdctx = Net::SSLeay::EVP_MD_CTX_create();
+       Net::SSLeay::EVP_DigestInit($mdctx, $SHA{$n}) or
+                       die "EVP_DigestInit $n: $!";
+       bless \$mdctx, $cls;
+}
+
+sub add {
+       my $self = shift;
+       Net::SSLeay::EVP_DigestUpdate($$self, $_) for @_;
+       $self;
+}
+
+sub digest { Net::SSLeay::EVP_DigestFinal(${$_[0]}) };
+sub hexdigest { unpack('H*', Net::SSLeay::EVP_DigestFinal(${$_[0]})) }
+sub DESTROY { Net::SSLeay::EVP_MD_CTX_destroy(${$_[0]}) };
+
+sub sha1_hex { unpack('H*', Net::SSLeay::SHA1($_[0])) };
+sub sha256_hex { unpack('H*', Net::SSLeay::SHA256($_[0])) };
+*sha256 = \&Net::SSLeay::SHA256;
+# end of eval
+EOM
+       require Digest::SHA; # stdlib fallback
+       push @ISA, 'Digest::SHA';
+       *sha1_hex = \&Digest::SHA::sha1_hex;
+       *sha256_hex = \&Digest::SHA::sha256_hex;
+       *sha256 = \&Digest::SHA::sha256;
+}
+
+} # /BEGIN
+1;
index 83a8818e5fb1e517a085d3541df14a727882886d..737cc6cbb1f0e1932a32acb360a99095152d5941 100644 (file)
@@ -8,7 +8,7 @@ use strict;
 use parent 'PublicInbox::GzipFilter';
 
 use POSIX qw(strftime);
-use Digest::SHA qw(sha1_hex);
+use PublicInbox::SHA qw(sha1_hex);
 use PublicInbox::Address;
 use PublicInbox::Hval qw(ascii_html mid_href);
 use PublicInbox::MsgTime qw(msg_timestamp);
index 2e628963079cd047e185cc7ade6149afb6c18958..1f33a6d723df66fe571ed2920c8520f2c94715a0 100644 (file)
@@ -6,7 +6,7 @@ use PublicInbox::TestCommon;
 use PublicInbox::Import;
 use File::Temp;
 use File::Path qw(remove_tree);
-use Digest::SHA qw(sha1_hex);
+use PublicInbox::SHA qw(sha1_hex);
 require_mods(qw(json Plack::Builder HTTP::Date HTTP::Status));
 require_git '1.8.5';
 require_ok 'PublicInbox::LeiMirror';
index ea643024db5032ab006514b1927736f76479b5c0..1e96d7b18c1bd0e536559857553e4c8c92cb4522 100644 (file)
@@ -4,7 +4,7 @@
 # Usage: plackup [OPTIONS] /path/to/this/file
 use v5.12;
 use Plack::Builder;
-require Digest::SHA;
+require PublicInbox::SHA;
 if (defined(my $f = $ENV{TEST_OPEN_FIFO})) {
        open my $fh, '>', $f or die "open($f): $!";
        say $fh 'hi';
@@ -29,7 +29,7 @@ my $app = sub {
        my $h = [ 'Content-Type' => 'text/plain' ];
        my $body = [];
        if ($path eq '/sha1') {
-               my $sha1 = Digest::SHA->new('SHA-1');
+               my $sha1 = PublicInbox::SHA->new(1);
                my $buf;
                while (1) {
                        my $r = $in->read($buf, 4096);
index 88820270d4f97100cd3f66f931529ccdee88e446..7600c2b955f27b067d29328d3843832920b56506 100644 (file)
@@ -7,7 +7,7 @@ use strict; use v5.10.1; use PublicInbox::TestCommon;
 use Time::HiRes qw(gettimeofday tv_interval);
 use PublicInbox::Spawn qw(spawn popen_rd);
 require_mods(qw(Plack::Util Plack::Builder HTTP::Date HTTP::Status));
-use Digest::SHA qw(sha1_hex);
+use PublicInbox::SHA qw(sha1_hex);
 use IO::Handle ();
 use IO::Socket::UNIX;
 use Fcntl qw(:seek);
diff --git a/t/ipc.t b/t/ipc.t
index ce89f94bddc0d3daaa541f3b54aaae8545dd2cb0..fd4d559962c877d7125f3d554b41721558bf710a 100644 (file)
--- a/t/ipc.t
+++ b/t/ipc.t
@@ -1,19 +1,19 @@
 #!perl -w
-# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use v5.10.1;
 use Test::More;
 use PublicInbox::TestCommon;
 use Fcntl qw(SEEK_SET);
-use Digest::SHA qw(sha1_hex);
+use PublicInbox::SHA qw(sha1_hex);
 require_mods(qw(Storable||Sereal));
 require_ok 'PublicInbox::IPC';
 my ($tmpdir, $for_destroy) = tmpdir();
 state $once = eval <<'';
 package PublicInbox::IPC;
 use strict;
-use Digest::SHA qw(sha1_hex);
+use PublicInbox::SHA qw(sha1_hex);
 sub test_array { qw(test array) }
 sub test_scalar { 'scalar' }
 sub test_scalarref { \'scalarref' }
index bebf4203c18367f94cd65634d6ae4e05bbe288ac..84a605741c10f218946d60c1593a83819927344a 100644 (file)
--- a/t/nntpd.t
+++ b/t/nntpd.t
@@ -7,7 +7,7 @@ use PublicInbox::Eml;
 use Socket qw(IPPROTO_TCP TCP_NODELAY);
 use Sys::Hostname;
 use POSIX qw(_exit);
-use Digest::SHA;
+use PublicInbox::SHA;
 
 # t/nntpd-v2.t wraps this for v2
 my $version = $ENV{PI_TEST_VERSION} || 1;
@@ -304,7 +304,7 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000
                        my %sums;
                        for (1..$nart) {
                                <$s> =~ /\A220 / or _exit(4);
-                               my $dig = Digest::SHA->new(1);
+                               my $dig = PublicInbox::SHA->new(1);
                                while (my $l = <$s>) {
                                        last if $l eq ".\r\n";
                                        $dig->add($l);
diff --git a/t/sha.t b/t/sha.t
new file mode 100644 (file)
index 0000000..2e2d563
--- /dev/null
+++ b/t/sha.t
@@ -0,0 +1,25 @@
+#!perl -w
+# Copyright (C) all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+use v5.12;
+use PublicInbox::SHA;
+use Test::More;
+
+{
+       my $dig = PublicInbox::SHA->new(1);
+       open my $fh, '<', 'COPYING' or die "open: $!";
+       $dig->add(do { local $/; <$fh> });
+       is($dig->hexdigest, '78e50e186b04c8fe1defaa098f1c192181b3d837',
+               'AGPL-3 matches');
+}
+
+SKIP: {
+       my $n = $ENV{TEST_LEAK_NR} or skip 'TEST_LEAK_NR unset', 1;
+       for (1..$n) {
+               PublicInbox::SHA->new(1)->add('hello')->digest;
+               PublicInbox::SHA->new(1)->add('hello');
+               PublicInbox::SHA->new(1);
+       }
+}
+
+done_testing;
index 6166b94ed508ab5c642c38d204eb5685d47132de..4784c39d4ccb3b9387a001dc86e599188a60e24b 100644 (file)
@@ -5,7 +5,7 @@
 use strict; use v5.10.1; use PublicInbox::TestCommon;
 use PublicInbox::Import;
 use IO::Uncompress::Gunzip qw(gunzip);
-require_mods(qw(json URI::Escape Plack::Builder Digest::SHA HTTP::Tiny));
+require_mods(qw(json URI::Escape Plack::Builder HTTP::Tiny));
 require PublicInbox::WwwListing;
 require PublicInbox::ManifestJsGz;
 use PublicInbox::Config;
index d66b371ff760153d8b2ee5b8b560d734807953b9..9edc1f3752d590dc48c52956f4649105f91ee0df 100644 (file)
@@ -1,10 +1,10 @@
 #!perl -w
-# Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
 use Test::More;
 use Benchmark qw(:all);
-use Digest::SHA;
+use PublicInbox::SHA;
 use PublicInbox::TestCommon;
 my $git_dir = $ENV{GIANT_GIT_DIR};
 plan 'skip_all' => "GIANT_GIT_DIR not defined for $0" unless defined($git_dir);
@@ -20,7 +20,7 @@ my @dig;
 my $nr = $ENV{NR} || 1;
 diag "NR=$nr";
 my $async = timeit($nr, sub {
-       my $dig = Digest::SHA->new(1);
+       my $dig = PublicInbox::SHA->new(1);
        my $cb = sub {
                my ($bref) = @_;
                $dig->add($$bref);
@@ -37,7 +37,7 @@ my $async = timeit($nr, sub {
 });
 
 my $sync = timeit($nr, sub {
-       my $dig = Digest::SHA->new(1);
+       my $dig = PublicInbox::SHA->new(1);
        my $cat = $git->popen(@cat);
        while (<$cat>) {
                my ($oid, undef, undef) = split(/ /);
@@ -51,7 +51,7 @@ my $sync = timeit($nr, sub {
 ok(scalar(@dig) >= 2, 'got some digests');
 my $ref = shift @dig;
 my $exp = $ref->[1];
-isnt($exp, Digest::SHA->new(1)->hexdigest, 'not empty');
+isnt($exp, PublicInbox::SHA->new(1)->hexdigest, 'not empty');
 foreach (@dig) {
        is($_->[1], $exp, "digest matches $_->[0] <=> $ref->[0]");
 }
index 5d27d2a0655eefddb914522a62453311a9c1c467..5d665fa96713bde267c4eda78cd5ed149d3695ce 100644 (file)
@@ -1,11 +1,12 @@
 #!perl -w
-# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 # Expensive test to validate compression and TLS.
 use strict;
 use v5.10.1;
 use Symbol qw(gensym);
 use PublicInbox::DS qw(now);
+use PublicInbox::SHA;
 use POSIX qw(_exit);
 use PublicInbox::TestCommon;
 my $inbox_dir = $ENV{GIANT_INBOX_DIR};
@@ -64,7 +65,7 @@ my $do_get_all = sub {
        my ($desc, $opt) = @_;
        local $SIG{__DIE__} = sub { print STDERR $desc, ': ', @_; _exit(1) };
        my $t0 = now();
-       my $dig = Digest::SHA->new(1);
+       my $dig = PublicInbox::SHA->new(1);
        my $mic = $imap_client->new(%$opt);
        $mic->examine($mailbox) or die "examine: $!";
        my $uid_base = 1;
index 83f024f984ebdf9f56d45c433fd919201ba9ead7..a6f3980eca861356367ffc60d3aeeecf967cc879 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 
 # Integration test to validate compression.
@@ -9,6 +9,7 @@ use Symbol qw(gensym);
 use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC);
 use POSIX qw(_exit);
 use PublicInbox::TestCommon;
+use PublicInbox::SHA;
 my $inbox_dir = $ENV{GIANT_INBOX_DIR};
 plan skip_all => "GIANT_INBOX_DIR not defined for $0" unless $inbox_dir;
 my $mid = $ENV{TEST_MID};
@@ -55,7 +56,7 @@ sub do_get_all {
        my ($methods) = @_;
        my $desc = join(',', @$methods);
        my $t0 = clock_gettime(CLOCK_MONOTONIC);
-       my $dig = Digest::SHA->new(1);
+       my $dig = PublicInbox::SHA->new(1);
        my $digfh = gensym;
        my $tmpfh;
        if ($File::Temp::KEEP_ALL) {