@@ -104,7 +104,7 @@ ParseKeyResult TryParsePublicKey(EVPKeyPointer* pkey,
104104ParseKeyResult ParsePublicKeyPEM (EVPKeyPointer* pkey,
105105 const char * key_pem,
106106 int key_pem_len) {
107- BIOPointer bp ( BIO_new_mem_buf ( const_cast < char *>( key_pem) , key_pem_len) );
107+ auto bp = BIOPointer::New ( key_pem, key_pem_len);
108108 if (!bp)
109109 return ParseKeyResult::kParseKeyFailed ;
110110
@@ -119,7 +119,7 @@ ParseKeyResult ParsePublicKeyPEM(EVPKeyPointer* pkey,
119119 return ret;
120120
121121 // Maybe it is PKCS#1.
122- CHECK (BIO_reset ( bp.get () ));
122+ CHECK (bp.resetBio ( ));
123123 ret = TryParsePublicKey (pkey, bp, " RSA PUBLIC KEY" ,
124124 [](const unsigned char ** p, long l) { // NOLINT(runtime/int)
125125 return d2i_PublicKey (EVP_PKEY_RSA, nullptr , p, l);
@@ -128,7 +128,7 @@ ParseKeyResult ParsePublicKeyPEM(EVPKeyPointer* pkey,
128128 return ret;
129129
130130 // X.509 fallback.
131- CHECK (BIO_reset ( bp.get () ));
131+ CHECK (bp.resetBio ( ));
132132 return TryParsePublicKey (pkey, bp, " CERTIFICATE" ,
133133 [](const unsigned char ** p, long l) { // NOLINT(runtime/int)
134134 X509Pointer x509 (d2i_X509 (nullptr , p, l));
@@ -218,7 +218,7 @@ ParseKeyResult ParsePrivateKey(EVPKeyPointer* pkey,
218218 const ByteSource* passphrase = config.passphrase_ .get ();
219219
220220 if (config.format_ == kKeyFormatPEM ) {
221- BIOPointer bio ( BIO_new_mem_buf ( key, key_len) );
221+ auto bio = BIOPointer::New ( key, key_len);
222222 if (!bio)
223223 return ParseKeyResult::kParseKeyFailed ;
224224
@@ -233,7 +233,7 @@ ParseKeyResult ParsePrivateKey(EVPKeyPointer* pkey,
233233 const unsigned char * p = reinterpret_cast <const unsigned char *>(key);
234234 pkey->reset (d2i_PrivateKey (EVP_PKEY_RSA, nullptr , &p, key_len));
235235 } else if (config.type_ .ToChecked () == kKeyEncodingPKCS8 ) {
236- BIOPointer bio ( BIO_new_mem_buf ( key, key_len) );
236+ auto bio = BIOPointer::New ( key, key_len);
237237 if (!bio)
238238 return ParseKeyResult::kParseKeyFailed ;
239239
@@ -270,12 +270,10 @@ ParseKeyResult ParsePrivateKey(EVPKeyPointer* pkey,
270270 return ParseKeyResult::kParseKeyFailed ;
271271}
272272
273- MaybeLocal<Value> BIOToStringOrBuffer (
274- Environment* env,
275- BIO* bio,
276- PKFormatType format) {
277- BUF_MEM* bptr;
278- BIO_get_mem_ptr (bio, &bptr);
273+ MaybeLocal<Value> BIOToStringOrBuffer (Environment* env,
274+ const BIOPointer& bio,
275+ PKFormatType format) {
276+ BUF_MEM* bptr = bio;
279277 if (format == kKeyFormatPEM ) {
280278 // PEM is an ASCII format, so we will return it as a string.
281279 return String::NewFromUtf8 (env->isolate (), bptr->data ,
@@ -292,7 +290,7 @@ MaybeLocal<Value> BIOToStringOrBuffer(
292290MaybeLocal<Value> WritePrivateKey (Environment* env,
293291 OSSL3_CONST EVP_PKEY* pkey,
294292 const PrivateKeyEncodingConfig& config) {
295- BIOPointer bio ( BIO_new ( BIO_s_mem ()) );
293+ auto bio = BIOPointer::NewMem ( );
296294 CHECK (bio);
297295
298296 // If an empty string was passed as the passphrase, the ByteSource might
@@ -388,7 +386,7 @@ MaybeLocal<Value> WritePrivateKey(Environment* env,
388386 ThrowCryptoError (env, ERR_get_error (), " Failed to encode private key" );
389387 return MaybeLocal<Value>();
390388 }
391- return BIOToStringOrBuffer (env, bio. get () , config.format_ );
389+ return BIOToStringOrBuffer (env, bio, config.format_ );
392390}
393391
394392bool WritePublicKeyInner (OSSL3_CONST EVP_PKEY* pkey,
@@ -422,14 +420,14 @@ bool WritePublicKeyInner(OSSL3_CONST EVP_PKEY* pkey,
422420MaybeLocal<Value> WritePublicKey (Environment* env,
423421 OSSL3_CONST EVP_PKEY* pkey,
424422 const PublicKeyEncodingConfig& config) {
425- BIOPointer bio ( BIO_new ( BIO_s_mem ()) );
423+ auto bio = BIOPointer::NewMem ( );
426424 CHECK (bio);
427425
428426 if (!WritePublicKeyInner (pkey, bio, config)) {
429427 ThrowCryptoError (env, ERR_get_error (), " Failed to encode public key" );
430428 return MaybeLocal<Value>();
431429 }
432- return BIOToStringOrBuffer (env, bio. get () , config.format_ );
430+ return BIOToStringOrBuffer (env, bio, config.format_ );
433431}
434432
435433Maybe<void > ExportJWKSecretKey (Environment* env,
@@ -1448,7 +1446,7 @@ WebCryptoKeyExportStatus PKEY_SPKI_Export(
14481446 CHECK_EQ (key_data->GetKeyType (), kKeyTypePublic );
14491447 ManagedEVPPKey m_pkey = key_data->GetAsymmetricKey ();
14501448 Mutex::ScopedLock lock (*m_pkey.mutex ());
1451- BIOPointer bio ( BIO_new ( BIO_s_mem ()) );
1449+ auto bio = BIOPointer::NewMem ( );
14521450 CHECK (bio);
14531451 if (!i2d_PUBKEY_bio (bio.get (), m_pkey.get ()))
14541452 return WebCryptoKeyExportStatus::FAILED;
@@ -1464,7 +1462,7 @@ WebCryptoKeyExportStatus PKEY_PKCS8_Export(
14641462 ManagedEVPPKey m_pkey = key_data->GetAsymmetricKey ();
14651463 Mutex::ScopedLock lock (*m_pkey.mutex ());
14661464
1467- BIOPointer bio ( BIO_new ( BIO_s_mem ()) );
1465+ auto bio = BIOPointer::NewMem ( );
14681466 CHECK (bio);
14691467 PKCS8Pointer p8inf (EVP_PKEY2PKCS8 (m_pkey.get ()));
14701468 if (!i2d_PKCS8_PRIV_KEY_INFO_bio (bio.get (), p8inf.get ()))
0 commit comments