<commit_before>"use strict";

var Err = function(ctx, code, msg) {
    this.ctx = ctx;
    this.code = code;
    this.msg = msg;
};

Err.Context = {};
Err.Context.KEY = 0x02;
Err.Context.NET = 0x03;
Err.Context.UNK = 0x0f;

var Crypto = {};

Crypto.toBase64 = function(str) {
    return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Latin1.parse(str));
};

Crypto.fromBase64 = function(str) {
    return CryptoJS.enc.Latin1.stringify(CryptoJS.enc.Base64.parse(str));
};

Crypto.randomNonce = function() {
    var word = sjcl.random.randomWords(1)[0];
    // Twos-complement it if negative.
    if (word < 0)
        word += 0x80000000;
    return word;
};

Crypto.retryForEntropy = function (action) {
    var deferred = Q.defer();
    // We can maybe be more awesome and note that SJCL never needs to
    // re-seed its PRNG once its been seeded initially.
    var retry = function() {
        sjcl.random.removeEventListener("seeded", retry);
	try {
            deferred.resolve(action());
	} catch (e) {
            if (e instanceof sjcl.exception.notReady) {
		// Retry when we have more entropy.
		// FIXME: NO. Just... no.
		alert("Not enough entropy! Please jiggle the mouse a bunch.");
		sjcl.random.addEventListener("seeded", retry);
            } else {
		deferred.reject(e);
            }
	}
    };
    retry();<commit_msg>Use SJCL's base64 implementation<commit_after>"use strict";

var Err = function(ctx, code, msg) {
    this.ctx = ctx;
    this.code = code;
    this.msg = msg;
};

Err.Context = {};
Err.Context.KEY = 0x02;
Err.Context.NET = 0x03;
Err.Context.UNK = 0x0f;

var Crypto = {};

Crypto.toBase64 = function(str) {
    return sjcl.codec.base64.fromBits(sjcl.codec.byteString.toBits(str));
};

Crypto.fromBase64 = function(str) {
    return sjcl.codec.byteString.fromBits(sjcl.codec.base64.toBits(str));
};

Crypto.randomNonce = function() {
    var word = sjcl.random.randomWords(1)[0];
    // Twos-complement it if negative.
    if (word < 0)
        word += 0x80000000;
    return word;
};

Crypto.retryForEntropy = function (action) {
    var deferred = Q.defer();
    // We can maybe be more awesome and note that SJCL never needs to
    // re-seed its PRNG once its been seeded initially.
    var retry = function() {
        sjcl.random.removeEventListener("seeded", retry);
	try {
            deferred.resolve(action());
	} catch (e) {
            if (e instanceof sjcl.exception.notReady) {
		// Retry when we have more entropy.
		// FIXME: NO. Just... no.
		alert("Not enough entropy! Please jiggle the mouse a bunch.");
		sjcl.random.addEventListener("seeded", retry);
            } else {
		deferred.reject(e);
            }
	}
    };
    retry();
{'fraction_non_alphanumeric': 0.14136516225289072, 'fraction_numerical': 0.02237970906378217, 'mean_word_length': 2.7563025210084033, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '198392', 'n_tokens_mistral': 958, 'n_tokens_neox': 913, 'n_words': 222}