Dicop::Hash - manage hashes over files


Dicop-Base documentation  | view source Contained in the Dicop-Base distribution.

Index


NAME

Top

Dicop::Hash -- manage hashes over files

SYNOPSIS

Top

	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

Top

perl5.005, Exporter

EXPORTS

Top

Exports nothing per default.

DESCRIPTION

Top

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

METHODS

Top

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

Top

AUTHOR

Top

(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.


Dicop-Base documentation  | view source Contained in the Dicop-Base distribution.