23 lines
1,022 B
Text
23 lines
1,022 B
Text
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||
|
|
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||
|
|
|
||
|
|
export module Crafter.Review:Totp;
|
||
|
|
import std;
|
||
|
|
|
||
|
|
// A current TOTP code (RFC 6238, SHA-1, 30 s, 6 digits) for a login fixture:
|
||
|
|
// what the functional lens types into the one-time-code field.
|
||
|
|
export namespace Crafter::Review::Totp {
|
||
|
|
struct Code {
|
||
|
|
std::string code;
|
||
|
|
// The seconds left in its window.
|
||
|
|
std::int32_t left;
|
||
|
|
};
|
||
|
|
// secret: base32, spaces and case as a seeder writes it; std::invalid_argument
|
||
|
|
// with binascii's message for one that is no base32. The clock is read once,
|
||
|
|
// so the code and the seconds left belong to the same window.
|
||
|
|
Code At(std::string_view secret, double now, std::int32_t step = 30, std::int32_t digits = 6);
|
||
|
|
// `crafter-review totp <fixture.json>` or `--secret <base32>`: prints
|
||
|
|
// "123456 (valid 17s)". Exit 1 for a fixture without a secret or a bad
|
||
|
|
// command line.
|
||
|
|
std::int32_t Main(std::span<const std::string_view> args);
|
||
|
|
}
|