mirror of
https://gitee.com/openharmony/useriam_user_auth_framework
synced 2024-11-27 01:40:49 +00:00
fix code
Signed-off-by: liuziwei <liuziwei12@huawei.com>
This commit is contained in:
parent
d90312d443
commit
450e4c57ed
@ -45,6 +45,7 @@ public:
|
||||
bool SetUint16Value(AttributeKey key, uint16_t value);
|
||||
bool SetUint8Value(AttributeKey key, uint8_t value);
|
||||
bool SetInt32Value(AttributeKey key, int32_t value);
|
||||
bool SetInt64Value(AttributeKey key, int64_t value);
|
||||
bool SetStringValue(AttributeKey key, const std::string &value);
|
||||
bool SetAttributesValue(AttributeKey key, const Impl &value);
|
||||
bool SetUint64ArrayValue(AttributeKey key, const std::vector<uint64_t> &value);
|
||||
@ -58,6 +59,7 @@ public:
|
||||
bool GetUint16Value(AttributeKey key, uint16_t &value) const;
|
||||
bool GetUint8Value(AttributeKey key, uint8_t &value) const;
|
||||
bool GetInt32Value(AttributeKey key, int32_t &value) const;
|
||||
bool GetInt64Value(AttributeKey key, int64_t &value) const;
|
||||
bool GetStringValue(AttributeKey key, std::string &value) const;
|
||||
bool GetUint64ArrayValue(AttributeKey key, std::vector<uint64_t> &value) const;
|
||||
bool GetUint32ArrayValue(AttributeKey key, std::vector<uint32_t> &value) const;
|
||||
@ -282,6 +284,23 @@ bool Attributes::Impl::SetInt32Value(AttributeKey key, int32_t value)
|
||||
return ret.second;
|
||||
}
|
||||
|
||||
bool Attributes::Impl::SetInt64Value(AttributeKey key, int64_t value)
|
||||
{
|
||||
std::vector<uint8_t> dest;
|
||||
if (!EncodeInt64Value(value, dest)) {
|
||||
IAM_LOGE("EncodeInt32Value error");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (map_.size() > MAX_ATTR_COUNT) {
|
||||
IAM_LOGE("attrs size reach max");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto ret = map_.try_emplace(key, dest);
|
||||
return ret.second;
|
||||
}
|
||||
|
||||
bool Attributes::Impl::SetStringValue(AttributeKey key, const std::string &value)
|
||||
{
|
||||
std::vector<uint8_t> dest;
|
||||
@ -473,6 +492,21 @@ bool Attributes::Impl::GetInt32Value(AttributeKey key, int32_t &value) const
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Attributes::Impl::GetInt64Value(AttributeKey key, int32_t &value) const
|
||||
{
|
||||
auto iter = map_.find(key);
|
||||
if (iter == map_.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!DecodeInt64Value(iter->second, value)) {
|
||||
IAM_LOGE("DecodeInt32Value error");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Attributes::Impl::GetStringValue(AttributeKey key, std::string &value) const
|
||||
{
|
||||
auto iter = map_.find(key);
|
||||
@ -656,6 +690,16 @@ bool Attributes::Impl::EncodeInt32Value(int32_t src, std::vector<uint8_t> &dst)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Attributes::Impl::EncodeInt64Value(int64_t src, std::vector<uint8_t> &dst)
|
||||
{
|
||||
std::vector<uint8_t> out(sizeof(int64_t) / sizeof(uint8_t));
|
||||
if (memcpy_s(out.data(), out.size(), &src, sizeof(src)) != EOK) {
|
||||
return false;
|
||||
}
|
||||
dst.swap(out);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Attributes::Impl::EncodeStringValue(const std::string &src, std::vector<uint8_t> &dst)
|
||||
{
|
||||
if (src.size() > MAX_ATTR_LENGTH) {
|
||||
@ -794,6 +838,17 @@ bool Attributes::Impl::DecodeInt32Value(const std::vector<uint8_t> &src, int32_t
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Attributes::Impl::DecodeInt64Value(const std::vector<uint8_t> &src, int64_t &dst)
|
||||
{
|
||||
if (src.size() * sizeof(uint8_t) != sizeof(int64_t)) {
|
||||
return false;
|
||||
}
|
||||
if (memcpy_s(&dst, sizeof(dst), src.data(), src.size() * sizeof(uint8_t)) != EOK) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Attributes::Impl::DecodeStringValue(const std::vector<uint8_t> &src, std::string &dst)
|
||||
{
|
||||
if (src.empty()) {
|
||||
@ -939,6 +994,14 @@ bool Attributes::SetInt32Value(AttributeKey key, int32_t value)
|
||||
return impl_->SetInt32Value(key, value);
|
||||
}
|
||||
|
||||
bool Attributes::SetInt64Value(AttributeKey key, int64_t value)
|
||||
{
|
||||
if (!impl_) {
|
||||
return false;
|
||||
}
|
||||
return impl_->SetInt64Value(key, value);
|
||||
}
|
||||
|
||||
bool Attributes::SetStringValue(AttributeKey key, const std::string &value)
|
||||
{
|
||||
if (!impl_) {
|
||||
@ -1035,6 +1098,14 @@ bool Attributes::GetInt32Value(AttributeKey key, int32_t &value) const
|
||||
return impl_->GetInt32Value(key, value);
|
||||
}
|
||||
|
||||
bool Attributes::GetInt64Value(AttributeKey key, int32_t &value) const
|
||||
{
|
||||
if (!impl_) {
|
||||
return false;
|
||||
}
|
||||
return impl_->GetInt64Value(key, value);
|
||||
}
|
||||
|
||||
bool Attributes::GetStringValue(AttributeKey key, std::string &value) const
|
||||
{
|
||||
if (!impl_) {
|
||||
|
@ -661,7 +661,7 @@ int32_t UserAuthProxy::SetGlobalConfigParam(const GlobalConfigParam ¶m)
|
||||
}
|
||||
if (param.type == GlobalConfigType::PIN_EXPIRED_PERIOD) {
|
||||
IAM_LOGI("GlobalConfigType is pin expired period");
|
||||
if (!data.WriteUint64(param.value.pinExpiredPeriod)) {
|
||||
if (!data.Writeint64(param.value.pinExpiredPeriod)) {
|
||||
IAM_LOGE("failed to write GlobalConfigParam pinExpiredPeriod");
|
||||
return WRITE_PARCEL_ERROR;
|
||||
}
|
||||
|
@ -618,7 +618,7 @@ int32_t UserAuthStub::SetGlobalConfigParamStub(MessageParcel &data, MessageParce
|
||||
globalConfigParam.type = static_cast<GlobalConfigType>(globalConfigType);
|
||||
|
||||
if (globalConfigParam.type == GlobalConfigType::PIN_EXPIRED_PERIOD) {
|
||||
if (!data.ReadUint64(globalConfigParam.value.pinExpiredPeriod)) {
|
||||
if (!data.Readint64(globalConfigParam.value.pinExpiredPeriod)) {
|
||||
IAM_LOGE("failed to read pinExpiredPeriod");
|
||||
return READ_PARCEL_ERROR;
|
||||
}
|
||||
|
@ -233,6 +233,15 @@ public:
|
||||
*/
|
||||
bool SetInt32Value(AttributeKey key, int32_t value);
|
||||
|
||||
/**
|
||||
* @brief Set int64_t value.
|
||||
*
|
||||
* @param key The attribute key.
|
||||
* @param value The int64_t value.
|
||||
* @return Return success or not(true:success; false:failed).
|
||||
*/
|
||||
bool SetInt64Value(AttributeKey key, int32_t value);
|
||||
|
||||
/**
|
||||
* @brief Set string value.
|
||||
*
|
||||
@ -341,6 +350,15 @@ public:
|
||||
*/
|
||||
bool GetInt32Value(AttributeKey key, int32_t &value) const;
|
||||
|
||||
/**
|
||||
* @brief Get int64_t value.
|
||||
*
|
||||
* @param key The attribute key.
|
||||
* @param value Return int64_t value corresponding to key.
|
||||
* @return Return success or not(true:success; false:failed).
|
||||
*/
|
||||
bool GetInt64Value(AttributeKey key, int32_t &value) const;
|
||||
|
||||
/**
|
||||
* @brief Get string value.
|
||||
*
|
||||
|
@ -30,8 +30,6 @@
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
/** Invalid pin expired period. */
|
||||
constexpr size_t INVALID_PIN_EXPIRED_PERIOD = 0;
|
||||
/**
|
||||
* @brief Executor property needed to get.
|
||||
*/
|
||||
@ -66,9 +64,9 @@ enum GlobalConfigType : int32_t {
|
||||
* @brief Global config value.
|
||||
*/
|
||||
union GlobalConfigValue {
|
||||
/** Global config value of pin expired period. When pinExpiredPeriod equals to INVALID_PIN_EXPIRED_PERIOD,
|
||||
/** Global config value of pin expired period. When pinExpiredPeriod <= 0,
|
||||
* userAuth won't check pin expired period */
|
||||
uint64_t pinExpiredPeriod;
|
||||
int64_t pinExpiredPeriod;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -103,7 +103,7 @@ private:
|
||||
AuthType authType { 0 };
|
||||
uint64_t credentialDigest;
|
||||
uint16_t credentialCount;
|
||||
int32_t pinExpiredInfo;
|
||||
int64_t pinExpiredInfo;
|
||||
};
|
||||
|
||||
uint64_t contextId_ {0};
|
||||
|
@ -183,7 +183,7 @@ void SimpleAuthContext::InvokeResultCallback(const Authentication::AuthResultInf
|
||||
Attributes finalResult;
|
||||
bool setResultCodeRet = finalResult.SetInt32Value(Attributes::ATTR_RESULT_CODE, resultInfo.result);
|
||||
IF_FALSE_LOGE_AND_RETURN(setResultCodeRet == true);
|
||||
setResultCodeRet = finalResult.SetInt32Value(Attributes::ATTR_PIN_EXPIRED_INFO, resultInfo.pinExpiredInfo);
|
||||
setResultCodeRet = finalResult.SetInt64Value(Attributes::ATTR_PIN_EXPIRED_INFO, resultInfo.pinExpiredInfo);
|
||||
IF_FALSE_LOGE_AND_RETURN(setResultCodeRet == true);
|
||||
if (resultInfo.result == SUCCESS || NeedSetFreezingTimeAndRemainTimes(resultInfo.result)) {
|
||||
bool setFreezingTimeRet = finalResult.SetInt32Value(Attributes::ATTR_FREEZING_TIME, resultInfo.freezingTime);
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
uint16_t credentialCount{0};
|
||||
int32_t sdkVersion{0};
|
||||
int32_t userId;
|
||||
int32_t pinExpiredInfo;
|
||||
int64_t pinExpiredInfo;
|
||||
};
|
||||
struct AuthExecutorMsg {
|
||||
uint64_t executorIndex;
|
||||
|
Loading…
Reference in New Issue
Block a user