Documentation
¶
Overview ¶
Package totp implements TOTP (RFC 6238) validation using only the standard library: HMAC-SHA1 with a 30-second step, 6-digit output, and ±1 step clock skew. It has no dependencies on the rest of Culvert (first internal/ leaf extracted under ADR-0002).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SameKey ¶ added in v1.0.248
SameKey reports whether two stored secret strings denote the SAME authenticator key.
It compares the DECODED keys, never the stored strings: the verifier canonicalises case and surrounding whitespace before decoding, so "jbswy3dpehpk3pxp", " JBSWY3DPEHPK3PXP " and "JBSWY3DPEHPK3PXP" are one key and generate identical codes. A caller deciding whether a key CHANGED must ask this question, not whether the stored string changed.
An unusable secret is never the same key as anything, so a caller must treat !Usable separately rather than reading false as "the key changed" — see Config.SetTOTPSecret in package main.
func Usable ¶ added in v1.0.248
Usable reports whether a stored secret decodes to a key that could validate a code. A secret that is not usable authenticates nothing.
func VerifyTOTPReturnCounter ¶
func VerifyTOTPReturnCounter(secret, code string, nowUnix, lastCounter int64) (ok bool, counter int64)
VerifyTOTPReturnCounter validates a TOTP code and returns (ok, counter) where counter is the matched time-step. Callers MUST track the last-matched counter per user and reject codes whose matched counter is <= lastCounter to close the replay window (RFC 6238 §5.2). Passing lastCounter = 0 disables replay protection (legacy call sites).
A nowUnix parameter is taken instead of calling time.Now() so tests can exercise the function deterministically without clock monkey-patching.
Types ¶
This section is empty.