Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 1.6.14 #7

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
```
6 changes: 3 additions & 3 deletions otp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions otp.nimble
Original file line number Diff line number Diff line change
@@ -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"