# Path: openid/kvform.py
# _LOGGER = logging.getLogger(__name__)
# class KVFormError(ValueError):
# def seqToKV(seq, strict=False):
#     def err(msg):
# def kvToSeq(data, strict=False):
#     def err(msg):
# def dictToKV(d):
# def kvToDict(s):
# 
# Path: openid/oidutil.py
# def autoSubmitHTML(form, title='OpenID transaction in progress'):
# def log(message, level=0):
# def appendArgs(url, args):
# def toBase64(s):
# def fromBase64(s):
#     def __init__(self, name):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __hash__(self):
#     def __repr__(self):
# def string_to_text(value, deprecate_msg):
# def force_text(value):
# class Symbol(object):
# 
# Path: openid/message.py
# OPENID_NS = oidutil.Symbol('OpenID namespace')
# 
# Path: openid/oidutil.py
# def string_to_text(value, deprecate_msg):
#     """
#     Return input string coverted to text string.
# 
#     If input is text, it is returned as is.
#     If input is binary, it is decoded using UTF-8 to text.
#     """
#     assert isinstance(value, (six.text_type, six.binary_type))
#     if isinstance(value, six.binary_type):
#         warnings.warn(deprecate_msg, DeprecationWarning)
#         value = value.decode('utf-8')
#     return value


import time
import six
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.constant_time import bytes_eq
from cryptography.hazmat.primitives.hmac import HMAC
from openid import kvform, oidutil
from openid.message import OPENID_NS
from .oidutil import string_to_text
        extant_handle = message.getArg(OPENID_NS, 'assoc_handle')
        if extant_handle and extant_handle != self.handle:
            raise ValueError("Message has a different association handle")

        signed_message = message.copy()
        signed_message.setArg(OPENID_NS, 'assoc_handle', self.handle)
        message_keys = signed_message.toPostArgs().keys()
        signed_list = [k[7:] for k in message_keys
                       if k.startswith('openid.')]
        signed_list.append('signed')
        signed_list.sort()
        signed_message.setArg(OPENID_NS, 'signed', ','.join(signed_list))
        sig = self.getMessageSignature(signed_message)
        signed_message.setArg(OPENID_NS, 'sig', sig)
        return signed_message

    def checkMessageSignature(self, message):
        """Given a message with a signature, calculate a new signature
        and return whether it matches the signature in the message.

        @raises ValueError: if the message has no signature or no signature
            can be calculated for it.
        """
        message_sig = message.getArg(OPENID_NS, 'sig')
        if not message_sig:
            raise ValueError("%s has no sig." % (message,))
        calculated_sig = self.getMessageSignature(message)
        return bytes_eq(calculated_sig.encode('utf-8'), message_sig.encode('utf-8'))

    def _makePairs(self, message):

# Path: openid/kvform.py
# _LOGGER = logging.getLogger(__name__)
# class KVFormError(ValueError):
# def seqToKV(seq, strict=False):
#     def err(msg):
# def kvToSeq(data, strict=False):
#     def err(msg):
# def dictToKV(d):
# def kvToDict(s):
# 
# Path: openid/oidutil.py
# def autoSubmitHTML(form, title='OpenID transaction in progress'):
# def log(message, level=0):
# def appendArgs(url, args):
# def toBase64(s):
# def fromBase64(s):
#     def __init__(self, name):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __hash__(self):
#     def __repr__(self):
# def string_to_text(value, deprecate_msg):
# def force_text(value):
# class Symbol(object):
# 
# Path: openid/message.py
# OPENID_NS = oidutil.Symbol('OpenID namespace')
# 
# Path: openid/oidutil.py
# def string_to_text(value, deprecate_msg):
#     """
#     Return input string coverted to text string.
# 
#     If input is text, it is returned as is.
#     If input is binary, it is decoded using UTF-8 to text.
#     """
#     assert isinstance(value, (six.text_type, six.binary_type))
#     if isinstance(value, six.binary_type):
#         warnings.warn(deprecate_msg, DeprecationWarning)
#         value = value.decode('utf-8')
#     return value


# Path: openid/association.py
import time
import six
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.constant_time import bytes_eq
from cryptography.hazmat.primitives.hmac import HMAC
from openid import kvform, oidutil
from openid.message import OPENID_NS
from .oidutil import string_to_text

        extant_handle = message.getArg(OPENID_NS, 'assoc_handle')
        if extant_handle and extant_handle != self.handle:
            raise ValueError("Message has a different association handle")

        signed_message = message.copy()
        signed_message.setArg(OPENID_NS, 'assoc_handle', self.handle)
        message_keys = signed_message.toPostArgs().keys()
        signed_list = [k[7:] for k in message_keys
                       if k.startswith('openid.')]
        signed_list.append('signed')
        signed_list.sort()
        signed_message.setArg(OPENID_NS, 'signed', ','.join(signed_list))
        sig = self.getMessageSignature(signed_message)
        signed_message.setArg(OPENID_NS, 'sig', sig)
        return signed_message

    def checkMessageSignature(self, message):
        """Given a message with a signature, calculate a new signature
        and return whether it matches the signature in the message.

        @raises ValueError: if the message has no signature or no signature
            can be calculated for it.
        """
        message_sig = message.getArg(OPENID_NS, 'sig')
        if not message_sig:
            raise ValueError("%s has no sig." % (message,))
        calculated_sig = self.getMessageSignature(message)
        return bytes_eq(calculated_sig.encode('utf-8'), message_sig.encode('utf-8'))

    def _makePairs(self, message):

        signed = message.getArg(OPENID_NS, 'signed')