• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "inputer_data_impl.h"
17 
18 #include <cstddef>
19 #include <vector>
20 
21 #include "iam_logger.h"
22 #include "iam_ptr.h"
23 #include "scrypt.h"
24 
25 #define LOG_LABEL OHOS::UserIam::Common::LABEL_PIN_AUTH_SDK
26 
27 namespace OHOS {
28 namespace UserIam {
29 namespace PinAuth {
InputerDataImpl(const std::vector<uint8_t> & salt,const sptr<InputerSetData> & inputerSetData)30 InputerDataImpl::InputerDataImpl(const std::vector<uint8_t> &salt, const sptr<InputerSetData> &inputerSetData)
31     : salt_(salt), inputerSetData_(inputerSetData)
32 {
33 }
34 
OnSetData(int32_t authSubType,std::vector<uint8_t> data)35 void InputerDataImpl::OnSetData(int32_t authSubType, std::vector<uint8_t> data)
36 {
37     IAM_LOGI("start and data size is %{public}zu", data.size());
38     std::vector<uint8_t> scrypt;
39     if (data.size() == 0) {
40         IAM_LOGE("data size is 0");
41         return OnSetDataInner(authSubType, scrypt);
42     }
43     auto scryptPointer = Common::MakeUnique<Scrypt>(salt_);
44     if (scryptPointer == nullptr) {
45         IAM_LOGE("scryptPointer is nullptr");
46         return OnSetDataInner(authSubType, scrypt);
47     }
48     scrypt = scryptPointer->GetScrypt(data);
49     if (scrypt.empty()) {
50         IAM_LOGE("get scrypt fail");
51     }
52     return OnSetDataInner(authSubType, scrypt);
53 }
54 
OnSetDataInner(int32_t authSubType,std::vector<uint8_t> & scrypt)55 void InputerDataImpl::OnSetDataInner(int32_t authSubType, std::vector<uint8_t> &scrypt)
56 {
57     if (inputerSetData_ == nullptr) {
58         IAM_LOGE("inputerSetData is nullptr");
59         return;
60     }
61     inputerSetData_->OnSetData(authSubType, scrypt);
62 }
63 } // namespace PinAuth
64 } // namespace UserIam
65 } // namespace OHOS
66