Skip to content

Commit

Permalink
Merge pull request #7 from beef331/master
Browse files Browse the repository at this point in the history
Support 1.6.14
  • Loading branch information
ba0f3 authored Sep 27, 2023
2 parents 48c2f5a + b8e7c4d commit 963acaa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
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"

0 comments on commit 963acaa

Please sign in to comment.