Removed inlines
This commit is contained in:
parent
064ec22e51
commit
25b02ba99a
@ -2,7 +2,6 @@ use super::AlterableField::{self, Login, Name, Pass};
|
|||||||
use crate::{change_state, cryptography::account::Cipher, prelude::*};
|
use crate::{change_state, cryptography::account::Cipher, prelude::*};
|
||||||
use tokio::task::spawn_blocking;
|
use tokio::task::spawn_blocking;
|
||||||
|
|
||||||
#[inline]
|
|
||||||
async fn update_account(
|
async fn update_account(
|
||||||
user_id: u64,
|
user_id: u64,
|
||||||
db: &Pool,
|
db: &Pool,
|
||||||
@ -38,7 +37,6 @@ async fn update_account(
|
|||||||
Ok(updated)
|
Ok(updated)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
async fn get_master_pass(
|
async fn get_master_pass(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
@ -72,7 +70,6 @@ async fn get_master_pass(
|
|||||||
|
|
||||||
handler!(get_field(name:String, field:AlterableField, field_value:String),send_master_password, State::GetMasterPass, get_master_pass);
|
handler!(get_field(name:String, field:AlterableField, field_value:String),send_master_password, State::GetMasterPass, get_master_pass);
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub async fn alter(
|
pub async fn alter(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
q: CallbackQuery,
|
q: CallbackQuery,
|
||||||
|
@ -2,7 +2,6 @@ use crate::{
|
|||||||
entity::locale::LocaleType, locales::LocaleTypeExt, markups::language_markup, prelude::*,
|
entity::locale::LocaleType, locales::LocaleTypeExt, markups::language_markup, prelude::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub async fn change_locale(
|
pub async fn change_locale(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
q: CallbackQuery,
|
q: CallbackQuery,
|
||||||
|
@ -2,7 +2,6 @@ use crate::{change_state, markups::account_markup, prelude::*};
|
|||||||
use teloxide::types::ParseMode;
|
use teloxide::types::ParseMode;
|
||||||
use tokio::task::spawn_blocking;
|
use tokio::task::spawn_blocking;
|
||||||
|
|
||||||
#[inline]
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
async fn get_master_pass(
|
async fn get_master_pass(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
@ -40,7 +39,6 @@ async fn get_master_pass(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub async fn decrypt(
|
pub async fn decrypt(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
q: CallbackQuery,
|
q: CallbackQuery,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::{change_state, prelude::*};
|
use crate::{change_state, prelude::*};
|
||||||
|
|
||||||
#[inline]
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
async fn get_master_pass(
|
async fn get_master_pass(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
@ -23,7 +22,6 @@ async fn get_master_pass(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub async fn delete(
|
pub async fn delete(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
q: CallbackQuery,
|
q: CallbackQuery,
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
/// Deletes the message from the callback
|
/// Deletes the message from the callback
|
||||||
#[inline]
|
|
||||||
pub async fn delete_message(
|
pub async fn delete_message(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
q: CallbackQuery,
|
q: CallbackQuery,
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use crate::{markups::account_markup, prelude::*};
|
use crate::{markups::account_markup, prelude::*};
|
||||||
use teloxide::types::ParseMode;
|
use teloxide::types::ParseMode;
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub async fn get(
|
pub async fn get(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
q: CallbackQuery,
|
q: CallbackQuery,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub async fn get_menu(
|
pub async fn get_menu(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
q: CallbackQuery,
|
q: CallbackQuery,
|
||||||
|
@ -3,7 +3,6 @@ use tokio::task::spawn_blocking;
|
|||||||
|
|
||||||
/// Gets the name of the master password, encryptes the account and adds it to the DB
|
/// Gets the name of the master password, encryptes the account and adds it to the DB
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
#[inline]
|
|
||||||
async fn get_master_pass(
|
async fn get_master_pass(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
msg: Message,
|
msg: Message,
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
/// Handles /cancel command when there's no active state
|
/// Handles /cancel command when there's no active state
|
||||||
#[inline]
|
|
||||||
pub async fn cancel(bot: Throttle<Bot>, msg: Message, locale: LocaleRef) -> crate::Result<()> {
|
pub async fn cancel(bot: Throttle<Bot>, msg: Message, locale: LocaleRef) -> crate::Result<()> {
|
||||||
bot.send_message(msg.chat.id, &locale.nothing_to_cancel)
|
bot.send_message(msg.chat.id, &locale.nothing_to_cancel)
|
||||||
.reply_markup(deletion_markup(locale))
|
.reply_markup(deletion_markup(locale))
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::{markups::language_markup, prelude::*};
|
use crate::{markups::language_markup, prelude::*};
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub async fn change_language(
|
pub async fn change_language(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
msg: Message,
|
msg: Message,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub async fn delete(
|
pub async fn delete(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
msg: Message,
|
msg: Message,
|
||||||
|
@ -2,7 +2,6 @@ use crate::prelude::*;
|
|||||||
|
|
||||||
/// Gets the master password, deletes the accounts and the master password from DB.
|
/// Gets the master password, deletes the accounts and the master password from DB.
|
||||||
/// Although it doesn't use the master password, we get it to be sure that it's the user who used that command
|
/// Although it doesn't use the master password, we get it to be sure that it's the user who used that command
|
||||||
#[inline]
|
|
||||||
async fn get_master_pass(
|
async fn get_master_pass(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
msg: Message,
|
msg: Message,
|
||||||
|
@ -5,7 +5,6 @@ use teloxide::types::InputFile;
|
|||||||
use tokio::task::spawn_blocking;
|
use tokio::task::spawn_blocking;
|
||||||
|
|
||||||
/// Decryptes the account on a worker thread and adds it to the accounts vector
|
/// Decryptes the account on a worker thread and adds it to the accounts vector
|
||||||
#[inline]
|
|
||||||
async fn decrypt_account(
|
async fn decrypt_account(
|
||||||
account: Account,
|
account: Account,
|
||||||
master_pass: Arc<str>,
|
master_pass: Arc<str>,
|
||||||
@ -18,7 +17,6 @@ async fn decrypt_account(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the master password, decryptes the account and sends the json file to the user
|
/// Gets the master password, decryptes the account and sends the json file to the user
|
||||||
#[inline]
|
|
||||||
async fn get_master_pass(
|
async fn get_master_pass(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
msg: Message,
|
msg: Message,
|
||||||
|
@ -11,7 +11,6 @@ type PasswordArray = [ArrayString<PASSWORD_LENGTH>; AMOUNT_OF_PASSWORDS];
|
|||||||
const BUFFER_LENGTH: usize = (PASSWORD_LENGTH + PASSWORD_PADDING_LENGTH) * AMOUNT_OF_PASSWORDS;
|
const BUFFER_LENGTH: usize = (PASSWORD_LENGTH + PASSWORD_PADDING_LENGTH) * AMOUNT_OF_PASSWORDS;
|
||||||
|
|
||||||
/// Handles /`gen_password` command by generating 10 copyable passwords and sending them to the user
|
/// Handles /`gen_password` command by generating 10 copyable passwords and sending them to the user
|
||||||
#[inline]
|
|
||||||
pub async fn gen_password(
|
pub async fn gen_password(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
msg: Message,
|
msg: Message,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub async fn get_account(
|
pub async fn get_account(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
msg: Message,
|
msg: Message,
|
||||||
|
@ -3,7 +3,6 @@ use std::fmt::Write;
|
|||||||
use teloxide::types::ParseMode;
|
use teloxide::types::ParseMode;
|
||||||
|
|
||||||
/// Handles /`get_accounts` command by sending the list of copyable account names to the user
|
/// Handles /`get_accounts` command by sending the list of copyable account names to the user
|
||||||
#[inline]
|
|
||||||
pub async fn get_accounts(
|
pub async fn get_accounts(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
msg: Message,
|
msg: Message,
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
/// Handles the help command by sending the passwords descryptions
|
/// Handles the help command by sending the passwords descryptions
|
||||||
#[inline]
|
|
||||||
pub async fn help(bot: Throttle<Bot>, msg: Message, locale: LocaleRef) -> crate::Result<()> {
|
pub async fn help(bot: Throttle<Bot>, msg: Message, locale: LocaleRef) -> crate::Result<()> {
|
||||||
bot.send_message(msg.chat.id, &locale.help_command)
|
bot.send_message(msg.chat.id, &locale.help_command)
|
||||||
.reply_markup(deletion_markup(locale))
|
.reply_markup(deletion_markup(locale))
|
||||||
|
@ -7,7 +7,6 @@ use tokio::task::spawn_blocking;
|
|||||||
|
|
||||||
/// Ecryptes the account and adds it to the database
|
/// Ecryptes the account and adds it to the database
|
||||||
/// If any of these steps fail, the account name will be added to the failed vector
|
/// If any of these steps fail, the account name will be added to the failed vector
|
||||||
#[inline]
|
|
||||||
async fn encrypt_account(
|
async fn encrypt_account(
|
||||||
account: DecryptedAccount,
|
account: DecryptedAccount,
|
||||||
user_id: u64,
|
user_id: u64,
|
||||||
@ -26,7 +25,6 @@ async fn encrypt_account(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the master password, encryptes and adds the accounts to the DB
|
/// Gets the master password, encryptes and adds the accounts to the DB
|
||||||
#[inline]
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
async fn get_master_pass(
|
async fn get_master_pass(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub async fn menu(
|
pub async fn menu(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
msg: Message,
|
msg: Message,
|
||||||
|
@ -4,7 +4,6 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use tokio::task::spawn_blocking;
|
use tokio::task::spawn_blocking;
|
||||||
|
|
||||||
#[inline]
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
async fn get_master_pass2(
|
async fn get_master_pass2(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
@ -50,7 +49,6 @@ async fn get_master_pass2(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
async fn get_master_pass(
|
async fn get_master_pass(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
_: Message,
|
_: Message,
|
||||||
@ -77,7 +75,6 @@ async fn get_master_pass(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Handles /`set_master_pass` command
|
/// Handles /`set_master_pass` command
|
||||||
#[inline]
|
|
||||||
pub async fn set_master_pass(
|
pub async fn set_master_pass(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
msg: Message,
|
msg: Message,
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
/// Handles /start command by sending the greeting message
|
/// Handles /start command by sending the greeting message
|
||||||
#[inline]
|
|
||||||
pub async fn start(bot: Throttle<Bot>, msg: Message, locale: LocaleRef) -> crate::Result<()> {
|
pub async fn start(bot: Throttle<Bot>, msg: Message, locale: LocaleRef) -> crate::Result<()> {
|
||||||
bot.send_message(msg.chat.id, &locale.start_command).await?;
|
bot.send_message(msg.chat.id, &locale.start_command).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -5,7 +5,6 @@ pub mod hashing;
|
|||||||
pub mod passwords;
|
pub mod passwords;
|
||||||
|
|
||||||
/// Returns true if the field is valid
|
/// Returns true if the field is valid
|
||||||
#[inline]
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn validate_field(field: &str) -> bool {
|
pub fn validate_field(field: &str) -> bool {
|
||||||
if field.len() > 255 {
|
if field.len() > 255 {
|
||||||
|
@ -10,7 +10,6 @@ pub struct Cipher {
|
|||||||
|
|
||||||
impl Cipher {
|
impl Cipher {
|
||||||
/// Creates a new cipher from a master password and the salt
|
/// Creates a new cipher from a master password and the salt
|
||||||
#[inline]
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new(password: &[u8], salt: &[u8]) -> Self {
|
pub fn new(password: &[u8], salt: &[u8]) -> Self {
|
||||||
let key = pbkdf2_hmac_array::<Sha256, 32>(password, salt, 480_000);
|
let key = pbkdf2_hmac_array::<Sha256, 32>(password, salt, 480_000);
|
||||||
@ -21,7 +20,6 @@ impl Cipher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Encrypts the value with the current cipher. The 12 byte nonce is appended to the result
|
/// Encrypts the value with the current cipher. The 12 byte nonce is appended to the result
|
||||||
#[inline]
|
|
||||||
pub fn encrypt(&self, value: &mut Vec<u8>) {
|
pub fn encrypt(&self, value: &mut Vec<u8>) {
|
||||||
let nonce = ChaCha20Poly1305::generate_nonce(&mut OsRng);
|
let nonce = ChaCha20Poly1305::generate_nonce(&mut OsRng);
|
||||||
self.chacha.encrypt_in_place(&nonce, b"", value).unwrap();
|
self.chacha.encrypt_in_place(&nonce, b"", value).unwrap();
|
||||||
@ -33,7 +31,6 @@ impl Cipher {
|
|||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// Returns an error if the tag doesn't match the ciphertext
|
/// Returns an error if the tag doesn't match the ciphertext
|
||||||
#[inline]
|
|
||||||
#[allow(clippy::missing_panics_doc)]
|
#[allow(clippy::missing_panics_doc)]
|
||||||
pub fn decrypt(&self, value: &mut Vec<u8>) -> super::Result<()> {
|
pub fn decrypt(&self, value: &mut Vec<u8>) -> super::Result<()> {
|
||||||
if value.len() <= 12 {
|
if value.len() <= 12 {
|
||||||
@ -61,7 +58,6 @@ impl Decrypted {
|
|||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// Returns an error if the tag doesn't match the ciphertext or if the decrypted data isn't valid UTF-8
|
/// Returns an error if the tag doesn't match the ciphertext or if the decrypted data isn't valid UTF-8
|
||||||
#[inline]
|
|
||||||
pub fn from_account(mut account: Account, master_pass: &str) -> super::Result<Self> {
|
pub fn from_account(mut account: Account, master_pass: &str) -> super::Result<Self> {
|
||||||
let cipher = Cipher::new(master_pass.as_bytes(), &account.salt);
|
let cipher = Cipher::new(master_pass.as_bytes(), &account.salt);
|
||||||
cipher.decrypt(&mut account.enc_login)?;
|
cipher.decrypt(&mut account.enc_login)?;
|
||||||
@ -75,7 +71,6 @@ impl Decrypted {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Constructs `ActiveModel` with eath field Set by encrypting `self`
|
/// Constructs `ActiveModel` with eath field Set by encrypting `self`
|
||||||
#[inline]
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn into_account(self, user_id: u64, master_pass: &str) -> Account {
|
pub fn into_account(self, user_id: u64, master_pass: &str) -> Account {
|
||||||
let mut enc_login = self.login.into_bytes();
|
let mut enc_login = self.login.into_bytes();
|
||||||
@ -97,7 +92,6 @@ impl Decrypted {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the account's fields are valid
|
/// Returns true if the account's fields are valid
|
||||||
#[inline]
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn validate(&self) -> bool {
|
pub fn validate(&self) -> bool {
|
||||||
[
|
[
|
||||||
|
@ -10,7 +10,6 @@ pub const SALT_LENGTH: usize = 64;
|
|||||||
static PARAMS: Lazy<Params> = Lazy::new(|| Params::new(14, 8, 1, HASH_LENGTH).unwrap());
|
static PARAMS: Lazy<Params> = Lazy::new(|| Params::new(14, 8, 1, HASH_LENGTH).unwrap());
|
||||||
|
|
||||||
/// Hashes the bytes with Scrypt with the given salt
|
/// Hashes the bytes with Scrypt with the given salt
|
||||||
#[inline]
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[allow(clippy::missing_panics_doc)]
|
#[allow(clippy::missing_panics_doc)]
|
||||||
pub fn hash_scrypt(bytes: &[u8], salt: &[u8]) -> [u8; HASH_LENGTH] {
|
pub fn hash_scrypt(bytes: &[u8], salt: &[u8]) -> [u8; HASH_LENGTH] {
|
||||||
@ -30,7 +29,6 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl HashedBytes<[u8; HASH_LENGTH], [u8; SALT_LENGTH]> {
|
impl HashedBytes<[u8; HASH_LENGTH], [u8; SALT_LENGTH]> {
|
||||||
#[inline]
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new(bytes: &[u8]) -> Self {
|
pub fn new(bytes: &[u8]) -> Self {
|
||||||
let mut salt = [0; 64];
|
let mut salt = [0; 64];
|
||||||
@ -47,7 +45,6 @@ where
|
|||||||
T: AsRef<[u8]>,
|
T: AsRef<[u8]>,
|
||||||
U: AsRef<[u8]>,
|
U: AsRef<[u8]>,
|
||||||
{
|
{
|
||||||
#[inline]
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn verify(&self, bytes: &[u8]) -> bool {
|
pub fn verify(&self, bytes: &[u8]) -> bool {
|
||||||
let hash = hash_scrypt(bytes, self.salt.as_ref());
|
let hash = hash_scrypt(bytes, self.salt.as_ref());
|
||||||
@ -56,7 +53,6 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<&'a MasterPass> for HashedBytes<&'a [u8], &'a [u8]> {
|
impl<'a> From<&'a MasterPass> for HashedBytes<&'a [u8], &'a [u8]> {
|
||||||
#[inline]
|
|
||||||
fn from(value: &'a MasterPass) -> Self {
|
fn from(value: &'a MasterPass) -> Self {
|
||||||
HashedBytes {
|
HashedBytes {
|
||||||
hash: &value.password_hash,
|
hash: &value.password_hash,
|
||||||
|
@ -24,7 +24,6 @@ bitflags::bitflags! {
|
|||||||
|
|
||||||
/// Returns true if the generated master password is valid.
|
/// Returns true if the generated master password is valid.
|
||||||
/// It checks that it has at least one lowercase, one uppercase, one number and one punctuation char
|
/// It checks that it has at least one lowercase, one uppercase, one number and one punctuation char
|
||||||
#[inline]
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn check_generated_password<const LENGTH: usize>(password: &[u8; LENGTH]) -> bool {
|
fn check_generated_password<const LENGTH: usize>(password: &[u8; LENGTH]) -> bool {
|
||||||
let mut flags = PasswordFlags::empty();
|
let mut flags = PasswordFlags::empty();
|
||||||
@ -46,7 +45,6 @@ fn check_generated_password<const LENGTH: usize>(password: &[u8; LENGTH]) -> boo
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Continuously generates the password until it passes the checks
|
/// Continuously generates the password until it passes the checks
|
||||||
#[inline]
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn generate_password<R, const LENGTH: usize>(rng: &mut R) -> ArrayString<LENGTH>
|
fn generate_password<R, const LENGTH: usize>(rng: &mut R) -> ArrayString<LENGTH>
|
||||||
where
|
where
|
||||||
@ -60,7 +58,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[allow(clippy::module_name_repetitions)]
|
#[allow(clippy::module_name_repetitions)]
|
||||||
pub fn generate_passwords<const AMOUNT: usize, const LENGTH: usize>(
|
pub fn generate_passwords<const AMOUNT: usize, const LENGTH: usize>(
|
||||||
@ -69,7 +66,6 @@ pub fn generate_passwords<const AMOUNT: usize, const LENGTH: usize>(
|
|||||||
array::from_fn(|_| generate_password(&mut rng))
|
array::from_fn(|_| generate_password(&mut rng))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn check_master_pass(password: &str) -> PasswordValidity {
|
pub fn check_master_pass(password: &str) -> PasswordValidity {
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
/// Handles the messages which weren't matched by any commands or states
|
/// Handles the messages which weren't matched by any commands or states
|
||||||
#[inline]
|
|
||||||
pub async fn default(bot: Throttle<Bot>, msg: Message, locale: LocaleRef) -> crate::Result<()> {
|
pub async fn default(bot: Throttle<Bot>, msg: Message, locale: LocaleRef) -> crate::Result<()> {
|
||||||
bot.send_message(msg.chat.id, &locale.unknown_command_use_help)
|
bot.send_message(msg.chat.id, &locale.unknown_command_use_help)
|
||||||
.reply_markup(deletion_markup(locale))
|
.reply_markup(deletion_markup(locale))
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
/// Deletes the message without returning errors
|
/// Deletes the message without returning errors
|
||||||
#[inline]
|
|
||||||
pub async fn delete_message(bot: Throttle<Bot>, msg: Message) {
|
pub async fn delete_message(bot: Throttle<Bot>, msg: Message) {
|
||||||
let ids = MessageIds::from(&msg);
|
let ids = MessageIds::from(&msg);
|
||||||
if let Err(err) = ids.delete(&bot).await {
|
if let Err(err) = ids.delete(&bot).await {
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use teloxide::{dispatching::DpHandlerDescription, dptree::Handler};
|
use teloxide::{dispatching::DpHandlerDescription, dptree::Handler};
|
||||||
|
|
||||||
#[inline]
|
|
||||||
#[allow(clippy::needless_pass_by_value)]
|
#[allow(clippy::needless_pass_by_value)]
|
||||||
fn has_no_user_info(msg: Message) -> bool {
|
fn has_no_user_info(msg: Message) -> bool {
|
||||||
msg.from().is_none()
|
msg.from().is_none()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
async fn notify_about_no_user_info(
|
async fn notify_about_no_user_info(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
msg: Message,
|
msg: Message,
|
||||||
@ -48,7 +46,6 @@ async fn notify_about_no_user_info(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Gets a handler that filters out the messages without user information
|
/// Gets a handler that filters out the messages without user information
|
||||||
#[inline]
|
|
||||||
pub fn get_handler() -> Handler<'static, DependencyMap, crate::Result<()>, DpHandlerDescription> {
|
pub fn get_handler() -> Handler<'static, DependencyMap, crate::Result<()>, DpHandlerDescription> {
|
||||||
dptree::filter(has_no_user_info).endpoint(notify_about_no_user_info)
|
dptree::filter(has_no_user_info).endpoint(notify_about_no_user_info)
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ type DynError = Arc<dyn std::error::Error + Send + Sync>;
|
|||||||
///
|
///
|
||||||
/// Returns None if account exists, Some(None) if there's an account and Some(Some(DynError)) if an error occures.
|
/// Returns None if account exists, Some(None) if there's an account and Some(Some(DynError)) if an error occures.
|
||||||
/// The String represents the error that occured
|
/// The String represents the error that occured
|
||||||
#[inline]
|
|
||||||
async fn master_pass_exists(update: Update, db: Pool) -> Option<Option<DynError>> {
|
async fn master_pass_exists(update: Update, db: Pool) -> Option<Option<DynError>> {
|
||||||
let user_id = match update.user() {
|
let user_id = match update.user() {
|
||||||
Some(user) => user.id.0,
|
Some(user) => user.id.0,
|
||||||
@ -26,7 +25,6 @@ async fn master_pass_exists(update: Update, db: Pool) -> Option<Option<DynError>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
async fn notify_about_no_master_pass(
|
async fn notify_about_no_master_pass(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
locale: LocaleRef,
|
locale: LocaleRef,
|
||||||
@ -46,7 +44,6 @@ async fn notify_about_no_master_pass(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Gets a handler that filters out the messages of users that don't have a master password set
|
/// Gets a handler that filters out the messages of users that don't have a master password set
|
||||||
#[inline]
|
|
||||||
pub fn get_handler() -> Handler<'static, DependencyMap, crate::Result<()>, DpHandlerDescription> {
|
pub fn get_handler() -> Handler<'static, DependencyMap, crate::Result<()>, DpHandlerDescription> {
|
||||||
dptree::filter_map_async(master_pass_exists).endpoint(notify_about_no_master_pass)
|
dptree::filter_map_async(master_pass_exists).endpoint(notify_about_no_master_pass)
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ pub struct Account {
|
|||||||
|
|
||||||
impl Account {
|
impl Account {
|
||||||
// Inserts the account into DB
|
// Inserts the account into DB
|
||||||
#[inline]
|
|
||||||
pub async fn insert(&self, pool: &Pool) -> super::Result<()> {
|
pub async fn insert(&self, pool: &Pool) -> super::Result<()> {
|
||||||
query!(
|
query!(
|
||||||
"INSERT INTO account VALUES (?, ?, ?, ?, ?)",
|
"INSERT INTO account VALUES (?, ?, ?, ?, ?)",
|
||||||
@ -29,7 +28,6 @@ impl Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Gets all user's account from DB
|
/// Gets all user's account from DB
|
||||||
#[inline]
|
|
||||||
pub fn get_all(user_id: u64, pool: &Pool) -> impl Stream<Item = super::Result<Self>> + '_ {
|
pub fn get_all(user_id: u64, pool: &Pool) -> impl Stream<Item = super::Result<Self>> + '_ {
|
||||||
query_as("SELECT * FROM account WHERE user_id = ?")
|
query_as("SELECT * FROM account WHERE user_id = ?")
|
||||||
.bind(user_id)
|
.bind(user_id)
|
||||||
@ -37,7 +35,6 @@ impl Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Streams the names of the user accounts
|
/// Streams the names of the user accounts
|
||||||
#[inline]
|
|
||||||
pub fn get_names(user_id: u64, pool: &Pool) -> impl Stream<Item = super::Result<String>> + '_ {
|
pub fn get_names(user_id: u64, pool: &Pool) -> impl Stream<Item = super::Result<String>> + '_ {
|
||||||
query_as::<_, (String,)>("SELECT name FROM account WHERE user_id = ? ORDER BY name")
|
query_as::<_, (String,)>("SELECT name FROM account WHERE user_id = ? ORDER BY name")
|
||||||
.bind(user_id)
|
.bind(user_id)
|
||||||
@ -46,7 +43,6 @@ impl Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if the account exists
|
/// Checks if the account exists
|
||||||
#[inline]
|
|
||||||
pub async fn exists(user_id: u64, account_name: &str, pool: &Pool) -> super::Result<bool> {
|
pub async fn exists(user_id: u64, account_name: &str, pool: &Pool) -> super::Result<bool> {
|
||||||
query_as::<_, (bool,)>(
|
query_as::<_, (bool,)>(
|
||||||
"SELECT EXISTS(SELECT * FROM account WHERE user_id = ? AND name = ? LIMIT 1) as value",
|
"SELECT EXISTS(SELECT * FROM account WHERE user_id = ? AND name = ? LIMIT 1) as value",
|
||||||
@ -59,7 +55,6 @@ impl Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the account from the DB
|
/// Gets the account from the DB
|
||||||
#[inline]
|
|
||||||
pub async fn get(user_id: u64, account_name: &str, pool: &Pool) -> super::Result<Option<Self>> {
|
pub async fn get(user_id: u64, account_name: &str, pool: &Pool) -> super::Result<Option<Self>> {
|
||||||
query_as("SELECT * FROM account WHERE user_id = ? AND name = ?")
|
query_as("SELECT * FROM account WHERE user_id = ? AND name = ?")
|
||||||
.bind(user_id)
|
.bind(user_id)
|
||||||
@ -69,7 +64,6 @@ impl Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Deletes the account from DB
|
// Deletes the account from DB
|
||||||
#[inline]
|
|
||||||
pub async fn delete(user_id: u64, name: &str, pool: &Pool) -> super::Result<()> {
|
pub async fn delete(user_id: u64, name: &str, pool: &Pool) -> super::Result<()> {
|
||||||
query!(
|
query!(
|
||||||
"DELETE FROM account WHERE user_id = ? AND name = ?",
|
"DELETE FROM account WHERE user_id = ? AND name = ?",
|
||||||
@ -82,7 +76,6 @@ impl Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Deletes all the user's accounts from DB
|
/// Deletes all the user's accounts from DB
|
||||||
#[inline]
|
|
||||||
pub async fn delete_all(
|
pub async fn delete_all(
|
||||||
user_id: u64,
|
user_id: u64,
|
||||||
pool: impl Executor<'_, Database = MySql>,
|
pool: impl Executor<'_, Database = MySql>,
|
||||||
@ -94,7 +87,6 @@ impl Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Gets a name by a SHA256 hash of the name
|
/// Gets a name by a SHA256 hash of the name
|
||||||
#[inline]
|
|
||||||
pub async fn get_name_by_hash(
|
pub async fn get_name_by_hash(
|
||||||
user_id: u64,
|
user_id: u64,
|
||||||
hash: &[u8],
|
hash: &[u8],
|
||||||
@ -111,8 +103,6 @@ impl Account {
|
|||||||
|
|
||||||
Ok(name.map(|(name,)| name))
|
Ok(name.map(|(name,)| name))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub async fn get_salt(user_id: u64, name: &str, pool: &Pool) -> super::Result<Option<Vec<u8>>> {
|
pub async fn get_salt(user_id: u64, name: &str, pool: &Pool) -> super::Result<Option<Vec<u8>>> {
|
||||||
let salt =
|
let salt =
|
||||||
query_as::<_, (Vec<u8>,)>("SELECT salt FROM account WHERE user_id = ? AND name = ?")
|
query_as::<_, (Vec<u8>,)>("SELECT salt FROM account WHERE user_id = ? AND name = ?")
|
||||||
@ -123,8 +113,6 @@ impl Account {
|
|||||||
|
|
||||||
Ok(salt.map(|(salt,)| salt))
|
Ok(salt.map(|(salt,)| salt))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub async fn update_name(
|
pub async fn update_name(
|
||||||
user_id: u64,
|
user_id: u64,
|
||||||
original_name: &str,
|
original_name: &str,
|
||||||
@ -141,8 +129,6 @@ impl Account {
|
|||||||
.await
|
.await
|
||||||
.map(|result| result.rows_affected() != 0)
|
.map(|result| result.rows_affected() != 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub async fn update_login(
|
pub async fn update_login(
|
||||||
user_id: u64,
|
user_id: u64,
|
||||||
name: &str,
|
name: &str,
|
||||||
@ -159,8 +145,6 @@ impl Account {
|
|||||||
.await
|
.await
|
||||||
.map(|result| result.rows_affected() != 0)
|
.map(|result| result.rows_affected() != 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub async fn update_password(
|
pub async fn update_password(
|
||||||
user_id: u64,
|
user_id: u64,
|
||||||
name: &str,
|
name: &str,
|
||||||
|
@ -10,7 +10,6 @@ pub struct MasterPass {
|
|||||||
|
|
||||||
impl MasterPass {
|
impl MasterPass {
|
||||||
// Inserts the master password into DB
|
// Inserts the master password into DB
|
||||||
#[inline]
|
|
||||||
pub async fn insert(&self, pool: &Pool, locale: LocaleType) -> super::Result<()> {
|
pub async fn insert(&self, pool: &Pool, locale: LocaleType) -> super::Result<()> {
|
||||||
let locale: u8 = locale.into();
|
let locale: u8 = locale.into();
|
||||||
query!(
|
query!(
|
||||||
@ -26,7 +25,6 @@ impl MasterPass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the master password from the database
|
/// Gets the master password from the database
|
||||||
#[inline]
|
|
||||||
pub async fn get(user_id: u64, pool: &Pool) -> super::Result<Option<Self>> {
|
pub async fn get(user_id: u64, pool: &Pool) -> super::Result<Option<Self>> {
|
||||||
query_as("SELECT user_id, salt, password_hash FROM master_pass WHERE user_id = ?")
|
query_as("SELECT user_id, salt, password_hash FROM master_pass WHERE user_id = ?")
|
||||||
.bind(user_id)
|
.bind(user_id)
|
||||||
@ -35,7 +33,6 @@ impl MasterPass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if the master password for the user exists
|
/// Checks if the master password for the user exists
|
||||||
#[inline]
|
|
||||||
pub async fn exists(user_id: u64, pool: &Pool) -> super::Result<bool> {
|
pub async fn exists(user_id: u64, pool: &Pool) -> super::Result<bool> {
|
||||||
query_as::<_, (bool,)>(
|
query_as::<_, (bool,)>(
|
||||||
"SELECT EXISTS(SELECT * FROM master_pass WHERE user_id = ? LIMIT 1) as value",
|
"SELECT EXISTS(SELECT * FROM master_pass WHERE user_id = ? LIMIT 1) as value",
|
||||||
|
@ -21,7 +21,6 @@ pub enum InvalidCommand {
|
|||||||
UnknownLocale,
|
UnknownLocale,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn init_logger() {
|
pub fn init_logger() {
|
||||||
tracing_subscriber::registry()
|
tracing_subscriber::registry()
|
||||||
.with(fmt::layer().pretty())
|
.with(fmt::layer().pretty())
|
||||||
@ -32,7 +31,6 @@ pub fn init_logger() {
|
|||||||
/// Handles an error.
|
/// Handles an error.
|
||||||
/// This function must be as cheap and generic as possible and must remain sync.
|
/// This function must be as cheap and generic as possible and must remain sync.
|
||||||
/// If expensive or long action is required, a task should be spawned but not joined.
|
/// If expensive or long action is required, a task should be spawned but not joined.
|
||||||
#[inline]
|
|
||||||
pub fn handle_error<T>(error: T)
|
pub fn handle_error<T>(error: T)
|
||||||
where
|
where
|
||||||
T: Debug + Display,
|
T: Debug + Display,
|
||||||
@ -43,7 +41,6 @@ where
|
|||||||
pub struct ErrorHandler;
|
pub struct ErrorHandler;
|
||||||
|
|
||||||
impl teloxide::error_handlers::ErrorHandler<crate::Error> for ErrorHandler {
|
impl teloxide::error_handlers::ErrorHandler<crate::Error> for ErrorHandler {
|
||||||
#[inline]
|
|
||||||
fn handle_error(
|
fn handle_error(
|
||||||
self: std::sync::Arc<Self>,
|
self: std::sync::Arc<Self>,
|
||||||
error: crate::Error,
|
error: crate::Error,
|
||||||
|
@ -13,7 +13,6 @@ macro_rules! change_state {
|
|||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! first_handler {
|
macro_rules! first_handler {
|
||||||
($function_name: ident, $message: ident, $next_state: expr, $next_func: ident) => {
|
($function_name: ident, $message: ident, $next_state: expr, $next_func: ident) => {
|
||||||
#[inline]
|
|
||||||
pub async fn $function_name(
|
pub async fn $function_name(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
msg: Message,
|
msg: Message,
|
||||||
@ -33,7 +32,6 @@ macro_rules! first_handler {
|
|||||||
macro_rules! handler {
|
macro_rules! handler {
|
||||||
($function_name: ident ($($param: ident: $type: ty),*), $message: ident, $next_state: expr, $next_func: ident) => {
|
($function_name: ident ($($param: ident: $type: ty),*), $message: ident, $next_state: expr, $next_func: ident) => {
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
#[inline]
|
|
||||||
async fn $function_name(
|
async fn $function_name(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
_: Message,
|
_: Message,
|
||||||
@ -55,7 +53,6 @@ macro_rules! handler {
|
|||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! simple_state_handler {
|
macro_rules! simple_state_handler {
|
||||||
($function_name: ident, $check: ident) => {
|
($function_name: ident, $check: ident) => {
|
||||||
#[inline]
|
|
||||||
pub async fn $function_name(
|
pub async fn $function_name(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
msg: Message,
|
msg: Message,
|
||||||
|
@ -5,7 +5,6 @@ use sha2::{Digest, Sha256};
|
|||||||
use teloxide::types::{InlineKeyboardButton, InlineKeyboardMarkup};
|
use teloxide::types::{InlineKeyboardButton, InlineKeyboardMarkup};
|
||||||
use tokio::task::spawn_blocking;
|
use tokio::task::spawn_blocking;
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn menu_markup_sync(
|
pub fn menu_markup_sync(
|
||||||
command: &str,
|
command: &str,
|
||||||
names: impl IntoIterator<Item = String>,
|
names: impl IntoIterator<Item = String>,
|
||||||
@ -25,7 +24,6 @@ pub fn menu_markup_sync(
|
|||||||
InlineKeyboardMarkup::new(&names)
|
InlineKeyboardMarkup::new(&names)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub async fn menu_markup(
|
pub async fn menu_markup(
|
||||||
command: impl Into<String> + Send,
|
command: impl Into<String> + Send,
|
||||||
user_id: u64,
|
user_id: u64,
|
||||||
@ -39,7 +37,6 @@ pub async fn menu_markup(
|
|||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn make_button(text: &str, command: &str, param: &str) -> InlineKeyboardButton {
|
fn make_button(text: &str, command: &str, param: &str) -> InlineKeyboardButton {
|
||||||
let mut data = command.to_owned();
|
let mut data = command.to_owned();
|
||||||
data.reserve(param.len() + 1);
|
data.reserve(param.len() + 1);
|
||||||
@ -48,7 +45,6 @@ fn make_button(text: &str, command: &str, param: &str) -> InlineKeyboardButton {
|
|||||||
InlineKeyboardButton::callback(text, data)
|
InlineKeyboardButton::callback(text, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn account_markup(name: &str, is_encrypted: bool, locale: LocaleRef) -> InlineKeyboardMarkup {
|
pub fn account_markup(name: &str, is_encrypted: bool, locale: LocaleRef) -> InlineKeyboardMarkup {
|
||||||
let mut hash = [0; 43];
|
let mut hash = [0; 43];
|
||||||
B64_ENGINE
|
B64_ENGINE
|
||||||
@ -78,7 +74,6 @@ pub fn account_markup(name: &str, is_encrypted: bool, locale: LocaleRef) -> Inli
|
|||||||
InlineKeyboardMarkup::new(&main_buttons).append_row([menu_button])
|
InlineKeyboardMarkup::new(&main_buttons).append_row([menu_button])
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn language_markup() -> InlineKeyboardMarkup {
|
pub fn language_markup() -> InlineKeyboardMarkup {
|
||||||
let languages = [("🇷🇺 Русский", "ru"), ("🇬🇧 English", "en")]
|
let languages = [("🇷🇺 Русский", "ru"), ("🇬🇧 English", "en")]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -89,7 +84,6 @@ pub fn language_markup() -> InlineKeyboardMarkup {
|
|||||||
|
|
||||||
/// Creates a markup with a "Delete message" button.
|
/// Creates a markup with a "Delete message" button.
|
||||||
/// This markup should be added for all messages that won't be deleted afterwards
|
/// This markup should be added for all messages that won't be deleted afterwards
|
||||||
#[inline]
|
|
||||||
pub fn deletion_markup(locale: LocaleRef) -> InlineKeyboardMarkup {
|
pub fn deletion_markup(locale: LocaleRef) -> InlineKeyboardMarkup {
|
||||||
let button = InlineKeyboardButton::callback(&locale.delete_message_button, "delete_message");
|
let button = InlineKeyboardButton::callback(&locale.delete_message_button, "delete_message");
|
||||||
InlineKeyboardMarkup::new([[button]])
|
InlineKeyboardMarkup::new([[button]])
|
||||||
|
@ -2,7 +2,6 @@ use crate::{errors::HandlerUsed, prelude::*};
|
|||||||
use futures::future::BoxFuture;
|
use futures::future::BoxFuture;
|
||||||
|
|
||||||
/// A generic state handler. It checks for "/cancel" messages and runs the provided validation function
|
/// A generic state handler. It checks for "/cancel" messages and runs the provided validation function
|
||||||
#[inline]
|
|
||||||
pub async fn generic<F>(
|
pub async fn generic<F>(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
msg: Message,
|
msg: Message,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
#[inline]
|
|
||||||
async fn check_login(
|
async fn check_login(
|
||||||
_: &Message,
|
_: &Message,
|
||||||
_: &Pool,
|
_: &Pool,
|
||||||
|
@ -2,7 +2,6 @@ use crate::{cryptography::hashing::HashedBytes, prelude::*};
|
|||||||
use tokio::task::spawn_blocking;
|
use tokio::task::spawn_blocking;
|
||||||
|
|
||||||
/// Returns true if the provided master password is valid
|
/// Returns true if the provided master password is valid
|
||||||
#[inline]
|
|
||||||
async fn check_master_pass(
|
async fn check_master_pass(
|
||||||
msg: &Message,
|
msg: &Message,
|
||||||
db: &Pool,
|
db: &Pool,
|
||||||
|
@ -4,7 +4,6 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use std::fmt::Write as _;
|
use std::fmt::Write as _;
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn process_validity(validity: PasswordValidity, locale: LocaleRef) -> Result<(), String> {
|
fn process_validity(validity: PasswordValidity, locale: LocaleRef) -> Result<(), String> {
|
||||||
if validity.is_empty() {
|
if validity.is_empty() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@ -39,7 +38,6 @@ fn process_validity(validity: PasswordValidity, locale: LocaleRef) -> Result<(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Checks that the account with that name exists
|
/// Checks that the account with that name exists
|
||||||
#[inline]
|
|
||||||
async fn check_new_master_pass(
|
async fn check_new_master_pass(
|
||||||
_: &Message,
|
_: &Message,
|
||||||
_: &Pool,
|
_: &Pool,
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
/// Validates a new account
|
/// Validates a new account
|
||||||
#[inline]
|
|
||||||
async fn check_new_account_name(
|
async fn check_new_account_name(
|
||||||
msg: &Message,
|
msg: &Message,
|
||||||
db: &Pool,
|
db: &Pool,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
#[inline]
|
|
||||||
async fn check_password(
|
async fn check_password(
|
||||||
_: &Message,
|
_: &Message,
|
||||||
_: &Pool,
|
_: &Pool,
|
||||||
|
@ -28,7 +28,6 @@ impl InvalidDocument {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn validate_document(document: Option<&Document>) -> Result<&Document, InvalidDocument> {
|
fn validate_document(document: Option<&Document>) -> Result<&Document, InvalidDocument> {
|
||||||
let Some(document) = document else {
|
let Some(document) = document else {
|
||||||
return Err(InvalidDocument::NoFileSend);
|
return Err(InvalidDocument::NoFileSend);
|
||||||
@ -49,7 +48,6 @@ fn validate_document(document: Option<&Document>) -> Result<&Document, InvalidDo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
async fn download_file(bot: &Throttle<Bot>, file: &FileMeta) -> crate::Result<Box<[u8]>> {
|
async fn download_file(bot: &Throttle<Bot>, file: &FileMeta) -> crate::Result<Box<[u8]>> {
|
||||||
let path = bot.get_file(&file.id).await?.path;
|
let path = bot.get_file(&file.id).await?.path;
|
||||||
let mut data = Vec::with_capacity(file.size as usize);
|
let mut data = Vec::with_capacity(file.size as usize);
|
||||||
@ -60,7 +58,6 @@ async fn download_file(bot: &Throttle<Bot>, file: &FileMeta) -> crate::Result<Bo
|
|||||||
Ok(data.into_boxed_slice())
|
Ok(data.into_boxed_slice())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn process_accounts(
|
fn process_accounts(
|
||||||
accounts: &mut [DecryptedAccount],
|
accounts: &mut [DecryptedAccount],
|
||||||
existing_names: ahash::HashSet<String>,
|
existing_names: ahash::HashSet<String>,
|
||||||
@ -136,7 +133,6 @@ fn process_accounts(
|
|||||||
Ok(Err(error_text))
|
Ok(Err(error_text))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn user_from_bytes(
|
fn user_from_bytes(
|
||||||
bytes: impl AsRef<[u8]>,
|
bytes: impl AsRef<[u8]>,
|
||||||
existing_names: ahash::HashSet<String>,
|
existing_names: ahash::HashSet<String>,
|
||||||
@ -150,7 +146,6 @@ fn user_from_bytes(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
async fn user_from_document(
|
async fn user_from_document(
|
||||||
bot: &Throttle<Bot>,
|
bot: &Throttle<Bot>,
|
||||||
db: &Pool,
|
db: &Pool,
|
||||||
@ -178,7 +173,6 @@ async fn user_from_document(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Function to handle `GetUser` state. It doesn't actually validate anything
|
/// Function to handle `GetUser` state. It doesn't actually validate anything
|
||||||
#[inline]
|
|
||||||
pub async fn get_user(
|
pub async fn get_user(
|
||||||
bot: Throttle<Bot>,
|
bot: Throttle<Bot>,
|
||||||
msg: Message,
|
msg: Message,
|
||||||
|
@ -13,7 +13,6 @@ pub struct MessageIds(pub ChatId, pub MessageId);
|
|||||||
|
|
||||||
impl MessageIds {
|
impl MessageIds {
|
||||||
// Tries to delete the message while ignoring API errors
|
// Tries to delete the message while ignoring API errors
|
||||||
#[inline]
|
|
||||||
pub async fn delete(self, bot: &Throttle<Bot>) -> Result<(), RequestError> {
|
pub async fn delete(self, bot: &Throttle<Bot>) -> Result<(), RequestError> {
|
||||||
match bot.delete_message(self.0, self.1).await {
|
match bot.delete_message(self.0, self.1).await {
|
||||||
Ok(_) | Err(RequestError::Api(_)) => Ok(()),
|
Ok(_) | Err(RequestError::Api(_)) => Ok(()),
|
||||||
@ -22,7 +21,6 @@ impl MessageIds {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Tries to alter the message or sends a new one
|
/// Tries to alter the message or sends a new one
|
||||||
#[inline]
|
|
||||||
pub async fn alter_message(
|
pub async fn alter_message(
|
||||||
&mut self,
|
&mut self,
|
||||||
bot: &Throttle<Bot>,
|
bot: &Throttle<Bot>,
|
||||||
@ -55,7 +53,6 @@ impl MessageIds {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl From<&Message> for MessageIds {
|
impl From<&Message> for MessageIds {
|
||||||
#[inline]
|
|
||||||
fn from(value: &Message) -> Self {
|
fn from(value: &Message) -> Self {
|
||||||
Self(value.chat.id, value.id)
|
Self(value.chat.id, value.id)
|
||||||
}
|
}
|
||||||
@ -84,7 +81,6 @@ pub type Packaged<T> = Arc<Mutex<Handler<T>>>;
|
|||||||
|
|
||||||
impl<T> Handler<T> {
|
impl<T> Handler<T> {
|
||||||
/// Convinience method to convert a simple async function and a previous message into `PackagedHandler`
|
/// Convinience method to convert a simple async function and a previous message into `PackagedHandler`
|
||||||
#[inline]
|
|
||||||
pub fn new<H>(f: H, previous: impl Into<MessageIds>) -> PackagedHandler<T>
|
pub fn new<H>(f: H, previous: impl Into<MessageIds>) -> PackagedHandler<T>
|
||||||
where
|
where
|
||||||
H: FnOnce(
|
H: FnOnce(
|
||||||
|
Loading…
Reference in New Issue
Block a user