<commit_before># SPDX-License-Identifier: MIT
# Copyright (c) 2015, Elaborated Networks GmbH
# Copyright (c) 2018, <NAME>

"""Generic message digest wrapper (hash algorithm)."""


from libc.stdlib cimport free, malloc

cimport mbedtls._md as _md

import binascii

import mbedtls.exceptions as _exc
import mbedtls.version as _version

__MD_NAME = (
    # Define as bytes to map to `const char*` without conversion.
    b"NONE",
    b"MD2",
    b"MD4",
    b"MD5",
    b"SHA1",
    b"SHA224",
    b"SHA256",
    b"SHA384",
    b"SHA512",
    b"RIPEMD160",
)


def __get_supported_mds():
    """Return the set of digests supported by the generic
    message digest module.

    See Also:
        mbedtls.tls.__get_supported_ciphersuites()

    """
    md_lookup = {n: v for n, v in enumerate(__MD_NAME)}
    cdef const int* md_types = _md.mbedtls_md_list()
    cdef size_t n = 0
    mds = []
    while md_types[n]:
        mds.append(md_lookup[md_types[n]])
        n += 1
    return mds


def _digestmod(sig_md):
    return __MD_NAME[sig_md].decode("ascii").lower()


algorithms_guaranteed = ("md5", "sha1", "sha224", "sha256", "sha384", "sha512")
algorithms_available = tuple(
    name.decode("ascii").lower() for name in __get_supported_mds()
    if _version.has_feature(name.decode("ascii"))
)


__all__ = algorithms_guaranteed + ("new", "algorithms_guaranteed",
                                   "algorithms_available")


cdef class MDBase:
    """Wrap and encapsulate the md library from mbed TLS.

    Parameters:
        name (str): The MD name known to mbed TLS.
        block_size (int): The internal block size of the hash
            algorithm in bytes.

    Attributes:
        digest_size (int): The size of the message digest, in bytes.
        block_size (int): The internal block size of the hash
            algorithm in bytes.
        name (str): The name of the message digest.

    """
    def __init__(self, name, _hmac, *, block_size=64):
        try:
            name_ = name.encode("ascii", "strict").upper()
        except (AttributeError, ValueError) as exc:
            # Not `str`-like.<commit_msg>md: Guarantee less algs<commit_after># SPDX-License-Identifier: MIT
# Copyright (c) 2015, Elaborated Networks GmbH
# Copyright (c) 2018, <NAME>

"""Generic message digest wrapper (hash algorithm)."""


from libc.stdlib cimport free, malloc

cimport mbedtls._md as _md

import binascii

import mbedtls.exceptions as _exc
import mbedtls.version as _version

__MD_NAME = (
    # Define as bytes to map to `const char*` without conversion.
    b"NONE",
    b"MD2",
    b"MD4",
    b"MD5",
    b"SHA1",
    b"SHA224",
    b"SHA256",
    b"SHA384",
    b"SHA512",
    b"RIPEMD160",
)


def __get_supported_mds():
    """Return the set of digests supported by the generic
    message digest module.

    See Also:
        mbedtls.tls.__get_supported_ciphersuites()

    """
    md_lookup = {n: v for n, v in enumerate(__MD_NAME)}
    cdef const int* md_types = _md.mbedtls_md_list()
    cdef size_t n = 0
    mds = []
    while md_types[n]:
        mds.append(md_lookup[md_types[n]])
        n += 1
    return mds


def _digestmod(sig_md):
    return __MD_NAME[sig_md].decode("ascii").lower()


algorithms_guaranteed = ("md5", "sha1", "sha256")
algorithms_available = tuple(
    name.decode("ascii").lower() for name in __get_supported_mds()
    if _version.has_feature(name.decode("ascii"))
)


__all__ = algorithms_guaranteed + ("new", "algorithms_guaranteed",
                                   "algorithms_available")


cdef class MDBase:
    """Wrap and encapsulate the md library from mbed TLS.

    Parameters:
        name (str): The MD name known to mbed TLS.
        block_size (int): The internal block size of the hash
            algorithm in bytes.

    Attributes:
        digest_size (int): The size of the message digest, in bytes.
        block_size (int): The internal block size of the hash
            algorithm in bytes.
        name (str): The name of the message digest.

    """
    def __init__(self, name, _hmac, *, block_size=64):
        try:
            name_ = name.encode("ascii", "strict").upper()
        except (AttributeError, ValueError) as exc:
            # Not `str`-like.
{'fraction_non_alphanumeric': 0.11158392434988179, 'fraction_numerical': 0.019148936170212766, 'mean_word_length': 2.7878245299910476, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7107818', 'n_tokens_mistral': 1463, 'n_tokens_neox': 1355, 'n_words': 413}