<commit_before>//
//  PasscodeLock.swift
//  PasscodeLock
//
//  Created by <NAME> on 8/28/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation
import LocalAuthentication

open class PasscodeLock: PasscodeLockType {
    
    open weak var delegate: PasscodeLockTypeDelegate?
    open let configuration: PasscodeLockConfigurationType
    
    open var repository: PasscodeRepositoryType {
        return configuration.repository
    }
    
    open var state: PasscodeLockStateType {
        return lockState
    }
    
    open var isTouchIDAllowed: Bool {
        return isTouchIDEnabled() && configuration.isTouchIDAllowed && lockState.isTouchIDAllowed
    }
    
    fileprivate var lockState: PasscodeLockStateType
    fileprivate lazy var passcode = ""
    
    public init(state: PasscodeLockStateType, configuration: PasscodeLockConfigurationType) {
        
        precondition(configuration.passcodeLength > 0, "Passcode length sould be greather than zero.")
        
        self.lockState = state
        self.configuration = configuration
    }
    
    open func addSign(_ sign: String) {
        
        passcode = passcode + sign
        delegate?.passcodeLock(self, addedSignAtIndex: passcode.characters.count - 1)
        
        if passcode.characters.count >= configuration.passcodeLength {
            
            lockState.acceptPasscode(passcode, fromLock: self)
            passcode.removeAll(keepingCapacity: true)
        }
    }
    
    open func removeSign() {
        
        guard passcode.characters.count > 0 else { return }
        
        let index = passcode.index(passcode.startIndex, offsetBy: passcode.characters.count)
        passcode = passcode.substring(to: index)
        delegate?.passcodeLock(self, removedSignAtIndex: passcode.characters.count)
    }
    
    open func changeStateTo(_ state: PasscodeLockStateType) {
        
        lockState = state
        delegate?.passcodeLockDidChangeState(self)
    }
    
    open func authenticateWithBiometrics() {
        
        guard isTouchIDAllowed else { return }
        
        let context = LAContext()<commit_msg>fix bug with removing sign<commit_after>//
//  PasscodeLock.swift
//  PasscodeLock
//
//  Created by <NAME> on 8/28/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation
import LocalAuthentication

open class PasscodeLock: PasscodeLockType {
    
    open weak var delegate: PasscodeLockTypeDelegate?
    open let configuration: PasscodeLockConfigurationType
    
    open var repository: PasscodeRepositoryType {
        return configuration.repository
    }
    
    open var state: PasscodeLockStateType {
        return lockState
    }
    
    open var isTouchIDAllowed: Bool {
        return isTouchIDEnabled() && configuration.isTouchIDAllowed && lockState.isTouchIDAllowed
    }
    
    fileprivate var lockState: PasscodeLockStateType
    fileprivate lazy var passcode = ""
    
    public init(state: PasscodeLockStateType, configuration: PasscodeLockConfigurationType) {
        
        precondition(configuration.passcodeLength > 0, "Passcode length sould be greather than zero.")
        
        self.lockState = state
        self.configuration = configuration
    }
    
    open func addSign(_ sign: String) {
        
        passcode = passcode + sign
        delegate?.passcodeLock(self, addedSignAtIndex: passcode.characters.count - 1)
        
        if passcode.characters.count >= configuration.passcodeLength {
            
            lockState.acceptPasscode(passcode, fromLock: self)
            passcode.removeAll(keepingCapacity: true)
        }
    }
    
    open func removeSign() {
        
        guard passcode.characters.count > 0 else { return }
        
        let index = passcode.index(passcode.startIndex, offsetBy: passcode.characters.count - 1)
        passcode = passcode.substring(to: index)
        delegate?.passcodeLock(self, removedSignAtIndex: passcode.characters.count)
    }
    
    open func changeStateTo(_ state: PasscodeLockStateType) {
        
        lockState = state
        delegate?.passcodeLockDidChangeState(self)
    }
    
    open func authenticateWithBiometrics() {
        
        guard isTouchIDAllowed else { return }
        
        let context = LAContext()
{'fraction_non_alphanumeric': 0.07220803343394475, 'fraction_numerical': 0.005804504295333178, 'mean_word_length': 2.4574638844301764, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7476961', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1140, 'n_words': 274}