File Coverage

/root/.cpan/build/File-RsyncP-0.76-0/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 3 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, see .
31             #
32             #========================================================================
33             #
34             # Version 0.76, released 14 Sep 2020.
35             #
36             # See http://perlrsync.sourceforge.net.
37             #
38             #========================================================================
39              
40             package File::RsyncP::Digest;
41              
42 1     1   6 use strict;
  1         3  
  1         43  
43 1     1   6 use vars qw($VERSION @ISA @EXPORT);
  1         2  
  1         131  
44              
45             require Exporter;
46             require DynaLoader;
47             require AutoLoader;
48              
49             @ISA = qw(Exporter AutoLoader DynaLoader);
50             # Items to export into callers namespace by default. Note: do not export
51             # names by default without a very good reason. Use EXPORT_OK instead.
52             # Do not simply export all your public functions/methods/constants.
53             @EXPORT = qw(
54            
55             );
56             $VERSION = '0.76';
57              
58             bootstrap File::RsyncP::Digest $VERSION;
59              
60             # Preloaded methods go here.
61              
62             sub addfile
63             {
64 1     1   7 no strict 'refs'; # Countermand any strct refs in force so that we
  1         2  
  1         287  
65             # can still handle file-handle names.
66              
67 0     0 0   my ($self, $handle) = @_;
68 0           my ($package, $file, $line) = caller;
69 0           my ($data) = '';
70              
71 0 0         if (!ref($handle))
72             {
73             # Old-style passing of filehandle by name. We need to add
74             # the calling package scope qualifier, if there is not one
75             # supplied already.
76              
77 0 0         $handle = $package . '::' . $handle unless ($handle =~ /(\:\:|\')/);
78             }
79              
80 0           while (read($handle, $data, 1024))
81             {
82 0           $self->add($data);
83             }
84 0           return $self;
85             }
86              
87             sub hexdigest
88             {
89 0     0 0   my ($self) = shift;
90              
91 0           unpack("H*", ($self->digest()));
92             }
93              
94             sub hash
95             {
96 0     0 0   my ($self, $data) = @_;
97              
98 0 0         if (ref($self))
99             {
100             # This is an instance method call so reset the current context
101              
102 0           $self->reset();
103             }
104             else
105             {
106             # This is a static method invocation, create a temporary MD4 context
107              
108 0           $self = new File::RsyncP::Digest;
109             }
110              
111             # Now do the hash
112              
113 0           $self->add($data);
114 0           $self->digest();
115             }
116              
117             sub hexhash
118             {
119 0     0 0   my ($self, $data) = @_;
120              
121 0           unpack("H*", ($self->hash($data)));
122             }
123              
124             # Autoload methods go after =cut, and are processed by the autosplit program.
125              
126             1;
127             __END__