about summary refs log tree commit homepage
path: root/lib/PublicInbox/ContentId.pm
diff options
context:
space:
mode:
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-02 18:27:54 +0000
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>2018-03-02 18:28:54 +0000
commit9e9863aa5fb74358cd2b5960e4d8d16f1ee9fece (patch)
treedc897d6ddb7541621fe168fa14726064344c947f /lib/PublicInbox/ContentId.pm
parentaf2e250ca2704d06afe0a7ed862dcfca7f740de7 (diff)
downloadpublic-inbox-9e9863aa5fb74358cd2b5960e4d8d16f1ee9fece.tar.gz
We merely use this for internal comparisons and do not store
this in Xapian.  So using a shorter, non-human readable digest
is enough.  Furthermore, introduce "content_digest" which
returns the Digest::SHA object for extra changes.
Diffstat (limited to 'lib/PublicInbox/ContentId.pm')
-rw-r--r--lib/PublicInbox/ContentId.pm15
1 files changed, 9 insertions, 6 deletions
diff --git a/lib/PublicInbox/ContentId.pm b/lib/PublicInbox/ContentId.pm
index d1a009e7..8347de2d 100644
--- a/lib/PublicInbox/ContentId.pm
+++ b/lib/PublicInbox/ContentId.pm
@@ -5,7 +5,7 @@ package PublicInbox::ContentId;
 use strict;
 use warnings;
 use base qw/Exporter/;
-our @EXPORT_OK = qw/content_id/;
+our @EXPORT_OK = qw/content_id content_digest/;
 use PublicInbox::MID qw(mids references);
 
 # not sure if less-widely supported hash families are worth bothering with
@@ -14,10 +14,9 @@ use Digest::SHA;
 # Content-* headers are often no-ops, so maybe we don't need them
 my @ID_HEADERS = qw(Subject From Date To Cc);
 
-sub content_id ($;$) {
-        my ($mime, $alg) = @_;
-        $alg ||= 256;
-        my $dig = Digest::SHA->new($alg);
+sub content_digest ($) {
+        my ($mime) = @_;
+        my $dig = Digest::SHA->new(256);
         my $hdr = $mime->header_obj;
 
         # References: and In-Reply-To: get used interchangeably
@@ -37,7 +36,11 @@ sub content_id ($;$) {
                 $dig->add("$h: $_") foreach @v;
         }
         $dig->add($mime->body_raw);
-        'SHA-' . $dig->algorithm . ':' . $dig->hexdigest;
+        $dig;
+}
+
+sub content_id ($) {
+        content_digest($_[0])->digest;
 }
 
 1;