File: oathtool

package info (click to toggle)
libpass-otp-perl 1.801-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 116 kB
  • sloc: perl: 141; makefile: 7
file content (85 lines) | stat: -rwxr-xr-x 1,784 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/perl

=head1 NAME

oathtool - alternative Perl implementation of oathtool(1), one-time password tool

=head1 SYNOPSIS

oathtool [options] KEY | URI

    Options:
        -h, --help
        -v, --version
        -a, --algorithm
        --hotp
        --totp[=STRING]
        -b, --base32
        -c, --counter=INT
        -s, --time-step-size, --period=SECONDS
        -S, --start-time=UNIX_TIME
        -N, --now=UNIX_TIME
        -d, --digits=INT

    URI: otpauth://....

=cut

use utf8;
use strict;
use warnings;
use open qw(:std :utf8);

use Getopt::Long;
use Pod::Usage;
use Pass::OTP qw(otp);
use Pass::OTP::URI qw(parse);

our $VERSION = '1.2';

pod2usage(2) if @ARGV == 0;
my %options;
$options{secret} = pop if $ARGV[-1] !~ /^-/;

Getopt::Long::Configure(qw(auto_version no_ignore_case));
GetOptions(\%options,
    'help|h|?' => sub { pod2usage(-verbose => 2) },
    'algorithm|a=s',
    'hotp',
    'totp:s',
    'base32|b',
    'counter|c=i',
    'period|time-step-size|s=s',
    'start-time|S=s',
    'now|N=s',
    'digits|d=i',
) || pod2usage(2);

pod2usage(2) if @ARGV == 0 and not defined $options{secret};

$options{type} = 'totp' if defined $options{totp};
$options{algorithm} = $options{totp} if defined $options{totp} and $options{totp} ne '';
%options = parse($options{secret}) if $options{secret} =~ m#^otpauth://#;

my $code = otp(%options);
print "$code\n";
exit 0;

__END__
=head1 SEE ALSO

L<Pass::OTP>

L<oathtool(1)>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2020 Jan Baier

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.

See L<http://dev.perl.org/licenses/> for more information.

=cut