<commit_before>import hashlib

from corehq.apps.integration.models import DialerSettings, HmacCalloutSettings


def domain_uses_dialer(domain):
    try:
        settings = DialerSettings.objects.get(domain=domain)
        return settings.is_enabled
    except DialerSettings.DoesNotExist:
        return False


def domain_uses_hmac_callout(domain):
    try:
        settings = HmacCalloutSettings.objects.get(domain=domain)
        return settings.is_enabled
    except HmacCalloutSettings.DoesNotExist:
        return False


def get_dialer_settings(domain):
    return DialerSettings.objects.get(domain=domain)


def integration_contexts(domain):
    context = {'dialer_enabled': domain_uses_dialer(domain)}
    if domain_uses_hmac_callout:
        settings = HmacCalloutSettings.objects.get(domain=domain)
        context.update({
            'hmac_root_url': settings.destination_url,
            'hmac_api_key': settings.api_key,
            'hmac_hashed_secret': hash_secret(settings.api_secret),
        })

    return context


def hash_secret(secret):
    return hashlib.sha256(secret.encode()).hexdigest()
<commit_msg>use sha512 for hashed secret<commit_after>import hashlib

from corehq.apps.integration.models import DialerSettings, HmacCalloutSettings


def domain_uses_dialer(domain):
    try:
        settings = DialerSettings.objects.get(domain=domain)
        return settings.is_enabled
    except DialerSettings.DoesNotExist:
        return False


def domain_uses_hmac_callout(domain):
    try:
        settings = HmacCalloutSettings.objects.get(domain=domain)
        return settings.is_enabled
    except HmacCalloutSettings.DoesNotExist:
        return False


def get_dialer_settings(domain):
    return DialerSettings.objects.get(domain=domain)


def integration_contexts(domain):
    context = {'dialer_enabled': domain_uses_dialer(domain)}
    if domain_uses_hmac_callout:
        settings = HmacCalloutSettings.objects.get(domain=domain)
        context.update({
            'hmac_root_url': settings.destination_url,
            'hmac_api_key': settings.api_key,
            'hmac_hashed_secret': hash_secret(settings.api_secret),
        })

    return context


def hash_secret(secret):
    return hashlib.sha512(secret.encode()).hexdigest()

{'fraction_non_alphanumeric': 0.0818301803783546, 'fraction_numerical': 0.003959524857017158, 'mean_word_length': 3.727650727650728, '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': '7367600', 'n_tokens_mistral': 707, 'n_tokens_neox': 676, 'n_words': 114}