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