<commit_before>package net.viperfish.journal.secureProvider;

import java.io.File;
import java.io.IOException;

import org.eclipse.jface.preference.PreferenceNode;

import net.viperfish.journal.framework.ConfigMapping;
import net.viperfish.journal.framework.Configuration;
import net.viperfish.journal.framework.JournalTransformer;
import net.viperfish.journal.framework.provider.PreferenceGUIManager;
import net.viperfish.journal.framework.provider.Provider;
import net.viperfish.utils.file.CommonFunctions;

public final class ViperfishEncryptionProvider implements Provider<JournalTransformer> {

	private File secureDir;
	private BlockCipherMacTransformer bm;
	private StreamCipherTransformer sc;

	public ViperfishEncryptionProvider() {
		if (Configuration.containsKey(ConfigMapping.PORTABLE) && Configuration.getBoolean(ConfigMapping.PORTABLE)) {
			secureDir = new File("secure");
		} else {
			File homeDir = new File(System.getProperty("user.home"));
			File vDiaryDir = new File(homeDir, ".vsDiary");
			CommonFunctions.initDir(vDiaryDir);
			secureDir = new File(vDiaryDir, "secure");
		}
		CommonFunctions.initDir(secureDir);
	}

	@Override
	public JournalTransformer newInstance() {
		try {
			return new BlockCipherMacTransformer(new File(secureDir.getCanonicalPath() + "/salt"));
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public JournalTransformer getInstance() {
		if (bm == null) {
			bm = new BlockCipherMacTransformer(new File(secureDir.getAbsolutePath() + "/salt"));
		}
		return bm;
	}

	@Override
	public JournalTransformer newInstance(String instance) {
		if (instance.equals("BlockCipherMAC")) {
			return newInstance();
		}
		if (instance.equals("StreamCipher")) {
			return new StreamCipherTransformer(new File(secureDir, "salt"));
		}
		return null;
	}

	@Override
	public JournalTransformer getInstance(String instance) {
		if (instance.equals("BlockCipherMAC")) {
			return getInstance();
		}
		if (instance.equals("StreamCipher")) {
			if (sc == null) {
				sc = new StreamCipherTransformer(new File(secureDir, "salt"));
			}
			return sc;
		}
		return null;
	}

	@Override
	public String[] getSupported() {
		return new String[] { "BlockCipherMAC", "StreamCipher" };
	}

	@Override
	public String getName() {
		return "viperfish";
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

	@Override
	public void setDefaultInstance(String instance) {
		// TODO Auto-generated method stub

	}

	@Override
	public String getDefaultInstance() {
		return "BlockCipherMAC";
	}

	@Override
	public void delete() {
		CommonFunctions.delete(secureDir);

	}

	@Override
	public void refresh() {
		bm = null;
		sc = null;

	}

	@Override
	public void initDefaults() {
		Configuration.setProperty(BlockCipherMacTransformer.COMPRESSION, "GZ");
		Configuration.setProperty(BlockCipherMacTransformer.ENCRYPTION_ALG_NAME, "AES");
		Configuration.setProperty(BlockCipherMacTransformer.ENCRYPTION_MODE, "CFB");
		Configuration.setProperty(BlockCipherMacTransformer.ENCRYPTION_PADDING, "PKCS7Padding");
		Configuration.setProperty(BlockCipherMacTransformer.KDF_HASH, "SHA256");
		Configuration.setProperty(BlockCipherMacTransformer.MAC_ALGORITHM, "SHA256");
		Configuration.setProperty(BlockCipherMacTransformer.MAC_TYPE, "HMAC");

	}

	@Override<commit_msg>adds default value for stream cipher, fix bug<commit_after>package net.viperfish.journal.secureProvider;

import java.io.File;
import java.io.IOException;

import org.eclipse.jface.preference.PreferenceNode;

import net.viperfish.journal.framework.ConfigMapping;
import net.viperfish.journal.framework.Configuration;
import net.viperfish.journal.framework.JournalTransformer;
import net.viperfish.journal.framework.provider.PreferenceGUIManager;
import net.viperfish.journal.framework.provider.Provider;
import net.viperfish.utils.file.CommonFunctions;

public final class ViperfishEncryptionProvider implements Provider<JournalTransformer> {

	private File secureDir;
	private BlockCipherMacTransformer bm;
	private StreamCipherTransformer sc;

	public ViperfishEncryptionProvider() {
		if (Configuration.containsKey(ConfigMapping.PORTABLE) && Configuration.getBoolean(ConfigMapping.PORTABLE)) {
			secureDir = new File("secure");
		} else {
			File homeDir = new File(System.getProperty("user.home"));
			File vDiaryDir = new File(homeDir, ".vsDiary");
			CommonFunctions.initDir(vDiaryDir);
			secureDir = new File(vDiaryDir, "secure");
		}
		CommonFunctions.initDir(secureDir);
	}

	@Override
	public JournalTransformer newInstance() {
		try {
			return new BlockCipherMacTransformer(new File(secureDir.getCanonicalPath() + "/salt"));
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public JournalTransformer getInstance() {
		if (bm == null) {
			bm = new BlockCipherMacTransformer(new File(secureDir.getAbsolutePath() + "/salt"));
		}
		return bm;
	}

	@Override
	public JournalTransformer newInstance(String instance) {
		if (instance.equals("BlockCipherMAC")) {
			return newInstance();
		}
		if (instance.equals("StreamCipher")) {
			return new StreamCipherTransformer(new File(secureDir, "salt"));
		}
		return null;
	}

	@Override
	public JournalTransformer getInstance(String instance) {
		if (instance.equals("BlockCipherMAC")) {
			return getInstance();
		}
		if (instance.equals("StreamCipher")) {
			if (sc == null) {
				sc = new StreamCipherTransformer(new File(secureDir, "salt"));
			}
			return sc;
		}
		return null;
	}

	@Override
	public String[] getSupported() {
		return new String[] { "BlockCipherMAC", "StreamCipher" };
	}

	@Override
	public String getName() {
		return "viperfish";
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

	@Override
	public void setDefaultInstance(String instance) {
		// TODO Auto-generated method stub

	}

	@Override
	public String getDefaultInstance() {
		return "BlockCipherMAC";
	}

	@Override
	public void delete() {
		CommonFunctions.delete(secureDir);

	}

	@Override
	public void refresh() {
		bm = null;
		sc = null;

	}

	@Override
	public void initDefaults() {
		Configuration.setProperty(BlockCipherMacTransformer.COMPRESSION, "GZ");
		Configuration.setProperty(BlockCipherMacTransformer.ENCRYPTION_ALG_NAME, "AES");
		Configuration.setProperty(BlockCipherMacTransformer.ENCRYPTION_MODE, "CFB");
		Configuration.setProperty(BlockCipherMacTransformer.ENCRYPTION_PADDING, "PKCS7Padding");
		Configuration.setProperty(BlockCipherMacTransformer.KDF_HASH, "SHA256");
		Configuration.setProperty(BlockCipherMacTransformer.MAC_ALGORITHM, "SHA256");
		Configuration.setProperty(BlockCipherMacTransformer.MAC_TYPE, "HMAC");
		Configuration.setProperty(StreamCipherTransformer.ALG_NAME, "ChaCha");

	}

	@Override
{'fraction_non_alphanumeric': 0.11143911439114391, 'fraction_numerical': 0.002066420664206642, 'mean_word_length': 5.428842504743833, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '537163', 'n_tokens_mistral': 2288, 'n_tokens_neox': 2081, 'n_words': 408}