~aleteoryx/muditaos

ref: 5badad2b087c956e38c546a66cba16cb31f72e84 muditaos/module-apps/application-settings-new/widgets/ChangePasscodeLockHandler.cpp -rw-r--r-- 2.1 KiB
5badad2b — Krzysztof Móżdżyński [EGD-5443] Onboarding date and time window 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "ChangePasscodeLockHandler.hpp"
#include "application-desktop/widgets/PinHash.hpp"

namespace gui
{
    ChangePasscodeLockHandler::ChangePasscodeLockHandler()
        : lock(Store::GSM::SIM::NONE, PinLock::LockState::PasscodeRequired, PinLock::LockType::Screen)
    {}

    PinLock::LockState ChangePasscodeLockHandler::checkPasscode(unsigned int currentLockPassHash)
    {
        return activateLock([this, currentLockPassHash](PinLock::LockType, const std::vector<unsigned int> &pin) {
            const auto hash = GetPinHash(pin);
            if (hash == currentLockPassHash) {
                lock.lockState = PinLock::LockState::NewPasscodeRequired;
            }
            else {
                lock.lockState = PinLock::LockState::PasscodeInvalidRetryRequired;
            }
        });
    }

    PinLock::LockState ChangePasscodeLockHandler::newPasscodeConfirmed()
    {
        return activateLock([this](PinLock::LockType, const std::vector<unsigned int> &pin) {
            const auto newPasscodeConfirmedHash = GetPinHash(pin);
            if (newPasscodeHash == newPasscodeConfirmedHash) {
                lock.lockState = PinLock::LockState::Unlocked;
            }
            else {
                lock.lockState = PinLock::LockState::NewPasscodeInvalid;
            }
        });
    }

    PinLock::LockState ChangePasscodeLockHandler::newPasscodeProvided()
    {
        return activateLock([this](PinLock::LockType, const std::vector<unsigned int> &pin) {
            if (pin.size() < lock.getMaxPinSize()) {
                lock.lockState = PinLock::LockState::NewPasscodeInvalidRetryRequired;
                return;
            }
            newPasscodeHash = GetPinHash(pin);
            lock.lockState  = PinLock::LockState::NewPasscodeConfirmRequired;
        });
    }

    PinLock::LockState ChangePasscodeLockHandler::activateLock(OnActivatedCallback onActivatedCallback)
    {
        lock.onActivatedCallback = onActivatedCallback;
        lock.activate();
        return lock.lockState;
    }
} // namespace gui