File Coverage

blib/lib/File/RsyncP/Digest.pm
Criterion Covered Total %
statement 9 27 33.3
branch 0 6 0.0
condition n/a
subroutine 3 7 42.8
pod 0 4 0.0
total 12 44 27.2


line stmt bran cond sub pod time code
1             #============================================================= -*-perl-*-
2             #
3             # File::RsyncP::Digest package
4             #
5             # DESCRIPTION
6             # File::RsyncP::Digest is a perl module that implements the
7             # various message digests that rsync uses.
8             #
9             # AUTHOR
10             # Craig Barratt
11             #
12             # COPYRIGHT
13             # File::RsyncP is Copyright (C) 2002-2015 Craig Barratt.
14             #
15             # Rsync is Copyright (C) 1996-2001 by Andrew Tridgell, 1996 by Paul
16             # Mackerras, 2001-2002 by Martin Pool, and 2003-2009 by Wayne Davison,
17             # and others.
18             #
19             # This program is free software; you can redistribute it and/or modify
20             # it under the terms of the GNU General Public License as published by
21             # the Free Software Foundation; either version 2 of the License, or
22             # (at your option) any later version.
23             #
24             # This program is distributed in the hope that it will be useful,
25             # but WITHOUT ANY WARRANTY; without even the implied warranty of
26             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27             # GNU General Public License for more details.
28             #
29             # You should have received a copy of the GNU General Public License
30             # along with this program; if not, write to the Free Software
31             # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32             #
33             #========================================================================
34             #
35             # Version 0.72, released 11 Jan 2015.
36             #
37             # See http://perlrsync.sourceforge.net.
38             #
39             #========================================================================
40              
41             package File::RsyncP::Digest;
42              
43 1     1   7 use strict;
  1         2  
  1         35  
44 1     1   4 use vars qw($VERSION @ISA @EXPORT);
  1         1  
  1         104  
45              
46             require Exporter;
47             require DynaLoader;
48             require AutoLoader;
49              
50             @ISA = qw(Exporter AutoLoader DynaLoader);
51             # Items to export into callers namespace by default. Note: do not export
52             # names by default without a very good reason. Use EXPORT_OK instead.
53             # Do not simply export all your public functions/methods/constants.
54             @EXPORT = qw(
55            
56             );
57             $VERSION = '0.72';
58              
59             bootstrap File::RsyncP::Digest $VERSION;
60              
61             # Preloaded methods go here.
62              
63             sub addfile
64             {
65 1     1   5 no strict 'refs'; # Countermand any strct refs in force so that we
  1         1  
  1         204  
66             # can still handle file-handle names.
67              
68 0     0 0   my ($self, $handle) = @_;
69 0           my ($package, $file, $line) = caller;
70 0           my ($data) = '';
71              
72 0 0         if (!ref($handle))
73             {
74             # Old-style passing of filehandle by name. We need to add
75             # the calling package scope qualifier, if there is not one
76             # supplied already.
77              
78 0 0         $handle = $package . '::' . $handle unless ($handle =~ /(\:\:|\')/);
79             }
80              
81 0           while (read($handle, $data, 1024))
82             {
83 0           $self->add($data);
84             }
85 0           return $self;
86             }
87              
88             sub hexdigest
89             {
90 0     0 0   my ($self) = shift;
91              
92 0           unpack("H*", ($self->digest()));
93             }
94              
95             sub hash
96             {
97 0     0 0   my ($self, $data) = @_;
98              
99 0 0         if (ref($self))
100             {
101             # This is an instance method call so reset the current context
102              
103 0           $self->reset();
104             }
105             else
106             {
107             # This is a static method invocation, create a temporary MD4 context
108              
109 0           $self = new File::RsyncP::Digest;
110             }
111              
112             # Now do the hash
113              
114 0           $self->add($data);
115 0           $self->digest();
116             }
117              
118             sub hexhash
119             {
120 0     0 0   my ($self, $data) = @_;
121              
122 0           unpack("H*", ($self->hash($data)));
123             }
124              
125             # Autoload methods go after =cut, and are processed by the autosplit program.
126              
127             1;
128             __END__