def __make_tmp_cert(d, pth):
try:
with open(pth, "rb") as f:
cert = x509.load_pem_x509_certificate(f.read(),
default_backend())
except (ValueError, IOError) as e:
raise api_errors.BadFileFormat(_("The file {0} was expected to "
"be a PEM certificate but it could not be read.").format(
pth))
fd, fp = tempfile.mkstemp(dir=d)
with os.fdopen(fd, "wb") as fh:
fh.write(cert.public_bytes(serialization.Encoding.PEM))
return fp
评论列表
文章目录