<commit_before>import '@/lib/sjcl.js'
import '@/lib/hmacsha1.js'
import store from '@/store'

import Util from '@/utils/util.js'

export default class Crypto {
    /**
     * setupAes
     *
     * Sets up AES key and starts sjcl
     */
    static setupAes() {
        // Setup key
        var combinedKey = store.state.account_id + ":" + store.state.hash + "\n"
        var key = sjcl.misc.pbkdf2(combinedKey, store.state.salt, 10000, 256, hmacSHA1)

        store.dispatch('aes', new sjcl.cipher.aes(key)); // Store aes
        sjcl.beware["CBC mode is dangerous because it doesn't protect message integrity."]();
    }
    
    /**
     * decryptConversation
     *
     * Decryptes conversation object
     * @param convo - conversation object
     * @return decrypted conversation
     */
    static decryptConversation (convo) {
        // Removes miliiseconds from timestamp
        convo.timestamp = convo.timestamp / 1000 >> 0; // Remove ms
        convo.timestamp = convo.timestamp * 1000; // Add back zero timestamp

        // Handle title and snippet
        try { 
            convo.title = Crypto.decrypt(convo.title);

            convo.snippet = Crypto.decrypt(convo.snippet);
            convo.snippet = convo.snippet;
        } catch (err) {
            return null
        }
        
        // Handle phone number(s) if applicable
        try {
            convo.phone_numbers = Crypto.decrypt(convo.phone_numbers);
        } catch (err) {
            convo.phone_numbers = "";
        }

        convo.color = Util.expandColor(convo.color);

        return convo;
    }

    /**
     * decryptMessage
     *
     * Decryptes message object
     * @param convo - message object
     * @return decrypted message
     */

    static decryptMessage (message) {
        // Removes miliiseconds from timestamp
        message.timestamp = message.timestamp / 1000 >> 0; // Remove ms
        message.timestamp = message.timestamp * 1000; // Add back zero timestamp

        // Decrypt
        try {
            message.mime_type = Crypto.decrypt(message.mime_type);

            message.data = Crypto.decrypt(message.data)
            message.data = Util.entityEncode(message.data); // encode message

            message.message_from = Crypto.decrypt(message.message_from);
        } catch (err) {<commit_msg>Fix: encoding on messages in thread (from server)<commit_after>import '@/lib/sjcl.js'
import '@/lib/hmacsha1.js'
import store from '@/store'

import Util from '@/utils/util.js'

export default class Crypto {
    /**
     * setupAes
     *
     * Sets up AES key and starts sjcl
     */
    static setupAes() {
        // Setup key
        var combinedKey = store.state.account_id + ":" + store.state.hash + "\n"
        var key = sjcl.misc.pbkdf2(combinedKey, store.state.salt, 10000, 256, hmacSHA1)

        store.dispatch('aes', new sjcl.cipher.aes(key)); // Store aes
        sjcl.beware["CBC mode is dangerous because it doesn't protect message integrity."]();
    }
    
    /**
     * decryptConversation
     *
     * Decryptes conversation object
     * @param convo - conversation object
     * @return decrypted conversation
     */
    static decryptConversation (convo) {
        // Removes miliiseconds from timestamp
        convo.timestamp = convo.timestamp / 1000 >> 0; // Remove ms
        convo.timestamp = convo.timestamp * 1000; // Add back zero timestamp

        // Handle title and snippet
        try { 
            convo.title = Crypto.decrypt(convo.title);

            convo.snippet = Crypto.decrypt(convo.snippet);
            convo.snippet = convo.snippet;
        } catch (err) {
            return null
        }
        
        // Handle phone number(s) if applicable
        try {
            convo.phone_numbers = Crypto.decrypt(convo.phone_numbers);
        } catch (err) {
            convo.phone_numbers = "";
        }

        convo.color = Util.expandColor(convo.color);

        return convo;
    }

    /**
     * decryptMessage
     *
     * Decryptes message object
     * @param convo - message object
     * @return decrypted message
     */

    static decryptMessage (message) {
        // Removes miliiseconds from timestamp
        message.timestamp = message.timestamp / 1000 >> 0; // Remove ms
        message.timestamp = message.timestamp * 1000; // Add back zero timestamp

        // Decrypt
        try {
            message.mime_type = Crypto.decrypt(message.mime_type);

            message.data = Crypto.decrypt(message.data)

            message.message_from = Crypto.decrypt(message.message_from);
        } catch (err) {
{'fraction_non_alphanumeric': 0.10677083333333333, 'fraction_numerical': 0.012586805555555556, 'mean_word_length': 1.9793148028442147, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 11, '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': '309999', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1317, 'n_words': 325}