Implemented account altering
This commit is contained in:
		@@ -5,14 +5,14 @@ use rand::{rngs::OsRng, RngCore};
 | 
			
		||||
use sea_orm::ActiveValue::Set;
 | 
			
		||||
use sha2::Sha256;
 | 
			
		||||
 | 
			
		||||
struct Cipher {
 | 
			
		||||
pub struct Cipher {
 | 
			
		||||
    chacha: ChaCha20Poly1305,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Cipher {
 | 
			
		||||
    /// Creates a new cipher from a master password and the salt
 | 
			
		||||
    #[inline]
 | 
			
		||||
    fn new(password: &[u8], salt: &[u8]) -> Self {
 | 
			
		||||
    pub fn new(password: &[u8], salt: &[u8]) -> Self {
 | 
			
		||||
        let key = pbkdf2_hmac_array::<Sha256, 32>(password, salt, 480000);
 | 
			
		||||
 | 
			
		||||
        Self {
 | 
			
		||||
@@ -31,7 +31,7 @@ impl Cipher {
 | 
			
		||||
 | 
			
		||||
    /// Decrypts the value with the current cipher. The 12 byte nonce is expected to be at the end of the value
 | 
			
		||||
    #[inline]
 | 
			
		||||
    fn decrypt(&self, value: &[u8]) -> crate::Result<Vec<u8>> {
 | 
			
		||||
    pub fn decrypt(&self, value: &[u8]) -> crate::Result<Vec<u8>> {
 | 
			
		||||
        let (data, nonce) = value.split_at(value.len() - 12);
 | 
			
		||||
        self.chacha.decrypt(nonce.into(), data).map_err(Into::into)
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user