summaryrefslogtreecommitdiff
path: root/src/node_crypto_bio.cc
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-07-26 12:53:23 +0200
committerJames M Snell <jasnell@gmail.com>2018-08-12 03:58:37 -0700
commit987dc0711137685dabf472ad8e137ad365013557 (patch)
tree7651fa254f38f4d5cacf87454b15e1d0f29f85f3 /src/node_crypto_bio.cc
parent83ab3bfedaedb13e16b8499c1d61dd21b2956e99 (diff)
downloadnode-new-987dc0711137685dabf472ad8e137ad365013557.tar.gz
src: use smart pointers for NodeBIO
PR-URL: https://github.com/nodejs/node/pull/21984 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_crypto_bio.cc')
-rw-r--r--src/node_crypto_bio.cc26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/node_crypto_bio.cc b/src/node_crypto_bio.cc
index 094bb9cc1f..ab68c0a081 100644
--- a/src/node_crypto_bio.cc
+++ b/src/node_crypto_bio.cc
@@ -38,36 +38,32 @@ namespace crypto {
#endif
-BIO* NodeBIO::New() {
+BIOPointer NodeBIO::New(Environment* env) {
// The const_cast doesn't violate const correctness. OpenSSL's usage of
// BIO_METHOD is effectively const but BIO_new() takes a non-const argument.
- return BIO_new(const_cast<BIO_METHOD*>(GetMethod()));
+ BIOPointer bio(BIO_new(const_cast<BIO_METHOD*>(GetMethod())));
+ if (bio && env != nullptr)
+ NodeBIO::FromBIO(bio.get())->env_ = env;
+ return bio;
}
-BIO* NodeBIO::NewFixed(const char* data, size_t len) {
- BIO* bio = New();
+BIOPointer NodeBIO::NewFixed(const char* data, size_t len, Environment* env) {
+ BIOPointer bio = New(env);
- if (bio == nullptr ||
+ if (!bio ||
len > INT_MAX ||
- BIO_write(bio, data, len) != static_cast<int>(len) ||
- BIO_set_mem_eof_return(bio, 0) != 1) {
- BIO_free(bio);
- return nullptr;
+ BIO_write(bio.get(), data, len) != static_cast<int>(len) ||
+ BIO_set_mem_eof_return(bio.get(), 0) != 1) {
+ return BIOPointer();
}
return bio;
}
-void NodeBIO::AssignEnvironment(Environment* env) {
- env_ = env;
-}
-
-
int NodeBIO::New(BIO* bio) {
BIO_set_data(bio, new NodeBIO());
-
BIO_set_init(bio, 1);
return 1;