Browse Source

crypto: export externals to internal structs

Export External getters for a internal structs: SSL, SSL_CTX.
v0.11.14-release
Fedor Indutny 10 years ago
parent
commit
6e08bb94e8
  1. 32
      src/node_crypto.cc
  2. 4
      src/node_crypto.h
  3. 15
      src/node_internals.h

32
src/node_crypto.cc

@ -81,6 +81,7 @@ using v8::Boolean;
using v8::Context; using v8::Context;
using v8::EscapableHandleScope; using v8::EscapableHandleScope;
using v8::Exception; using v8::Exception;
using v8::External;
using v8::False; using v8::False;
using v8::FunctionCallbackInfo; using v8::FunctionCallbackInfo;
using v8::FunctionTemplate; using v8::FunctionTemplate;
@ -286,6 +287,11 @@ void SecureContext::Initialize(Environment* env, Handle<Object> target) {
"getIssuer", "getIssuer",
SecureContext::GetCertificate<false>); SecureContext::GetCertificate<false>);
NODE_SET_EXTERNAL(
t->PrototypeTemplate(),
"_external",
CtxGetter);
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "SecureContext"), target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "SecureContext"),
t->GetFunction()); t->GetFunction());
env->set_secure_context_constructor_template(t); env->set_secure_context_constructor_template(t);
@ -956,6 +962,16 @@ void SecureContext::SetTicketKeys(const FunctionCallbackInfo<Value>& args) {
} }
void SecureContext::CtxGetter(Local<String> property,
const PropertyCallbackInfo<Value>& info) {
HandleScope scope(info.GetIsolate());
SSL_CTX* ctx = Unwrap<SecureContext>(info.Holder())->ctx_;
Local<External> ext = External::New(info.GetIsolate(), ctx);
info.GetReturnValue().Set(ext);
}
template <bool primary> template <bool primary>
void SecureContext::GetCertificate(const FunctionCallbackInfo<Value>& args) { void SecureContext::GetCertificate(const FunctionCallbackInfo<Value>& args) {
HandleScope scope(args.GetIsolate()); HandleScope scope(args.GetIsolate());
@ -1008,6 +1024,11 @@ void SSLWrap<Base>::AddMethods(Environment* env, Handle<FunctionTemplate> t) {
NODE_SET_PROTOTYPE_METHOD(t, "getNegotiatedProtocol", GetNegotiatedProto); NODE_SET_PROTOTYPE_METHOD(t, "getNegotiatedProtocol", GetNegotiatedProto);
NODE_SET_PROTOTYPE_METHOD(t, "setNPNProtocols", SetNPNProtocols); NODE_SET_PROTOTYPE_METHOD(t, "setNPNProtocols", SetNPNProtocols);
#endif // OPENSSL_NPN_NEGOTIATED #endif // OPENSSL_NPN_NEGOTIATED
NODE_SET_EXTERNAL(
t->PrototypeTemplate(),
"_external",
SSLGetter);
} }
@ -1846,6 +1867,17 @@ int SSLWrap<Base>::TLSExtStatusCallback(SSL* s, void* arg) {
#endif // NODE__HAVE_TLSEXT_STATUS_CB #endif // NODE__HAVE_TLSEXT_STATUS_CB
template <class Base>
void SSLWrap<Base>::SSLGetter(Local<String> property,
const PropertyCallbackInfo<Value>& info) {
HandleScope scope(info.GetIsolate());
SSL* ssl = Unwrap<Base>(info.Holder())->ssl_;
Local<External> ext = External::New(info.GetIsolate(), ssl);
info.GetReturnValue().Set(ext);
}
void Connection::OnClientHelloParseEnd(void* arg) { void Connection::OnClientHelloParseEnd(void* arg) {
Connection* conn = static_cast<Connection*>(arg); Connection* conn = static_cast<Connection*>(arg);

4
src/node_crypto.h

@ -105,6 +105,8 @@ class SecureContext : public BaseObject {
static void LoadPKCS12(const v8::FunctionCallbackInfo<v8::Value>& args); static void LoadPKCS12(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetTicketKeys(const v8::FunctionCallbackInfo<v8::Value>& args); static void GetTicketKeys(const v8::FunctionCallbackInfo<v8::Value>& args);
static void SetTicketKeys(const v8::FunctionCallbackInfo<v8::Value>& args); static void SetTicketKeys(const v8::FunctionCallbackInfo<v8::Value>& args);
static void CtxGetter(v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value>& info);
template <bool primary> template <bool primary>
static void GetCertificate(const v8::FunctionCallbackInfo<v8::Value>& args); static void GetCertificate(const v8::FunctionCallbackInfo<v8::Value>& args);
@ -237,6 +239,8 @@ class SSLWrap {
void* arg); void* arg);
#endif // OPENSSL_NPN_NEGOTIATED #endif // OPENSSL_NPN_NEGOTIATED
static int TLSExtStatusCallback(SSL* s, void* arg); static int TLSExtStatusCallback(SSL* s, void* arg);
static void SSLGetter(v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value>& info);
inline Environment* ssl_env() const { inline Environment* ssl_env() const {
return env_; return env_;

15
src/node_internals.h

@ -216,6 +216,21 @@ NODE_DEPRECATED("Use ThrowUVException(isolate)",
return ThrowUVException(isolate, errorno, syscall, message, path); return ThrowUVException(isolate, errorno, syscall, message, path);
}) })
inline void NODE_SET_EXTERNAL(v8::Handle<v8::ObjectTemplate> target,
const char* key,
v8::AccessorGetterCallback getter) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope handle_scope(isolate);
v8::Local<v8::String> prop = v8::String::NewFromUtf8(isolate, key);
target->SetAccessor(prop,
getter,
NULL,
v8::Handle<v8::Value>(),
v8::DEFAULT,
static_cast<v8::PropertyAttribute>(v8::ReadOnly |
v8::DontDelete));
}
} // namespace node } // namespace node
#endif // SRC_NODE_INTERNALS_H_ #endif // SRC_NODE_INTERNALS_H_

Loading…
Cancel
Save