# Path: atlassian_jwt_auth/exceptions.py
# class KeyIdentifierException(ASAPAuthenticationException):
#     """Raise when there are issues validating the key identifier"""
# 
# class PublicKeyRetrieverException(_WithStatus, ASAPAuthenticationException):
#     """Raise when there are issues retrieving the public key"""
# 
# class PrivateKeyRetrieverException(_WithStatus, ASAPAuthenticationException):
#     """Raise when there are issues retrieving the private key"""


import base64
import cgi
import logging
import os
import re
import cachecontrol
import cryptography.hazmat.backends
import jwt
import requests
import requests.utils
from urllib.parse import unquote_plus
from cryptography.hazmat.primitives import serialization
from requests.exceptions import RequestException, ConnectionError
from atlassian_jwt_auth.exceptions import (KeyIdentifierException,
                                           PublicKeyRetrieverException,
                                           PrivateKeyRetrieverException)




PEM_FILE_TYPE = 'application/x-pem-file'


class KeyIdentifier(object):

    """ This class represents a key identifier """

    def __init__(self, identifier):
        self.__key_id = validate_key_identifier(identifier)

    @property
    def key_id(self):
        return self.__key_id


def validate_key_identifier(identifier):
    """ returns a validated key identifier. """
    regex = re.compile(r'^[\w.\-\+/]*$')
    _error_msg = 'Invalid key identifier %s' % identifier
    if not identifier:
        raise KeyIdentifierException(_error_msg)
    if not regex.match(identifier):
        raise KeyIdentifierException(_error_msg)
    normalised = os.path.normpath(identifier)
    if normalised != identifier:

# Path: atlassian_jwt_auth/exceptions.py
# class KeyIdentifierException(ASAPAuthenticationException):
#     """Raise when there are issues validating the key identifier"""
# 
# class PublicKeyRetrieverException(_WithStatus, ASAPAuthenticationException):
#     """Raise when there are issues retrieving the public key"""
# 
# class PrivateKeyRetrieverException(_WithStatus, ASAPAuthenticationException):
#     """Raise when there are issues retrieving the private key"""


# Path: atlassian_jwt_auth/key.py
import base64
import cgi
import logging
import os
import re
import cachecontrol
import cryptography.hazmat.backends
import jwt
import requests
import requests.utils
from urllib.parse import unquote_plus
from cryptography.hazmat.primitives import serialization
from requests.exceptions import RequestException, ConnectionError
from atlassian_jwt_auth.exceptions import (KeyIdentifierException,
                                           PublicKeyRetrieverException,
                                           PrivateKeyRetrieverException)





PEM_FILE_TYPE = 'application/x-pem-file'


class KeyIdentifier(object):

    """ This class represents a key identifier """

    def __init__(self, identifier):
        self.__key_id = validate_key_identifier(identifier)

    @property
    def key_id(self):
        return self.__key_id


def validate_key_identifier(identifier):
    """ returns a validated key identifier. """
    regex = re.compile(r'^[\w.\-\+/]*$')
    _error_msg = 'Invalid key identifier %s' % identifier
    if not identifier:
        raise KeyIdentifierException(_error_msg)
    if not regex.match(identifier):
        raise KeyIdentifierException(_error_msg)
    normalised = os.path.normpath(identifier)
    if normalised != identifier:

        raise KeyIdentifierException(_error_msg)