Uninett / drf-oidc-auth

OpenID Connect authentication for Django REST Framework
MIT License
0 stars 0 forks source link

Simplify public key extraction #14

Open stveit opened 8 months ago

stveit commented 8 months ago

I think its possible to replace this:

def get_public_key(key):
    """Returns public key for a RSAKey object"""
    public_key = key.get_public_key().public_bytes(
        encoding=crypto_serialization.Encoding.PEM,
        format= crypto_serialization.PublicFormat.SubjectPublicKeyInfo,
    ).decode("utf-8")
    return public_key

with this:

def get_public_key(key):
    """Returns public key for a RSAKey object"""
    public_key = key.as_bytes(is_private=False).decode("utf-8")
    return public_key

based on this working to extract private key in PEM format from a RSAKey object with:

private_key.as_bytes(is_private=True).decode("utf-8")