lib/util/hmac.py
def calculate_hmac(hmac_secret, *content, digestmod=hashlib.sha256):
    '''
    Calculates the HMAC for the given `content` using the `hmac_secret`.
    This is calculated by first generating the HMAC for each item in
    `content` separately, then concatenating them, and finally running another
    HMAC on the concatenated intermediate result. Finally, the result of that
    is base-64 encoded, so it is suitable for use in headers.
    '''
    assert isinstance(hmac_secret, (str, bytes)), \
        'hmac secret must be str or bytes: %r' % (hmac_secret)
    if len(content) == 0:
        raise ValueError('no data supplied')

    hmac_secret = str_to_bytes(hmac_secret)

    content_hmac_digests = map(
        lambda data: _calculate_hmac(
            hmac_secret, data=data, digestmod=digestmod,
        ), content,
    )

    if len(content) > 1:
        # compose individual hmac fragments into one and then hash it again
        concatenated_hmac_digests = b''.join(content_hmac_digests)
        hmac_digest_binary = _calculate_hmac(
            hmac_secret, data=concatenated_hmac_digests, digestmod=digestmod,
        )
    else:
        assert len(content) == 1, \
            '[internal] number of arguments is not 1: %r' % (content)
        hmac_digest_binary = next(content_hmac_digests)

    hmac_digest_bytes = base64_encode(hmac_digest_binary)
    hmac_digest_str = bytes_to_str(hmac_digest_bytes)

    return hmac_digest_str

    Calculates the HMAC for the given `content` using the `hmac_secret`.
    This is calculated by first generating the HMAC for each item in
    `content` separately, then concatenating them, and finally running another
    HMAC on the concatenated intermediate result. Finally, the result of that
    is base-64 encoded, so it is suitable for use in headers.
    
Calculates the HMAC for the given `content` using the `hmac_secret`.
This is calculated by first generating the HMAC for each item in
`content` separately, then concatenating them, and finally running another
HMAC on the concatenated intermediate result. Finally, the result of that
is base-64 encoded, so it is suitable for use in headers.
Calculates the HMAC for the given ` content ` using the ` hmac_secret ` . This is calculated by first generating the HMAC for each item in ` content ` separately then concatenating them and finally running another HMAC on the concatenated intermediate result . Finally the result of that is base - 64 encoded so it is suitable for use in headers .
def calculate_hmac(hmac_secret, *content, digestmod=hashlib.sha256):
    assert isinstance(hmac_secret, (str, bytes)), \
        'hmac secret must be str or bytes: %r' % (hmac_secret)
    if len(content) == 0:
        raise ValueError('no data supplied')
    hmac_secret = str_to_bytes(hmac_secret)
    content_hmac_digests = map(
        lambda data: _calculate_hmac(
            hmac_secret, data=data, digestmod=digestmod,
        ), content,
    )
    if len(content) > 1:
        concatenated_hmac_digests = b''.join(content_hmac_digests)
        hmac_digest_binary = _calculate_hmac(
            hmac_secret, data=concatenated_hmac_digests, digestmod=digestmod,
        )
    else:
        assert len(content) == 1, \
            '[internal] number of arguments is not 1: %r' % (content)
        hmac_digest_binary = next(content_hmac_digests)
    hmac_digest_bytes = base64_encode(hmac_digest_binary)
    hmac_digest_str = bytes_to_str(hmac_digest_bytes)
    return hmac_digest_str
def calculate_hmac ( hmac_secret , * content , digestmod = hashlib . sha256 ) : assert isinstance ( hmac_secret , ( str , bytes ) ) , 'hmac secret must be str or bytes: %r' % ( hmac_secret ) if len ( content ) == 0 : raise ValueError ( 'no data supplied' ) hmac_secret = str_to_bytes ( hmac_secret ) content_hmac_digests = map ( lambda data : _calculate_hmac ( hmac_secret , data = data , digestmod = digestmod , ) , content , ) if len ( content ) > 1 : concatenated_hmac_digests = b'' . join ( content_hmac_digests ) hmac_digest_binary = _calculate_hmac ( hmac_secret , data = concatenated_hmac_digests , digestmod = digestmod , ) else : assert len ( content ) == 1 , '[internal] number of arguments is not 1: %r' % ( content ) hmac_digest_binary = next ( content_hmac_digests ) hmac_digest_bytes = base64_encode ( hmac_digest_binary ) hmac_digest_str = bytes_to_str ( hmac_digest_bytes ) return hmac_digest_str
Calculates the HMAC for the given `content` using the `hmac_secret`.
Calculates the HMAC for the given ` content ` using the ` hmac_secret ` .
'''
    Calculates the HMAC for the given `content` using the `hmac_secret`.
    This is calculated by first generating the HMAC for each item in
    `content` separately, then concatenating them, and finally running another
    HMAC on the concatenated intermediate result. Finally, the result of that
    is base-64 encoded, so it is suitable for use in headers.
    ''' # compose individual hmac fragments into one and then hash it again
hmac_secret
digestmod