NAME
Dicop::Hash -- manage hashes over files
SYNOPSIS
use Dicop::Hash;
my $hash = Dicop::Hash->new('worker/linux/test');
$hash->update(); # to see whether file has changed
print $hash->as_hex();
my $hash2 = Dicop::Hash->new(\'Some static text');
$hash2->update(); # no-op
print $hash2->as_hex();
print $hash->compare($hash2) ? 'equal' : 'not equal';
REQUIRES
perl5.005, Exporter
EXPORTS
Exports nothing per default.
DESCRIPTION
This module manages all the file hashes for the server. It currently uses MD5 as hashing algorithmn.
METHODS
new
Create a new hash object. The only parameter is a filename to read in and calculate the hash over, or alternatively a ref to a scalar to hash.
read
Read in a file and then hash the file data, store hash along with time stamp.
update
When the file has changed, recalculate hash. Otherwise do nothing. Called by as_hex()
automatically.
as_hex
Return hash value as hexified string. Does update the hash value if neccessary before returning it, so there is no need to call update()
manually.
If an error occured while hashing the file, will return a reference to the error message.
error
Returns a potential error message or the empty string for no error.
compare
$hash->compare($other_hash);
Compares the both hashes and returns true if they are equal. Use this over a plain eq
because this can also work when different hash algorithmns are in use.
BUGS
If you copy over the file a file with the same size and same time stamp, but different contents, then the file will not be re-hashed, thus the change cannot be detected. (use inode time to prevent this when possible?)
AUTHOR
(c) Bundesamt fuer Sicherheit in der Informationstechnik 1998-2006
DiCoP is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.
See http://www.bsi.de/ for more information.