# 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

    class InvalidSignature(SignatureError):
        """Signature did not match the expected signature given the payload and secret."""

    class InvalidSignatureTimestamp(SignatureError):
        """Timestamp too old, not accepting signature as relevant."""

    def __init__(self, signature, timestamp):
        self.signature = signature
        self.timestamp = timestamp

    _header_format = "t={timestamp},s={signature}"

    def to_header(self):
        """Dump the signature to a header format."""
        signature = compat.want_text(encode_b64(self.signature))

        return Signature._header_format.format(
            timestamp=self.timestamp, signature=signature
        )

    @classmethod
    def from_header(cls, header):
        """Load a signature from a header string."""
        try:
            timestamp, signature = header.split(",", 1)

            timestamp = int(timestamp[2:])
            signature = signature[2:]


# 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


    class InvalidSignature(SignatureError):
        """Signature did not match the expected signature given the payload and secret."""

    class InvalidSignatureTimestamp(SignatureError):
        """Timestamp too old, not accepting signature as relevant."""

    def __init__(self, signature, timestamp):
        self.signature = signature
        self.timestamp = timestamp

    _header_format = "t={timestamp},s={signature}"

    def to_header(self):
        """Dump the signature to a header format."""
        signature = compat.want_text(encode_b64(self.signature))

        return Signature._header_format.format(
            timestamp=self.timestamp, signature=signature
        )

    @classmethod
    def from_header(cls, header):
        """Load a signature from a header string."""
        try:
            timestamp, signature = header.split(",", 1)

            timestamp = int(timestamp[2:])
            signature = signature[2:]


            signature = decode_b64(compat.want_bytes(signature))