| 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 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 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 44 | 1 | ▶ | use vars qw($VERSION @ISA @EXPORT); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 45 | |||||||||||
| 46 | 1 | require Exporter; | |||||||||
| 47 | 1 | require DynaLoader; | |||||||||
| 48 | 1 | require AutoLoader; | |||||||||
| 49 | |||||||||||
| 50 | 1 | @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 | 1 | @EXPORT = qw( | |||||||||
| 55 | |||||||||||
| 56 | ); | ||||||||||
| 57 | 1 | $VERSION = '0.72'; | |||||||||
| 58 | |||||||||||
| 59 | 1 | bootstrap File::RsyncP::Digest $VERSION; | |||||||||
| 60 | |||||||||||
| 61 | # Preloaded methods go here. | ||||||||||
| 62 | |||||||||||
| 63 | sub addfile | ||||||||||
| 64 | { | ||||||||||
| 65 | 1 | ▶ | no strict 'refs'; # Countermand any strct refs in force so that we | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 66 | # can still handle file-handle names. | ||||||||||
| 67 | |||||||||||
| 68 | 0 | ▶ | my ($self, $handle) = @_; | ||||||||
|
Subroutine
addfile: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 69 | 0 | my ($package, $file, $line) = caller; | |||||||||
| 70 | 0 | my ($data) = ''; | |||||||||
| 71 | |||||||||||
| 72 | 0 | ▶ | if (!ref($handle)) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | $handle = $package . '::' . $handle unless ($handle =~ /(\:\:|\')/); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 0 | ▶ | while (read($handle, $data, 1024)) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | { | ||||||||||
| 83 | 0 | $self->add($data); | |||||||||
| 84 | } | ||||||||||
| 85 | 0 | return $self; | |||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | sub hexdigest | ||||||||||
| 89 | { | ||||||||||
| 90 | 0 | ▶ | my ($self) = shift; | ||||||||
|
Subroutine
hexdigest: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 91 | |||||||||||
| 92 | 0 | unpack("H*", ($self->digest())); | |||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | sub hash | ||||||||||
| 96 | { | ||||||||||
| 97 | 0 | ▶ | my ($self, $data) = @_; | ||||||||
|
Subroutine
hash: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 98 | |||||||||||
| 99 | 0 | ▶ | if (ref($self)) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | my ($self, $data) = @_; | ||||||||
|
Subroutine
hexhash: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 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 | 1; | |||||||||
| 128 | __END__ | ||||||||||