def get_algorithm(algorithm):
    """Returns the wire format string and the hash module to use for the
    specified TSIG algorithm

    @rtype: (string, hash constructor)
    @raises NotImplementedError: I{algorithm} is not supported
    """

    hashes = {}
    try:
        import hashlib
        hashes[dns.name.from_text('hmac-sha224')] = hashlib.sha224
        hashes[dns.name.from_text('hmac-sha256')] = hashlib.sha256
        hashes[dns.name.from_text('hmac-sha384')] = hashlib.sha384
        hashes[dns.name.from_text('hmac-sha512')] = hashlib.sha512
        hashes[dns.name.from_text('hmac-sha1')] = hashlib.sha1
        hashes[dns.name.from_text('HMAC-MD5.SIG-ALG.REG.INT')] = hashlib.md5

        import sys
        if sys.hexversion < 0x02050000:
            # hashlib doesn't conform to PEP 247: API for
            # Cryptographic Hash Functions, which hmac before python
            # 2.5 requires, so add the necessary items.
            class HashlibWrapper:
                def __init__(self, basehash):
                    self.basehash = basehash
                    self.digest_size = self.basehash().digest_size

                def new(self, *args, **kwargs):
                    return self.basehash(*args, **kwargs)

            for name in hashes:
                hashes[name] = HashlibWrapper(hashes[name])

    except __HOLE__:
        import md5, sha
        hashes[dns.name.from_text('HMAC-MD5.SIG-ALG.REG.INT')] =  md5.md5
        hashes[dns.name.from_text('hmac-sha1')] = sha.sha

    if isinstance(algorithm, (str, unicode)):
        algorithm = dns.name.from_text(algorithm)

    if algorithm in hashes:
        return (algorithm.to_digestable(), hashes[algorithm])

    raise NotImplementedError("TSIG algorithm " + str(algorithm) +
                              " is not supported")
dataset/ETHPy150Open catap/namebench/nb_third_party/dns/tsig.py/get_algorithm