Debian Codegraph @

contrib/hashcash-request

raw
1 #!/usr/bin/perl
2
3 # $Id: hashcash-request,v 1.2 2004/03/31 05:05:10 kyle Exp $
4
5 #
6 # hashcash-request
7 #
8 # This goes with hashcash-daemon. Use this script to make a request for
9 # the daemon to precompute a token for a later message. When the daemon
10 # isn't busy, it will make the token to be used later.
11 #
12 # An up-to-date version is normally here:
13 # http://www.toehold.com/~kyle/hashcash/
14 #
15
16 # Consider this ALPHA software. It works for me, but it has not been through
17 # much real testing.
18
19 #
20 # Copyright (C) 2004 Kyle Hasselbacher <[email protected]>
21 #
22 # This program is free software; you can redistribute it and/or modify it
23 # under the terms of the GNU General Public License as published by the
24 # Free Software Foundation; either version 2 of the License, or (at your
25 # option) any later version.
26 #
27 # This program is distributed in the hope that it will be useful, but
28 # WITHOUT ANY WARRANTY; without even the implied warranty of
29 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
30 # Public License for more details.
31 #
32 # You should have received a copy of the GNU General Public License along
33 # with this program; if not, write to the Free Software Foundation, Inc.,
34 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 #
36
37 use strict;
38 use Data::Dumper;
39
40 #
41 # I want to support some of the same flags that hashcash does.
42 #
43 # -b bits find or check partial hash collision of length bits
44 # -r resource resource name for minting or checking token
45 # -e period time until token expires
46 # -t time modify current time token created at
47 # -a time modify time by random amount in range given
48 # -u give time in UTC instead of local time
49 # -h print this usage info
50 # -z width width of time field 2,4,6,8,10 or 12 chars (default 6)
51 # -L limit -- make no more than this many tokens for a given resource
52
53 # This hash will be sent to hashcash-sendmail when it's done.
54 my $add = { 'nice' => 19 };
55
56 # Process command line arguments. A better processor would do some
57 # sanity checks on these.
58 while ( defined( my $arg = shift ) ) {
59 if ( $arg eq '-b' ) {
60 $$add{ 'bits' } = shift;
61 }
62 elsif ( $arg eq '-t' ) {
63 $$add{ 'expiry' } = shift;
64 }
65 elsif ( $arg eq '-r' ) {
66 $$add{ 'addr' } = shift;
67 }
68 elsif ( $arg eq '-h' ) {
69 print<<'END_OF_HELP';
70 -b bits find partial hash collision of length bits
71 -r resource resource name for minting token
72 -t time modify current time token created at
73 -h print this usage info
74 END_OF_HELP
75 exit;
76 }
77 }
78 if ( ! exists( $$add{ 'addr' } ) ) {
79 $$add{ 'addr' } = undef;
80 }
81
82 my @rcpt = ( $add );
83
84 #my $width = 6;
85 #$width = $opt_z if ( defined( $opt_z ) );
86 #if ( $width != 2 && $width != 4 && $width != 6 && $width != 8 &&
87 # $width != 10 && $width != 12 ) {
88 # die "Acceptible widths are 2, 4, 6, 8, 10 or 12.\n";
89 #}
90
91 # Open a pipe to hashcash-sendmail. Invoking it this way implies that
92 # a request is on the way in on standard input.
93 if ( ! open( HCSM, "|hashcash-sendmail" ) ) {
94 die "Can't execute hashcash-sendmail: $!\n";
95 }
96
97 $Data::Dumper::Useqq = 1;
98
99 my $dump = Data::Dumper->Dump( [ \@rcpt ], [ qw( *rcpt ) ] );
100 $dump .= "\n1;\n";
101
102 print HCSM $dump;
103 close( HCSM );
104
105 exit 0;
106
107 # $Log: hashcash-request,v $
108 # Revision 1.2 2004/03/31 05:05:10 kyle
109 # It does the same thing but completely differently to go with the new
110 # hashcash-sendmail which doesn't have a hashcash-daemon
111 #
112 # Revision 1.1 2004/03/24 17:49:48 kyle
113 # Initial revision
114 #