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 auto scryptPointer = Common::MakeUnique<Scrypt>(salt_);
39 if (scryptPointer == nullptr) {
40 IAM_LOGE("scryptPointer is nullptr");
41 return;
42 }
43
44 std::vector<uint8_t> scrypt = scryptPointer->GetScrypt(data);
45 if (scrypt.empty()) {
46 IAM_LOGE("get scrypt fail");
47 return;
48 }
49
50 if (inputerSetData_ == nullptr) {
51 IAM_LOGE("inputerSetData is nullptr");
52 return;
53 }
54 inputerSetData_->OnSetData(authSubType, scrypt);
55 }
56 } // namespace PinAuth
57 } // namespace UserIam
58 } // namespace OHOS
59