mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-24 23:57:38 +01:00
Give a name to a magic number and document it
This commit is contained in:
parent
daec5ee13e
commit
05603560e6
1 changed files with 16 additions and 5 deletions
|
@ -758,11 +758,22 @@ pub(crate) fn hide_token(mut error: reqwest::Error) -> reqwest::Error {
|
||||||
if let Some(token) = segment.and_then(|s| s.strip_prefix("bot")) {
|
if let Some(token) = segment.and_then(|s| s.strip_prefix("bot")) {
|
||||||
// make sure that what we are about to delete looks like a bot token
|
// make sure that what we are about to delete looks like a bot token
|
||||||
if let Some((id, secret)) = token.split_once(':') {
|
if let Some((id, secret)) = token.split_once(':') {
|
||||||
if secret.len() >= 35
|
// The part before the : in the token is the id of the bot.
|
||||||
&& secret
|
let id_character = |c: char| c.is_ascii_digit();
|
||||||
.chars()
|
|
||||||
.all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_')
|
// The part after the : in the token is the secret.
|
||||||
&& id.chars().all(|c| c.is_ascii_digit())
|
//
|
||||||
|
// In all bot tokens we could find the secret is 35 characters long and is
|
||||||
|
// 0-9a-zA-Z_- only.
|
||||||
|
//
|
||||||
|
// It would be nice to research if TBA always has 35 character secrets or if it
|
||||||
|
// is just a coincidence.
|
||||||
|
const SECRET_LENGTH: usize = 35;
|
||||||
|
let secret_character = |c: char| c.is_ascii_alphanumeric() || c == '-' || c == '_';
|
||||||
|
|
||||||
|
if secret.len() >= SECRET_LENGTH
|
||||||
|
&& id.chars().all(id_character)
|
||||||
|
&& secret.chars().all(secret_character)
|
||||||
{
|
{
|
||||||
// found token, hide only the token
|
// found token, hide only the token
|
||||||
let without_token =
|
let without_token =
|
||||||
|
|
Loading…
Add table
Reference in a new issue