# Path: ricloud/compat.py
# PY3 = sys.version_info[0] >= 3
#     def want_bytes(data):
#     def want_text(data):
#     def to_str(data):
#     def want_bytes(data):
#     def want_text(data):
#     def to_str(data):
# 
# Path: ricloud/utils.py
# def encode_b64(data):
#     return base64.b64encode(data)
# 
# def decode_b64(data):
#     return base64.b64decode(data)
# 
# def generate_timestamp():
#     return int(time.time())


import hmac
import hashlib
from ricloud import compat
from ricloud.utils import encode_b64, decode_b64, generate_timestamp

            signature = decode_b64(compat.want_bytes(signature))
        except Exception:
            raise Signature.InvalidSignatureHeader

        return Signature(signature, timestamp)

    @classmethod
    def sign(cls, data, secret):
        """Sign a bit of data with the given secret."""
        timestamp = compat.want_text(generate_timestamp())

        payload = cls._get_payload(data, timestamp)

        signature = hmac_sign(payload, secret)

        return Signature(signature, timestamp)

    def verify(self, data, secret, delta=None):
        """Verify a signature is valid for a given payload and secret."""
        payload = self._get_payload(data, self.timestamp)

        if not hmac_verify(self.signature, payload, secret):
            raise Signature.InvalidSignature

        if delta and (generate_timestamp() - self.timestamp) > delta:
            raise Signature.InvalidSignatureTimestamp

    @staticmethod
    def _get_payload(data, timestamp):

# Path: ricloud/compat.py
# PY3 = sys.version_info[0] >= 3
#     def want_bytes(data):
#     def want_text(data):
#     def to_str(data):
#     def want_bytes(data):
#     def want_text(data):
#     def to_str(data):
# 
# Path: ricloud/utils.py
# def encode_b64(data):
#     return base64.b64encode(data)
# 
# def decode_b64(data):
#     return base64.b64decode(data)
# 
# def generate_timestamp():
#     return int(time.time())


# Path: ricloud/signing.py
import hmac
import hashlib
from ricloud import compat
from ricloud.utils import encode_b64, decode_b64, generate_timestamp


            signature = decode_b64(compat.want_bytes(signature))
        except Exception:
            raise Signature.InvalidSignatureHeader

        return Signature(signature, timestamp)

    @classmethod
    def sign(cls, data, secret):
        """Sign a bit of data with the given secret."""
        timestamp = compat.want_text(generate_timestamp())

        payload = cls._get_payload(data, timestamp)

        signature = hmac_sign(payload, secret)

        return Signature(signature, timestamp)

    def verify(self, data, secret, delta=None):
        """Verify a signature is valid for a given payload and secret."""
        payload = self._get_payload(data, self.timestamp)

        if not hmac_verify(self.signature, payload, secret):
            raise Signature.InvalidSignature

        if delta and (generate_timestamp() - self.timestamp) > delta:
            raise Signature.InvalidSignatureTimestamp

    @staticmethod
    def _get_payload(data, timestamp):

        return ".".join([compat.want_text(str(timestamp)), compat.want_text(data)])