Debian Codegraph @

bin/oathtool

raw
1 #!/usr/bin/perl
2
3 =head1 NAME
4
5 oathtool - alternative Perl implementation of oathtool(1), one-time password tool
6
7 =head1 SYNOPSIS
8
9 oathtool [options] KEY | URI | -
10
11 Options:
12 -h, --help
13 -v, --version
14 -a, --algorithm
15 --hotp
16 --totp[=STRING]
17 -b, --base32
18 -c, --counter=INT
19 -s, --time-step-size, --period=SECONDS
20 -S, --start-time=UNIX_TIME
21 -N, --now=UNIX_TIME
22 -d, --digits=INT
23
24 If invoked with '-', the key or URI is read from standard input.
25
26 URI: otpauth://....
27
28 =cut
29
30 use utf8;
31 use strict;
32 use warnings;
33 use open qw(:std :utf8);
34
35 use Getopt::Long;
36 use Pod::Usage;
37 use Pass::OTP qw(otp);
38 use Pass::OTP::URI qw(parse);
39
40 our $VERSION = '1.2';
41
42 pod2usage(2) if @ARGV == 0;
43 my %options;
44
45 Getopt::Long::Configure(qw(auto_version no_ignore_case));
46 GetOptions(\%options,
47 'help|h|?' => sub { pod2usage(-verbose => 2) },
48 'algorithm|a=s',
49 'hotp',
50 'totp:s',
51 'base32|b',
52 'counter|c=i',
53 'period|time-step-size|s=s',
54 'start-time|S=s',
55 'now|N=s',
56 'digits|d=i',
57 ) || pod2usage(2);
58
59 if ($ARGV[0] eq '-') {
60 $options{secret} = <>;
61 chomp($options{secret});
62 } elsif (@ARGV == 0) {
63 pod2usage(2);
64 } else {
65 $options{secret} = $ARGV[0];
66 }
67
68 $options{type} = 'totp' if defined $options{totp};
69 $options{algorithm} = $options{totp} if defined $options{totp} and $options{totp} ne '';
70 %options = parse($options{secret}) if $options{secret} =~ m#^otpauth://#;
71
72 my $code = otp(%options);
73 print "$code\n";
74 exit 0;
75
76 __END__
77 =head1 SEE ALSO
78
79 L<Pass::OTP>
80
81 L<oathtool(1)>
82
83 =head1 COPYRIGHT AND LICENSE
84
85 Copyright (C) 2020 Jan Baier
86
87 This program is free software; you can redistribute it and/or modify it
88 under the terms of either: the GNU General Public License as published
89 by the Free Software Foundation; or the Artistic License.
90
91 See L<http://dev.perl.org/licenses/> for more information.
92
93 =cut