# Path: app.py
# def setup_logging():
# 
# Path: skier/keyinfo.py
# def jsondes(obj):
# def wrap(i):
#     def __init__(self, uid: list = None, keyid: str = None, fingerprint: str = None,
#                  length: int = None, algo: PGPAlgo = None, created: int = None, expires: int = None,
#                  subkeys: list = None,
#                  sigs: dict = None,
#                  expired: bool = False, revoked: bool = False, armored: str = "", oid=None):
#     def expired(self):
#     def __repr__(self):
#     def to_pks(self):
#     def _setup_keybase(self, username):
#     def from_json(self, data: str):
#     def to_json(self):
#     def get_expired_ymd(self):
#     def get_created_ymd(self):
#     def get_algo_name(self):
#     def get_algo_id(self):
#     def get_user_fingerprint(self):
#     def translate(self, sig):
#     def get_length(self):
#     def __eq__(self, other):
#     def pgp_dump(cls, armored: str, packets: list = None):
#     def from_database_object(cls, keyob: db.Key):
# class PGPAlgo(Enum):
# class KeyInfo(object):
#     RSA = 1
#     RSA_E = 2
#     RSA_S = 3
#     ELGAMAL = 16
#     DSA = 17
#     ECC = 18
#     ECDSA = 19
#     DH = 21


from flask.ext.sqlalchemy import Pagination
from app import cache
from skier import keyinfo
import db
    Lookup a PGP key.
    :param keyid: The key ID to lookup.
    :return: The armored version of the PGP key, or None if the key does not exist in the DB.
    """
    if cache.exists(keyid + "-armor"):
        return cache.get(keyid + "-armor").decode()
    if keyid.startswith("0x"):
        keyid = keyid.replace("0x", "")
    if len(keyid) == 40:
        key = db.Key.query.filter(db.Key.fingerprint == keyid).first()
    elif len(keyid) == 8:
        key = db.Key.query.filter(db.Key.key_fp_id == keyid).first()
    else:
        key = db.Key.query.filter(db.Key.uid.ilike("%{}%".format(keyid))).first()
    if key:
        if key.armored:
            cache.setex(keyid + "-armor", 60*60*24, key.armored)
            return key.armored
        else:
            return ""
    else: return None

def get_pgp_keyinfo(keyid: str) -> keyinfo.KeyInfo:
    """
    Gets a :skier.keyinfo.KeyInfo: object for the specified key.
    :param keyid: The ID of the key to lookup.
    :return: A new :skier.keyinfo.KeyInfo: object for the key.
    """
    key = db.Key.query.filter(db.Key.key_fp_id == keyid).first()
    if key:

# Path: app.py
# def setup_logging():
# 
# Path: skier/keyinfo.py
# def jsondes(obj):
# def wrap(i):
#     def __init__(self, uid: list = None, keyid: str = None, fingerprint: str = None,
#                  length: int = None, algo: PGPAlgo = None, created: int = None, expires: int = None,
#                  subkeys: list = None,
#                  sigs: dict = None,
#                  expired: bool = False, revoked: bool = False, armored: str = "", oid=None):
#     def expired(self):
#     def __repr__(self):
#     def to_pks(self):
#     def _setup_keybase(self, username):
#     def from_json(self, data: str):
#     def to_json(self):
#     def get_expired_ymd(self):
#     def get_created_ymd(self):
#     def get_algo_name(self):
#     def get_algo_id(self):
#     def get_user_fingerprint(self):
#     def translate(self, sig):
#     def get_length(self):
#     def __eq__(self, other):
#     def pgp_dump(cls, armored: str, packets: list = None):
#     def from_database_object(cls, keyob: db.Key):
# class PGPAlgo(Enum):
# class KeyInfo(object):
#     RSA = 1
#     RSA_E = 2
#     RSA_S = 3
#     ELGAMAL = 16
#     DSA = 17
#     ECC = 18
#     ECDSA = 19
#     DH = 21


# Path: skier/pgp.py
from flask.ext.sqlalchemy import Pagination
from app import cache
from skier import keyinfo
import db

    Lookup a PGP key.
    :param keyid: The key ID to lookup.
    :return: The armored version of the PGP key, or None if the key does not exist in the DB.
    """
    if cache.exists(keyid + "-armor"):
        return cache.get(keyid + "-armor").decode()
    if keyid.startswith("0x"):
        keyid = keyid.replace("0x", "")
    if len(keyid) == 40:
        key = db.Key.query.filter(db.Key.fingerprint == keyid).first()
    elif len(keyid) == 8:
        key = db.Key.query.filter(db.Key.key_fp_id == keyid).first()
    else:
        key = db.Key.query.filter(db.Key.uid.ilike("%{}%".format(keyid))).first()
    if key:
        if key.armored:
            cache.setex(keyid + "-armor", 60*60*24, key.armored)
            return key.armored
        else:
            return ""
    else: return None

def get_pgp_keyinfo(keyid: str) -> keyinfo.KeyInfo:
    """
    Gets a :skier.keyinfo.KeyInfo: object for the specified key.
    :param keyid: The ID of the key to lookup.
    :return: A new :skier.keyinfo.KeyInfo: object for the key.
    """
    key = db.Key.query.filter(db.Key.key_fp_id == keyid).first()
    if key:

        return keyinfo.KeyInfo.from_database_object(key)