from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.backends import default_backend
import jwt


def decoder(encoded, public_key):
# generate private/public key pair
    # key = rsa.generate_private_key(backend=default_backend(), public_exponent=65537, \
    #     key_size=2048)

    # # get public key in OpenSSH format
    # public_key = key.public_key().public_bytes(serialization.Encoding.OpenSSH, \
    #     serialization.PublicFormat.OpenSSH)

    # # get private key in PEM container format
    # pem = key.private_bytes(encoding=serialization.Encoding.PEM,
    #     format=serialization.PrivateFormat.TraditionalOpenSSL,
    #     encryption_algorithm=serialization.NoEncryption())

    # # decode to printable strings
    # private_key_str = pem.decode('utf-8')
    # public_key_str = public_key.decode('utf-8')


    # encoded = jwt.encode({"some":"payload"}, private_key_str, algorithm='RS256')

    decoded = jwt.decode(encoded, public_key, algorithms=["RS256"])

    print("successfully decoded")
    
    return {"status":"success"}