Commit | Line | Data |
3fea05b9 |
1 | package Object::Signature; |
2 | |
3 | use 5.005; |
4 | use strict; |
5 | |
6 | use vars qw{$VERSION}; |
7 | BEGIN { |
8 | $VERSION = '1.05'; |
9 | } |
10 | |
11 | # If prefork is installed, use it |
12 | eval "use prefork 'Storable';"; |
13 | eval "use prefork 'Digest::MD5';"; |
14 | |
15 | sub signature { |
16 | require Storable; |
17 | require Digest::MD5; |
18 | local $Storable::canonical = 1; |
19 | Digest::MD5::md5_hex( |
20 | Storable::nfreeze(shift) |
21 | ); |
22 | } |
23 | |
24 | 1; |
25 | |
26 | __END__ |
27 | |
28 | =pod |
29 | |
30 | =head1 NAME |
31 | |
32 | Signature - Generate cryptographic signatures for objects |
33 | |
34 | =head1 SYNOPSIS |
35 | |
36 | # In your module |
37 | package My::Module |
38 | use base 'Object::Signature'; |
39 | |
40 | # In outside code |
41 | my $Object = My::Module->new; |
42 | print "Object Signature: " . $Object->signature; |
43 | |
44 | =head1 DESCRIPTION |
45 | |
46 | L<Object::Signature> is an abstract base class that you can inherit from in |
47 | order to allow your objects to generate unique cryptographic signatures. |
48 | |
49 | The method used to generate the signature is based on L<Storable> and |
50 | L<Digest::MD5>. The object is fed to C<Storable::nfreeze> to get a string, |
51 | which is then passed to L<Digest::MD5::md5_hex> to get a unique 32 |
52 | character hexidecimal signature. |
53 | |
54 | =head1 METHODS |
55 | |
56 | =head2 signature |
57 | |
58 | The C<signature> method is the only method added to your class, and will |
59 | generate a unique 32 hexidecimal signature for any object it is called on. |
60 | |
61 | =head1 SUPPORT |
62 | |
63 | All bugs should be filed via the bug tracker at |
64 | |
65 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Object-Signature> |
66 | |
67 | For other issues, or commercial enhancement or support, contact the author. |
68 | |
69 | =head1 TO DO |
70 | |
71 | =head2 Incremental Generation |
72 | |
73 | Currently has to generate the entire Storable string before digesting |
74 | it. Would be nice if there was a way to incrementally Storablise and Digest |
75 | in one pass so that it becomes much more memory efficient for large objects. |
76 | |
77 | =head2 Strengthen the Digest Algorithm |
78 | |
79 | Once the current (as of 2005) hashing controversy settles down, consider |
80 | selecting a newer and more powerful hashing algorithm to replace MD5. Or |
81 | offer alternatives depending on how important the security situation is, |
82 | as MD5 is B<very> fast (90 meg a second) and many more-secure ones are a |
83 | lot slower (more than 10 times slower in some cases). |
84 | |
85 | On our side is the fact we use Storable. It should be B<much> harder to create |
86 | collisions when you don't control the string, only the structure B<before> |
87 | it goes through Storable. |
88 | |
89 | =head1 AUTHORS |
90 | |
91 | Adam Kennedy E<lt>adamk@cpan.orgE<gt> |
92 | |
93 | =head1 COPYRIGHT |
94 | |
95 | Copyright 2004 - 2006 Adam Kennedy. |
96 | |
97 | This program is free software; you can redistribute |
98 | it and/or modify it under the same terms as Perl itself. |
99 | |
100 | The full text of the license can be found in the |
101 | LICENSE file included with this module. |
102 | |
103 | =cut |