File tree Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,10 @@ def parser
6868 parser . on_tail ( '-h' , '--help' , 'Show this message' ) do
6969 options! . mode = :help
7070 end
71+
72+ parser . on ( '-d' , '--digest [ALGORITHM]' , 'Use algorithm for the digest (default sha1)' ) do |digest |
73+ options! . digest = digest
74+ end
7175 end
7276 end
7377
Original file line number Diff line number Diff line change @@ -31,9 +31,9 @@ def output
3131 return arguments . to_s if options . mode == :help
3232
3333 if options . mode == :time
34- ROTP ::TOTP . new ( options . secret ) . now
34+ ROTP ::TOTP . new ( options . secret , options ) . now
3535 elsif options . mode == :hmac
36- ROTP ::HOTP . new ( options . secret ) . at options . counter
36+ ROTP ::HOTP . new ( options . secret , options ) . at options . counter
3737 end
3838 end
3939
Original file line number Diff line number Diff line change 1818 end
1919 end
2020
21+ context 'generating a TOTP with sha256 digest' do
22+ let ( :argv ) { %w[ --secret JBSWY3DPEHPK3PXP --digest sha256 ] }
23+
24+ it 'prints the corresponding token' do
25+ expect ( output ) . to eq '544902'
26+ end
27+ end
28+
2129 context 'generating a TOTP with no secret' do
2230 let ( :argv ) { %w[ --time --secret ] }
2331
4957 expect ( output ) . to eq '161024'
5058 end
5159 end
60+
61+ context 'generating a HOTP' do
62+ let ( :argv ) { %W[ --hmac --secret #{ 'a' * 32 } --counter 1234 --digest sha256 ] }
63+
64+ it 'prints the corresponding token' do
65+ expect ( output ) . to eq '325941'
66+ end
67+ end
5268end
You can’t perform that action at this time.
0 commit comments