code: def get_publickey(keydata):
      
      try:
          key = serialization.load_pem_public_key(
              keydata,
              backend=default_backend(),
          )
          return key
      except ValueError:
          key = serialization.load_pem_private_key(
              keydata,
              password=None,
              backend=default_backend(),
          )
          key = key.public_key()
          return key
docs: Load the public key from a PEM encoded string.