<commit_before>package hu.blackbelt.encryption.services.impl;

import hu.blackbelt.encryption.services.ConfigDecryptor;
import hu.blackbelt.encryption.services.Encryptor;
import lombok.extern.slf4j.Slf4j;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Slf4j
public abstract class BaseConfigDecryptor implements ConfigDecryptor {

    private static final String FN_NAME = "ENC";
    private static final Pattern PATTERN = Pattern.compile("^" + FN_NAME + "\\((.*)\\)$");
    private static final Pattern PATTERN_WITH_ALIAS = Pattern.compile("^" + FN_NAME + "\\((.*)\\s*,\\s*(.*)\\)$");

    @Override
    public String decrypt(final String encryptedMessage) {
        final Matcher mWithAias = PATTERN_WITH_ALIAS.matcher(encryptedMessage);
        final String encrypted;
        final String alias;
        if (mWithAias.matches()) {
            encrypted = mWithAias.group(1);
            alias = mWithAias.group(2);
        } else {
            final Matcher mWithoutAias = PATTERN.matcher(encryptedMessage);
            if (mWithoutAias.matches()) {
                encrypted = mWithoutAias.group(1);
                alias = null;
            } else {
                throw new IllegalArgumentException("Invalid encrypted message format");
            }
        }

        final Encryptor encryptor = getEncryptor(alias);

        // return original value is encryptor not found
        return encryptor != null ? encryptor.decrypt(encrypted) : encryptedMessage;
    }

    protected abstract Encryptor getEncryptor(String alias);

    @Override
    public boolean isEncrypted(final String value) {
        return value != null ? PATTERN.matcher(value).matches() : false;
    }
}<commit_msg>fix NPE and encrypted configuration value patterns<commit_after>package hu.blackbelt.encryption.services.impl;

import hu.blackbelt.encryption.services.ConfigDecryptor;
import hu.blackbelt.encryption.services.Encryptor;
import lombok.extern.slf4j.Slf4j;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Slf4j
public abstract class BaseConfigDecryptor implements ConfigDecryptor {

    private static final String FN_NAME = "ENC";
    private static final Pattern PATTERN = Pattern.compile("^" + FN_NAME + "\\((.*)\\)$");
    private static final Pattern PATTERN_WITH_ALIAS = Pattern.compile("^" + FN_NAME + "\\((.*)\\s*,\\s*(.*)\\)$");

    @Override
    public String decrypt(final String encryptedMessage) {
        if (encryptedMessage == null){
            return null;
        }

        final Matcher mWithAias = PATTERN_WITH_ALIAS.matcher(encryptedMessage);
        final String encrypted;
        final String alias;
        if (mWithAias.matches()) {
            encrypted = mWithAias.group(1);
            alias = mWithAias.group(2);
        } else {
            final Matcher mWithoutAias = PATTERN.matcher(encryptedMessage);
            if (mWithoutAias.matches()) {
                encrypted = mWithoutAias.group(1);
                alias = null;
            } else {
                throw new IllegalArgumentException("Invalid encrypted message format");
            }
        }

        final Encryptor encryptor = getEncryptor(alias);

        // return original value is encryptor not found
        return encryptor != null ? encryptor.decrypt(encrypted) : encryptedMessage;
    }

    protected abstract Encryptor getEncryptor(String alias);

    @Override
    public boolean isEncrypted(final String value) {
        return value != null ? PATTERN_WITH_ALIAS.matcher(value).matches() || PATTERN.matcher(value).matches() : false;
    }
}
{'fraction_non_alphanumeric': 0.10677446333983831, 'fraction_numerical': 0.003345413994981879, 'mean_word_length': 2.8210862619808306, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4560893', 'n_tokens_mistral': 1072, 'n_tokens_neox': 993, 'n_words': 236}