Bundesamt für Sicherheit in der Informationstechnik > Dicop-Base-3.05 > Dicop::Hash

Download:
dicop/Dicop-Base-3.05.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
Report a bug
Module Version: 1.06   Source  

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 ^

AUTHOR ^

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