| 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 <cbarratt@users.sourceforge.net> | ||||||||||
| 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 <http://www.gnu.org/licenses/>. | ||||||||||
| 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 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 43 | 5 | ▶ | use vars qw($VERSION @ISA @EXPORT); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 44 | |||||||||||
| 45 | 5 | require Exporter; | |||||||||
| 46 | 5 | require DynaLoader; | |||||||||
| 47 | 5 | require AutoLoader; | |||||||||
| 48 | |||||||||||
| 49 | 5 | @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 | 5 | @EXPORT = qw( | |||||||||
| 54 | |||||||||||
| 55 | ); | ||||||||||
| 56 | 5 | $VERSION = '0.76'; | |||||||||
| 57 | |||||||||||
| 58 | 5 | bootstrap File::RsyncP::Digest $VERSION; | |||||||||
| 59 | |||||||||||
| 60 | # Preloaded methods go here. | ||||||||||
| 61 | |||||||||||
| 62 | sub addfile | ||||||||||
| 63 | 6 | ▶ | { | ||||||||
|
Subroutine
addfile: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||
| 64 | 5 | ▶ | no strict 'refs'; # Countermand any strct refs in force so that we | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 65 | # can still handle file-handle names. | ||||||||||
| 66 | |||||||||||
| 67 | 6 | my ($self, $handle) = @_; | |||||||||
| 68 | 6 | my ($package, $file, $line) = caller; | |||||||||
| 69 | 6 | my ($data) = ''; | |||||||||
| 70 | |||||||||||
| 71 | 6 | ▶ | if (!ref($handle)) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | 5 | ▶ | $handle = $package . '::' . $handle unless ($handle =~ /(\:\:|\')/); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 6 | ▶ | while (read($handle, $data, 1024)) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | { | ||||||||||
| 82 | 36 | $self->add($data); | |||||||||
| 83 | } | ||||||||||
| 84 | 6 | return $self; | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | sub hexdigest | ||||||||||
| 88 | 9 | ▶ | { | ||||||||
|
Subroutine
hexdigest: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 89 | 9 | my ($self) = shift; | |||||||||
| 90 | |||||||||||
| 91 | 9 | unpack("H*", ($self->digest())); | |||||||||
| 92 | } | ||||||||||
| 93 | |||||||||||
| 94 | sub hash | ||||||||||
| 95 | 2 | ▶ | { | ||||||||
|
Subroutine
hash: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 96 | 2 | my ($self, $data) = @_; | |||||||||
| 97 | |||||||||||
| 98 | 2 | ▶ | if (ref($self)) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 99 | { | ||||||||||
| 100 | # This is an instance method call so reset the current context | ||||||||||
| 101 | |||||||||||
| 102 | 1 | $self->reset(); | |||||||||
| 103 | } | ||||||||||
| 104 | else | ||||||||||
| 105 | { | ||||||||||
| 106 | # This is a static method invocation, create a temporary MD4 context | ||||||||||
| 107 | |||||||||||
| 108 | 1 | $self = new File::RsyncP::Digest; | |||||||||
| 109 | } | ||||||||||
| 110 | |||||||||||
| 111 | # Now do the hash | ||||||||||
| 112 | |||||||||||
| 113 | 2 | $self->add($data); | |||||||||
| 114 | 2 | $self->digest(); | |||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | sub hexhash | ||||||||||
| 118 | 2 | ▶ | { | ||||||||
|
Subroutine
hexhash: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 119 | 2 | my ($self, $data) = @_; | |||||||||
| 120 | |||||||||||
| 121 | 2 | unpack("H*", ($self->hash($data))); | |||||||||
| 122 | } | ||||||||||
| 123 | |||||||||||
| 124 | # Autoload methods go after =cut, and are processed by the autosplit program. | ||||||||||
| 125 | |||||||||||
| 126 | 5 | 1; | |||||||||
| 127 | __END__ | ||||||||||