Files
zclaw_openfang/target/doc/totp_rs/index.html
iven 44256a511c feat: 增强SaaS后端功能与安全性
refactor: 重构数据库连接使用PostgreSQL替代SQLite
feat(auth): 增加JWT验证的audience和issuer检查
feat(crypto): 添加AES-256-GCM字段加密支持
feat(api): 集成utoipa实现OpenAPI文档
fix(admin): 修复配置项表单验证逻辑
style: 统一代码格式与类型定义
docs: 更新技术栈文档说明PostgreSQL
2026-03-31 00:12:53 +08:00

35 lines
7.3 KiB
HTML

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="This library permits the creation of 2FA authentification tokens per TOTP, the verification of said tokens, with configurable time skew, validity time of each token, algorithm and number of digits! Default features are kept as low-dependency as possible to ensure small binaries and short compilation time"><title>totp_rs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2"href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="totp_rs" data-themes="" data-resource-suffix="" data-rustdoc-version="1.93.1 (01f6ddf75 2026-02-11)" data-channel="1.93.1" data-search-js="search-9e2438ea.js" data-stringdex-js="stringdex-a3946164.js" data-settings-js="settings-c38705f0.js" ><script src="../static.files/storage-e2aeef58.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-a410ff4d.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><rustdoc-topbar><h2><a href="#">Crate totp_rs</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../totp_rs/index.html">totp_rs</a><span class="version">5.7.1</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#examples" title="Examples">Examples</a></li></ul><h3><a href="#structs">Crate Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>totp_rs</span>&nbsp;<button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/totp_rs/lib.rs.html#1-1368">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>This library permits the creation of 2FA authentification tokens per TOTP, the verification of said tokens, with configurable time skew, validity time of each token, algorithm and number of digits! Default features are kept as low-dependency as possible to ensure small binaries and short compilation time</p>
<p>Be aware that some authenticator apps will accept the <code>SHA256</code>
and <code>SHA512</code> algorithms but silently fallback to <code>SHA1</code> which will
make the <code>check()</code> function fail due to mismatched algorithms.</p>
<p>Use the <code>SHA1</code> algorithm to avoid this problem.</p>
<h2 id="examples"><a class="doc-anchor" href="#examples">§</a>Examples</h2>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::time::SystemTime;
<span class="kw">use </span>totp_rs::{Algorithm, TOTP, Secret};
<span class="kw">let </span>totp = TOTP::new(
Algorithm::SHA1,
<span class="number">6</span>,
<span class="number">1</span>,
<span class="number">30</span>,
Secret::Raw(<span class="string">"TestSecretSuperSecret"</span>.as_bytes().to_vec()).to_bytes().unwrap(),
<span class="prelude-val">Some</span>(<span class="string">"Github"</span>.to_string()),
<span class="string">"constantoine@github.com"</span>.to_string(),
).unwrap();
<span class="kw">let </span>token = totp.generate_current().unwrap();
<span class="macro">println!</span>(<span class="string">"{}"</span>, token);</code></pre></div>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>totp_rs::{Algorithm, TOTP};
<span class="kw">let </span>totp = TOTP::new(
Algorithm::SHA1,
<span class="number">6</span>,
<span class="number">1</span>,
<span class="number">30</span>,
<span class="string">"supersecret_topsecret"</span>.as_bytes().to_vec(),
<span class="prelude-val">Some</span>(<span class="string">"Github"</span>.to_string()),
<span class="string">"constantoine@github.com"</span>.to_string(),
).unwrap();
<span class="kw">let </span>url = totp.get_url();
<span class="macro">println!</span>(<span class="string">"{}"</span>, url);
<span class="kw">let </span>code = totp.get_qr_base64().unwrap();
<span class="macro">println!</span>(<span class="string">"{}"</span>, code);</code></pre></div></div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.Rfc6238.html" title="struct totp_rs::Rfc6238">Rfc6238</a></dt><dd><a href="https://tools.ietf.org/html/rfc6238">rfc-6238</a> compliant set of options to create a <a href="struct.TOTP.html">TOTP</a></dd><dt><a class="struct" href="struct.TOTP.html" title="struct totp_rs::TOTP">TOTP</a></dt><dd>TOTP holds informations as to how to generate an auth code and validate it. Its <a href="struct.TOTP.html#structfield.secret">secret</a> field is sensitive data, treat it accordingly</dd></dl><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><dl class="item-table"><dt><a class="enum" href="enum.Algorithm.html" title="enum totp_rs::Algorithm">Algorithm</a></dt><dd>Algorithm enum holds the three standards algorithms for TOTP as per the <a href="https://tools.ietf.org/html/rfc6238#appendix-A">reference implementation</a></dd><dt><a class="enum" href="enum.Rfc6238Error.html" title="enum totp_rs::Rfc6238Error">Rfc6238<wbr>Error</a></dt><dd>Error returned when input is not compliant to <a href="https://tools.ietf.org/html/rfc6238">rfc-6238</a>.</dd><dt><a class="enum" href="enum.Secret.html" title="enum totp_rs::Secret">Secret</a></dt><dd>Shared secret between client and server to validate token against/generate token from.</dd><dt><a class="enum" href="enum.SecretParseError.html" title="enum totp_rs::SecretParseError">Secret<wbr>Parse<wbr>Error</a></dt><dd>Different ways secret parsing failed.</dd><dt><a class="enum" href="enum.TotpUrlError.html" title="enum totp_rs::TotpUrlError">Totp<wbr>UrlError</a></dt><dd>Errors returned mostly upon decoding URL.</dd></dl></section></div></main></body></html>