def __string_to_cert(s, pkg_hash=None):
"""Convert a string to a X509 cert."""
try:
return x509.load_pem_x509_certificate(
misc.force_bytes(s), default_backend())
except ValueError:
if pkg_hash is not None:
raise api_errors.BadFileFormat(_("The file "
"with hash {0} was expected to be a PEM "
"certificate but it could not be "
"read.").format(pkg_hash))
raise api_errors.BadFileFormat(_("The following string "
"was expected to be a PEM certificate, but it "
"could not be parsed as such:\n{0}".format(s)))
评论列表
文章目录