mirror of
https://gitee.com/openharmony/security_asset
synced 2024-11-23 07:49:41 +00:00
catch exist error in get_existing_key_alias instead of return it to the caller
Signed-off-by: Cai Xincheng <caixincheng@huawei.com> Change-Id: I2221ae8ae7482b9529c1b2584045d9eb972445c7
This commit is contained in:
parent
a8e8e23053
commit
35f3cc43cd
@ -86,48 +86,57 @@ fn get_existing_key_alias(
|
||||
auth_type: AuthType,
|
||||
access_type: Accessibility,
|
||||
require_password_set: bool,
|
||||
) -> Result<KeyAliasVersion> {
|
||||
) -> KeyAliasVersion {
|
||||
let new_alias = calculate_key_alias(calling_info, auth_type, access_type, require_password_set, true);
|
||||
let prefixed_new_alias = [ALIAS_PREFIX.to_vec(), new_alias.clone()].concat();
|
||||
let key = SecretKey {
|
||||
let ret = SecretKey {
|
||||
user_id: calling_info.user_id(),
|
||||
auth_type,
|
||||
access_type,
|
||||
require_password_set,
|
||||
alias: prefixed_new_alias.clone(),
|
||||
};
|
||||
if key.exists()? {
|
||||
logi!("[INFO][{access_type}]-typed secret key with version 3 alias exists.");
|
||||
return Ok(KeyAliasVersion::V3);
|
||||
}
|
||||
.exists();
|
||||
if let Ok(true) = ret {
|
||||
logi!("[INFO][{access_type}]-typed secret key with v3 alias exists.");
|
||||
return KeyAliasVersion::V3;
|
||||
} else if let Err(e) = ret {
|
||||
loge!("[Fatal]Can not determine whether [{access_type}]-typed secret key with v3 alias exists. err is {e}.");
|
||||
}
|
||||
|
||||
let key = SecretKey {
|
||||
let ret = SecretKey {
|
||||
user_id: calling_info.user_id(),
|
||||
auth_type,
|
||||
access_type,
|
||||
require_password_set,
|
||||
alias: new_alias.clone(),
|
||||
};
|
||||
if key.exists()? {
|
||||
logi!("[INFO][{access_type}]-typed secret key with version 2 alias exists.");
|
||||
return Ok(KeyAliasVersion::V2(new_alias));
|
||||
}
|
||||
.exists();
|
||||
if let Ok(true) = ret {
|
||||
logi!("[INFO][{access_type}]-typed secret key with v2 alias exists.");
|
||||
return KeyAliasVersion::V2(new_alias);
|
||||
} else if let Err(e) = ret {
|
||||
loge!("[Fatal]Can not determine whether [{access_type}]-typed secret key with v2 alias exists. err is {e}.");
|
||||
}
|
||||
|
||||
let old_alias = calculate_key_alias(calling_info, auth_type, access_type, require_password_set, false);
|
||||
let key = SecretKey {
|
||||
let ret = SecretKey {
|
||||
user_id: calling_info.user_id(),
|
||||
auth_type,
|
||||
access_type,
|
||||
require_password_set,
|
||||
alias: old_alias.clone(),
|
||||
};
|
||||
if key.exists()? {
|
||||
logi!("[INFO][{access_type}]-typed secret key with version 1 alias exists.");
|
||||
return Ok(KeyAliasVersion::V1(old_alias));
|
||||
}
|
||||
.exists();
|
||||
if let Ok(true) = ret {
|
||||
logi!("[INFO][{access_type}]-typed secret key with v1 alias exists.");
|
||||
return KeyAliasVersion::V1(old_alias);
|
||||
} else if let Err(e) = ret {
|
||||
loge!("[Fatal]Can not determine whether [{access_type}]-typed secret key with v1 alias exists. err is {e}.");
|
||||
}
|
||||
|
||||
loge!("[INFO][{access_type}]-typed secret key does not exist.");
|
||||
Ok(KeyAliasVersion::None)
|
||||
KeyAliasVersion::None
|
||||
}
|
||||
|
||||
fn huks_rename_key_alias(
|
||||
@ -159,7 +168,7 @@ pub fn rename_key_alias(
|
||||
access_type: Accessibility,
|
||||
require_password_set: bool,
|
||||
) -> Result<bool> {
|
||||
match get_existing_key_alias(calling_info, auth_type, access_type, require_password_set)? {
|
||||
match get_existing_key_alias(calling_info, auth_type, access_type, require_password_set) {
|
||||
KeyAliasVersion::V3 => {
|
||||
logi!("[INFO]Alias of [{access_type}]-typed secret key has already been renamed successfully.");
|
||||
Ok(true)
|
||||
|
@ -25,8 +25,8 @@ use asset_log::logi;
|
||||
|
||||
use crate::{
|
||||
database::{
|
||||
fmt_backup_path, fmt_de_db_path_with_name, get_db, get_split_db_lock_by_user_id, Database, DE_ROOT_PATH,
|
||||
CE_ROOT_PATH, OLD_DB_NAME,
|
||||
fmt_backup_path, fmt_de_db_path_with_name, get_db, get_split_db_lock_by_user_id, Database, CE_ROOT_PATH,
|
||||
DE_ROOT_PATH, OLD_DB_NAME,
|
||||
},
|
||||
types::{column, DbMap, QueryOptions, DB_UPGRADE_VERSION, DB_UPGRADE_VERSION_V3},
|
||||
};
|
||||
|
@ -26,7 +26,9 @@ use crate::{
|
||||
database::Database,
|
||||
statement::Statement,
|
||||
transaction::Transaction,
|
||||
types::{ColumnInfo, DbMap, QueryOptions, UpgradeColumnInfo, DB_UPGRADE_VERSION, DB_UPGRADE_VERSION_V3, SQLITE_ROW},
|
||||
types::{
|
||||
ColumnInfo, DbMap, QueryOptions, UpgradeColumnInfo, DB_UPGRADE_VERSION, DB_UPGRADE_VERSION_V3, SQLITE_ROW,
|
||||
},
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
|
Loading…
Reference in New Issue
Block a user