ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Net-FCP/FCP/Key/CHK.pm
Revision: 1.1
Committed: Tue Sep 16 07:00:59 2003 UTC (23 years ago) by root
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

# Content
1 =head1 NAME
2
3 Net::FCP::Key::CHK - manage CHK keys.
4
5 =head1 SYNOPSIS
6
7 use Net::FCP::Key::CHK;
8
9 my $key = new Net::FCP::Key::CHK;
10 my $key = new_from_uri Net::FCP::Key::CHK $uri;
11 my $key = new_from_data Net::FCP::Key::CHK $data, $metadata;
12 ... more to come
13
14
15 =head1 DESCRIPTION
16
17 =back
18
19 =head2 THE Net::FCP::Key::CHK CLASS
20
21 =over 4
22
23 =cut
24
25 package Net::FCP::Key::CHK;
26
27 use Carp;
28 use Digest::SHA1;
29 use Crypt::Twofish2;
30 use MIME::Base64;
31
32 no warnings;
33
34 sub log2($$) { # n, minlog
35 my ($n, $b) = @_;
36
37 $b++ while 1 << $b < $n;
38
39 $b;
40 }
41
42 sub decode_fbase64 {
43 my $s = shift;
44
45 $s =~ y%~\-%+/%;
46 decode_base64 "$s======";
47 }
48
49 sub encode_fbase64 {
50 my $s = encode_base64 shift, "";
51 $s =~ s/=+$//;
52 $s =~ y%+/%~\-%;
53 $s;
54 }
55
56 =item my $key = new Net::FCP::Key::CHK;
57
58 Don't use :)
59
60 =cut
61
62 sub new {
63 my $class = shift;
64
65 bless { }, $class;
66 }
67
68 =item my $key = new_from_date Net::FCP::Key::CHK $data, $metadata;
69
70 Generate a CHK from the given data and metadata strings.
71
72 =cut
73
74 sub new_from_data {
75 my ($class, $data, $metadata) = @_;
76
77 $class->new->set_data ($data, $metadata);
78 }
79
80 sub set_data {
81 my ($self, $data, $metadata) = @_;
82
83 my $d = new Digest::SHA1;
84 $d->add ($metadata);
85 $d->add ($data);
86 $d = $d->digest;
87
88 # only works for 128 bit keys
89 my $k = new Digest::SHA1;
90 $k->add ("\x00" x 1);
91 $k->add ($d);
92 }
93
94 =item $size = $key->size
95
96 Returns the size of the data (in bytes).
97
98 =cut
99
100 =item $digest = $key->digest
101
102 Return the store digest/hash.
103
104 =cut
105
106 =item $keynum = $key->keynumber
107
108 Returns the keynumber (version?)
109
110 =cut
111
112 =item $chk = $key->chk
113
114 Return the full CHK.
115
116 =cut
117
118 =back
119
120 =head1 SEE ALSO
121
122 L<Net::FCP>.
123
124 =head1 BUGS
125
126 Not heavily tested.
127
128 =head1 AUTHOR
129
130 Marc Lehmann <pcg@goof.com>
131 http://www.goof.com/pcg/marc/
132
133 =cut
134
135 1;
136