docs: documentation for encryption functions (#3243)

This commit is contained in:
Nathan.fooo
2023-08-20 15:38:52 +08:00
committed by GitHub
parent a1647bee78
commit 30155924a9
6 changed files with 86 additions and 32 deletions

View File

@ -1,6 +1,6 @@
use std::sync::Arc;
use flowy_encrypt::generate_encrypt_secret;
use flowy_encrypt::generate_encryption_secret;
use flowy_error::FlowyResult;
use flowy_sqlite::kv::StorePreferences;
use flowy_user_deps::cloud::UserCloudConfig;
@ -8,7 +8,7 @@ use flowy_user_deps::cloud::UserCloudConfig;
const CLOUD_CONFIG_KEY: &str = "af_user_cloud_config";
fn generate_cloud_config(uid: i64, store_preference: &Arc<StorePreferences>) -> UserCloudConfig {
let config = UserCloudConfig::new(generate_encrypt_secret());
let config = UserCloudConfig::new(generate_encryption_secret());
let key = cache_key_for_cloud_config(uid);
store_preference.set_object(&key, config.clone()).unwrap();
config

View File

@ -1,4 +1,4 @@
use flowy_encrypt::{decrypt_string, encrypt_string};
use flowy_encrypt::{decrypt_text, encrypt_text};
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
use flowy_user_deps::entities::{EncryptionType, UpdateUserProfileParams, UserCredentials};
@ -24,7 +24,7 @@ impl UserManager {
}
pub fn generate_encryption_sign(&self, uid: i64, encrypt_secret: &str) -> FlowyResult<String> {
let encrypt_sign = encrypt_string(uid.to_string(), encrypt_secret)?;
let encrypt_sign = encrypt_text(uid.to_string(), encrypt_secret)?;
Ok(encrypt_sign)
}
@ -51,7 +51,7 @@ impl UserManager {
encrypt_sign: &str,
encryption_secret: &str,
) -> FlowyResult<()> {
let decrypt_str = decrypt_string(encrypt_sign, encryption_secret)
let decrypt_str = decrypt_text(encrypt_sign, encryption_secret)
.map_err(|_| FlowyError::new(ErrorCode::InvalidEncryptSecret, "Invalid decryption secret"))?;
if uid.to_string() == decrypt_str {
Ok(())