totptool/cmds/code.nim

27 lines
540 B
Nim
Raw Normal View History

2015-09-15 01:49:40 +00:00
import otp
import os
2016-02-05 01:39:13 +00:00
const codeUsage* =
2015-09-15 02:10:07 +00:00
"""Usage: totptool code <name>
2015-09-15 01:49:40 +00:00
2015-09-15 02:10:07 +00:00
This will generate a TOTP code for the given secret
name in the secret store.
"""
proc code*(root: string, args: seq[string]) =
2015-09-15 01:49:40 +00:00
if args.len != 1:
quit "I need a machine name"
try:
var
keyFileName = args[0]
2015-09-15 02:10:07 +00:00
fin = open root / keyFileName
2015-09-15 01:49:40 +00:00
key = fin.readLine
totp = newTotp key
echo totp.now()
except:
echo getCurrentExceptionMsg()
quit "Couldn't do that for " & args[0] & ". Does that machine exist in the store?"