| 310 | |
| 311 | |
| 312 | Try<Nothing> write_key_file(EVP_PKEY* private_key, const Path& path) |
| 313 | { |
| 314 | // We use 'FILE*' here because it is an API requirement by openssl. |
| 315 | FILE* file = fopen(path.string().c_str(), "wb"); |
| 316 | if (file == nullptr) { |
| 317 | return Error("Failed to open file '" + stringify(path) + "' for writing"); |
| 318 | } |
| 319 | |
| 320 | if (PEM_write_PrivateKey( |
| 321 | file, private_key, nullptr, nullptr, 0, nullptr, nullptr) != 1) { |
| 322 | fclose(file); |
| 323 | return Error("Failed to write private key to file '" + stringify(path) + |
| 324 | "': PEM_write_PrivateKey"); |
| 325 | } |
| 326 | |
| 327 | fclose(file); |
| 328 | |
| 329 | return Nothing(); |
| 330 | } |
| 331 | |
| 332 | |
| 333 | Try<Nothing> write_certificate_file(X509* x509, const Path& path) |