<commit_before>//
//  Copyright (c) 2014-2016 Actor LLC. <https://actor.im>
//

import Foundation
import CommonCrypto

class CocoaCrypto: NSObject, ARCocoaCryptoProxyProvider {
    
    func createSHA256() -> ARDigest! {
        return SHA256Digest()
    }
    
    func createAES128WithKey(key: IOSByteArray!) -> ARBlockCipher! {
        return AES128(key: key)
    }
}

class SHA256Digest: NSObject, ARDigest {
    
    let context = UnsafeMutablePointer<CC_SHA256_CTX>.alloc(1)
    
    override init() {
        super.init()
        reset()
    }
    
    deinit {
        context.dealloc(1)
    }
    
    func reset() {
        CC_SHA256_Init(context)
    }
    
    func update(src: IOSByteArray!, withOffset offset: jint, withLength length: jint) {
        
        let pointer = src
            .buffer()
            .advancedBy(Int(offset))
        
        CC_SHA256_Update(context, pointer, CC_LONG(length))
    }
    
    func doFinal(dest: IOSByteArray!, withOffset destOffset: jint) {
        
        let pointer = UnsafeMutablePointer<UInt8>(dest.buffer())
            .advancedBy(Int(destOffset))
        
        CC_SHA256_Final(pointer, context)
    }
    
    func getDigestSize() -> jint {
        return jint(CC_SHA256_DIGEST_LENGTH)
    }
}

class AES128: NSObject, ARBlockCipher {
    
    var encryptor = UnsafeMutablePointer<CCCryptorRef>.alloc(1)
    var decryptor = UnsafeMutablePointer<CCCryptorRef>.alloc(1)
    
    init(key: IOSByteArray) {
        let res = CCCryptorCreate(
            CCOperation(kCCEncrypt),
            CCAlgorithm(kCCAlgorithmAES),
            CCOptions(kCCOptionECBMode),
            key.buffer(), 32,
            nil,
            encryptor)
        
        print("res: \(res) \(key.length())")
        
        CCCryptorCreate(
            CCOperation(kCCDecrypt),
            CCAlgorithm(kCCAlgorithmAES),<commit_msg>feat(iOS): Remove aes init logging<commit_after>//
//  Copyright (c) 2014-2016 Actor LLC. <https://actor.im>
//

import Foundation
import CommonCrypto

class CocoaCrypto: NSObject, ARCocoaCryptoProxyProvider {
    
    func createSHA256() -> ARDigest! {
        return SHA256Digest()
    }
    
    func createAES128WithKey(key: IOSByteArray!) -> ARBlockCipher! {
        return AES128(key: key)
    }
}

class SHA256Digest: NSObject, ARDigest {
    
    let context = UnsafeMutablePointer<CC_SHA256_CTX>.alloc(1)
    
    override init() {
        super.init()
        reset()
    }
    
    deinit {
        context.dealloc(1)
    }
    
    func reset() {
        CC_SHA256_Init(context)
    }
    
    func update(src: IOSByteArray!, withOffset offset: jint, withLength length: jint) {
        
        let pointer = src
            .buffer()
            .advancedBy(Int(offset))
        
        CC_SHA256_Update(context, pointer, CC_LONG(length))
    }
    
    func doFinal(dest: IOSByteArray!, withOffset destOffset: jint) {
        
        let pointer = UnsafeMutablePointer<UInt8>(dest.buffer())
            .advancedBy(Int(destOffset))
        
        CC_SHA256_Final(pointer, context)
    }
    
    func getDigestSize() -> jint {
        return jint(CC_SHA256_DIGEST_LENGTH)
    }
}

class AES128: NSObject, ARBlockCipher {
    
    var encryptor = UnsafeMutablePointer<CCCryptorRef>.alloc(1)
    var decryptor = UnsafeMutablePointer<CCCryptorRef>.alloc(1)
    
    init(key: IOSByteArray) {
        CCCryptorCreate(
            CCOperation(kCCEncrypt),
            CCAlgorithm(kCCAlgorithmAES),
            CCOptions(kCCOptionECBMode),
            key.buffer(), 32,
            nil,
            encryptor)
        
        CCCryptorCreate(
            CCOperation(kCCDecrypt),
            CCAlgorithm(kCCAlgorithmAES),
{'fraction_non_alphanumeric': 0.09862570735650768, 'fraction_numerical': 0.025869037995149554, 'mean_word_length': 2.1377852916314453, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, 'https://': 2, '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': '3439188', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1160, 'n_words': 208}