
Dicop::Hash -- manage hashes over files

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';

perl5.005, Exporter

Exports nothing per default.

This module manages all the file hashes for the server. It currently uses MD5 as hashing algorithmn.

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 in a file and then hash the file data, store hash along with time stamp.
When the file has changed, recalculate hash. Otherwise do nothing. Called by as_hex() automatically.
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.
Returns a potential error message or the empty string for no error.
$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.


(c) Bundesamt fuer Sicherheit in der Informationstechnik 1998-2008
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.bund.de/ for more information.