| 379 | |
| 380 | template<typename Reader> |
| 381 | Try<shared_ptr<RSA>> pem_to_rsa(const string& pem, Reader reader) |
| 382 | { |
| 383 | // We cast away constness from `pem`'s data since in older SSL versions |
| 384 | // `BIO_new_mem_buf` took a non-const `char*` which was semantically `const`. |
| 385 | BIO *bio = BIO_new_mem_buf(const_cast<char*>(pem.c_str()), -1); |
| 386 | if (bio == nullptr) { |
| 387 | return Error("Failed to create RSA key bio"); |
| 388 | } |
| 389 | RSA *rsa = reader(bio, nullptr, nullptr, nullptr); |
| 390 | BIO_free(bio); |
| 391 | if (rsa == nullptr) { |
| 392 | return Error("Failed to create RSA from key bio"); |
| 393 | } |
| 394 | return shared_ptr<RSA>(rsa, RSA_free); |
| 395 | } |
| 396 | |
| 397 | |
| 398 | Try<shared_ptr<RSA>> pem_to_rsa_private_key(const string& pem) |
no outgoing calls
no test coverage detected