<commit_before>//
//  CryptedDataTransform.swift
//  Bartleby
//
//  Created by <NAME> on 05/01/2016.
//  Copyright © 2015 https://pereira-da-silva.com for Chaosmos SAS
//  All rights reserved you can ask for a license.


import Foundation

#if !USE_EMBEDDED_MODULES
    import ObjectMapper
#endif

public class CryptedDataTransform: TransformType {

    public typealias Object = NSData
    public typealias JSON = String


    public func transformFromJSON(value: AnyObject?) -> Object? {
        if let s=value as? String {
            do {
                if let data=s.dataUsingEncoding(Default.TEXT_ENCODING, allowLossyConversion:false) {
                    return try Bartleby.cryptoDelegate.decryptData(data)
                }

            } catch {
                // SILENT CATCH
            }
        }
        return nil
    }

    public func transformToJSON(value: Object?) -> JSON? {
        if let d=value as NSData? {
            return d.base64EncodedStringWithOptions(.EncodingEndLineWithCarriageReturn)
        }
        return nil<commit_msg>More pleasant / compact silent catch<commit_after>//
//  CryptedDataTransform.swift
//  Bartleby
//
//  Created by <NAME> on 05/01/2016.
//  Copyright © 2015 https://pereira-da-silva.com for Chaosmos SAS
//  All rights reserved you can ask for a license.


import Foundation

#if !USE_EMBEDDED_MODULES
    import ObjectMapper
#endif

public class CryptedDataTransform: TransformType {

    public typealias Object = NSData
    public typealias JSON = String


    public func transformFromJSON(value: AnyObject?) -> Object? {
        if let s=value as? String {
            if let data=s.dataUsingEncoding(Default.TEXT_ENCODING, allowLossyConversion:false) {
                return try? Bartleby.cryptoDelegate.decryptData(data)
            }
        }
        return nil
    }

    public func transformToJSON(value: Object?) -> JSON? {
        if let d=value as NSData? {
            return d.base64EncodedStringWithOptions(.EncodingEndLineWithCarriageReturn)
        }
        return nil
{'fraction_non_alphanumeric': 0.08179162609542356, 'fraction_numerical': 0.013631937682570594, 'mean_word_length': 2.3633387888707036, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '5885889', 'n_tokens_mistral': 627, 'n_tokens_neox': 576, 'n_words': 159}