diff --git a/README.md b/README.md index d72463a..9e0c51c 100644 --- a/README.md +++ b/README.md @@ -38,3 +38,13 @@ echo totp.now() This library uses the wonderful [stack_strings](https://github.com/termermc/nim-stack-strings) library for secrets. Meaning secrets are fixed length one can use `--otp.secretSize:50` to override the size. By default the secret length is 32 bytes. +Due to this the best way to handle secrets is as follows: +```nim +let mySecret = "S3cret" +if mySecret.len < secretSize: + let hotp = Hotp.init(mySecret) + assert hotp.at(0) == 755224 +else: + # Do something errory here + raise (ref ValueError)(msg: "Secret size too large") +``` diff --git a/otp.nim b/otp.nim index 63fed54..13583b4 100644 --- a/otp.nim +++ b/otp.nim @@ -14,7 +14,7 @@ from math import pow from times import epochTime import stack_strings as stackstrings -const secretSize {.intDefine: "otp.secretSize".} = 32 +const secretSize* {.intDefine: "otp.secretSize".} = 32 type OneTimePasswordDefect = object of Defect @@ -34,8 +34,8 @@ when NimMajor >= 2: proc `=dup`(_: HOTP): HOTP {.error: hookStr.} proc `=dup`(_: TOTP): TOTP {.error: hookStr.} -proc `=copy`(_: var HOTP, _: HOTP){.error: hookStr} -proc `=copy`(_: var TOTP, _: TOTP){.error: hookStr} +proc `=copy`(a: var HOTP, b: HOTP){.error: hookStr} +proc `=copy`(a: var TOTP, b: TOTP){.error: hookStr} proc init*(_: typedesc[HOTP], secret: static openArray[char], digits: int = 6): HOTP = when secret.len > secretSize: diff --git a/otp.nimble b/otp.nimble index 1420dd0..f44d216 100644 --- a/otp.nimble +++ b/otp.nimble @@ -1,13 +1,13 @@ [Package] name = "otp" -version = "0.3.1" +version = "0.3.2" author = "Huy Doan" description = "One Time Password library for Nim" license = "MIT" skipDirs = @["tests"] [Deps] -Requires: "nim >= 1.6.10" +Requires: "nim >= 1.6.14" Requires: "hmac >= 0.3.1" Requires: "base32 >= 0.1.3" -Requires: "stack_strings >= 1.1.2" +Requires: "stack_strings >= 1.1.3"