|
|
@ -86,14 +86,21 @@ static void grpc_rb_credentials_mark(void *p) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static rb_data_type_t grpc_rb_credentials_data_type = { |
|
|
|
|
|
|
|
"grpc_credentials", |
|
|
|
|
|
|
|
{grpc_rb_credentials_mark, grpc_rb_credentials_free, |
|
|
|
|
|
|
|
GRPC_RB_MEMSIZE_UNAVAILABLE}, |
|
|
|
|
|
|
|
NULL, |
|
|
|
|
|
|
|
NULL, |
|
|
|
|
|
|
|
RUBY_TYPED_FREE_IMMEDIATELY}; |
|
|
|
|
|
|
|
|
|
|
|
/* Allocates Credential instances.
|
|
|
|
/* Allocates Credential instances.
|
|
|
|
Provides safe initial defaults for the instance fields. */ |
|
|
|
Provides safe initial defaults for the instance fields. */ |
|
|
|
static VALUE grpc_rb_credentials_alloc(VALUE cls) { |
|
|
|
static VALUE grpc_rb_credentials_alloc(VALUE cls) { |
|
|
|
grpc_rb_credentials *wrapper = ALLOC(grpc_rb_credentials); |
|
|
|
grpc_rb_credentials *wrapper = ALLOC(grpc_rb_credentials); |
|
|
|
wrapper->wrapped = NULL; |
|
|
|
wrapper->wrapped = NULL; |
|
|
|
wrapper->mark = Qnil; |
|
|
|
wrapper->mark = Qnil; |
|
|
|
return Data_Wrap_Struct(cls, grpc_rb_credentials_mark, |
|
|
|
return TypedData_Wrap_Struct(cls, &grpc_rb_credentials_data_type, wrapper); |
|
|
|
grpc_rb_credentials_free, wrapper); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Clones Credentials instances.
|
|
|
|
/* Clones Credentials instances.
|
|
|
@ -113,8 +120,10 @@ static VALUE grpc_rb_credentials_init_copy(VALUE copy, VALUE orig) { |
|
|
|
rb_raise(rb_eTypeError, "not a %s", rb_obj_classname(grpc_rb_cCredentials)); |
|
|
|
rb_raise(rb_eTypeError, "not a %s", rb_obj_classname(grpc_rb_cCredentials)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Data_Get_Struct(orig, grpc_rb_credentials, orig_cred); |
|
|
|
TypedData_Get_Struct(orig, grpc_rb_credentials, |
|
|
|
Data_Get_Struct(copy, grpc_rb_credentials, copy_cred); |
|
|
|
&grpc_rb_credentials_data_type, orig_cred); |
|
|
|
|
|
|
|
TypedData_Get_Struct(copy, grpc_rb_credentials, |
|
|
|
|
|
|
|
&grpc_rb_credentials_data_type, copy_cred); |
|
|
|
|
|
|
|
|
|
|
|
/* use ruby's MEMCPY to make a byte-for-byte copy of the credentials
|
|
|
|
/* use ruby's MEMCPY to make a byte-for-byte copy of the credentials
|
|
|
|
* wrapper object. */ |
|
|
|
* wrapper object. */ |
|
|
@ -136,8 +145,7 @@ static VALUE grpc_rb_default_credentials_create(VALUE cls) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
wrapper->mark = Qnil; |
|
|
|
wrapper->mark = Qnil; |
|
|
|
return Data_Wrap_Struct(cls, grpc_rb_credentials_mark, |
|
|
|
return TypedData_Wrap_Struct(cls, &grpc_rb_credentials_data_type, wrapper); |
|
|
|
grpc_rb_credentials_free, wrapper); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
@ -154,8 +162,7 @@ static VALUE grpc_rb_compute_engine_credentials_create(VALUE cls) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
wrapper->mark = Qnil; |
|
|
|
wrapper->mark = Qnil; |
|
|
|
return Data_Wrap_Struct(cls, grpc_rb_credentials_mark, |
|
|
|
return TypedData_Wrap_Struct(cls, &grpc_rb_credentials_data_type, wrapper); |
|
|
|
grpc_rb_credentials_free, wrapper); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
@ -169,8 +176,10 @@ static VALUE grpc_rb_composite_credentials_create(VALUE self, VALUE other) { |
|
|
|
grpc_rb_credentials *other_wrapper = NULL; |
|
|
|
grpc_rb_credentials *other_wrapper = NULL; |
|
|
|
grpc_rb_credentials *wrapper = NULL; |
|
|
|
grpc_rb_credentials *wrapper = NULL; |
|
|
|
|
|
|
|
|
|
|
|
Data_Get_Struct(self, grpc_rb_credentials, self_wrapper); |
|
|
|
TypedData_Get_Struct(self, grpc_rb_credentials, |
|
|
|
Data_Get_Struct(other, grpc_rb_credentials, other_wrapper); |
|
|
|
&grpc_rb_credentials_data_type, self_wrapper); |
|
|
|
|
|
|
|
TypedData_Get_Struct(other, grpc_rb_credentials, |
|
|
|
|
|
|
|
&grpc_rb_credentials_data_type, other_wrapper); |
|
|
|
wrapper = ALLOC(grpc_rb_credentials); |
|
|
|
wrapper = ALLOC(grpc_rb_credentials); |
|
|
|
wrapper->wrapped = grpc_composite_credentials_create(self_wrapper->wrapped, |
|
|
|
wrapper->wrapped = grpc_composite_credentials_create(self_wrapper->wrapped, |
|
|
|
other_wrapper->wrapped); |
|
|
|
other_wrapper->wrapped); |
|
|
@ -181,8 +190,8 @@ static VALUE grpc_rb_composite_credentials_create(VALUE self, VALUE other) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
wrapper->mark = Qnil; |
|
|
|
wrapper->mark = Qnil; |
|
|
|
return Data_Wrap_Struct(grpc_rb_cCredentials, grpc_rb_credentials_mark, |
|
|
|
return TypedData_Wrap_Struct(grpc_rb_cCredentials, |
|
|
|
grpc_rb_credentials_free, wrapper); |
|
|
|
&grpc_rb_credentials_data_type, wrapper); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* The attribute used on the mark object to hold the pem_root_certs. */ |
|
|
|
/* The attribute used on the mark object to hold the pem_root_certs. */ |
|
|
@ -217,7 +226,8 @@ static VALUE grpc_rb_credentials_init(int argc, VALUE *argv, VALUE self) { |
|
|
|
rb_scan_args(argc, argv, "12", &pem_root_certs, &pem_private_key, |
|
|
|
rb_scan_args(argc, argv, "12", &pem_root_certs, &pem_private_key, |
|
|
|
&pem_cert_chain); |
|
|
|
&pem_cert_chain); |
|
|
|
|
|
|
|
|
|
|
|
Data_Get_Struct(self, grpc_rb_credentials, wrapper); |
|
|
|
TypedData_Get_Struct(self, grpc_rb_credentials, |
|
|
|
|
|
|
|
&grpc_rb_credentials_data_type, wrapper); |
|
|
|
if (pem_root_certs == Qnil) { |
|
|
|
if (pem_root_certs == Qnil) { |
|
|
|
rb_raise(rb_eRuntimeError, |
|
|
|
rb_raise(rb_eRuntimeError, |
|
|
|
"could not create a credential: nil pem_root_certs"); |
|
|
|
"could not create a credential: nil pem_root_certs"); |
|
|
@ -228,8 +238,8 @@ static VALUE grpc_rb_credentials_init(int argc, VALUE *argv, VALUE self) { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
key_cert_pair.private_key = RSTRING_PTR(pem_private_key); |
|
|
|
key_cert_pair.private_key = RSTRING_PTR(pem_private_key); |
|
|
|
key_cert_pair.cert_chain = RSTRING_PTR(pem_cert_chain); |
|
|
|
key_cert_pair.cert_chain = RSTRING_PTR(pem_cert_chain); |
|
|
|
creds = grpc_ssl_credentials_create( |
|
|
|
creds = grpc_ssl_credentials_create(RSTRING_PTR(pem_root_certs), |
|
|
|
RSTRING_PTR(pem_root_certs), &key_cert_pair); |
|
|
|
&key_cert_pair); |
|
|
|
} |
|
|
|
} |
|
|
|
if (creds == NULL) { |
|
|
|
if (creds == NULL) { |
|
|
|
rb_raise(rb_eRuntimeError, "could not create a credentials, not sure why"); |
|
|
|
rb_raise(rb_eRuntimeError, "could not create a credentials, not sure why"); |
|
|
@ -253,8 +263,8 @@ void Init_grpc_credentials() { |
|
|
|
rb_define_alloc_func(grpc_rb_cCredentials, grpc_rb_credentials_alloc); |
|
|
|
rb_define_alloc_func(grpc_rb_cCredentials, grpc_rb_credentials_alloc); |
|
|
|
|
|
|
|
|
|
|
|
/* Provides a ruby constructor and support for dup/clone. */ |
|
|
|
/* Provides a ruby constructor and support for dup/clone. */ |
|
|
|
rb_define_method(grpc_rb_cCredentials, "initialize", |
|
|
|
rb_define_method(grpc_rb_cCredentials, "initialize", grpc_rb_credentials_init, |
|
|
|
grpc_rb_credentials_init, -1); |
|
|
|
-1); |
|
|
|
rb_define_method(grpc_rb_cCredentials, "initialize_copy", |
|
|
|
rb_define_method(grpc_rb_cCredentials, "initialize_copy", |
|
|
|
grpc_rb_credentials_init_copy, 1); |
|
|
|
grpc_rb_credentials_init_copy, 1); |
|
|
|
|
|
|
|
|
|
|
@ -277,6 +287,7 @@ void Init_grpc_credentials() { |
|
|
|
/* Gets the wrapped grpc_credentials from the ruby wrapper */ |
|
|
|
/* Gets the wrapped grpc_credentials from the ruby wrapper */ |
|
|
|
grpc_credentials *grpc_rb_get_wrapped_credentials(VALUE v) { |
|
|
|
grpc_credentials *grpc_rb_get_wrapped_credentials(VALUE v) { |
|
|
|
grpc_rb_credentials *wrapper = NULL; |
|
|
|
grpc_rb_credentials *wrapper = NULL; |
|
|
|
Data_Get_Struct(v, grpc_rb_credentials, wrapper); |
|
|
|
TypedData_Get_Struct(v, grpc_rb_credentials, &grpc_rb_credentials_data_type, |
|
|
|
|
|
|
|
wrapper); |
|
|
|
return wrapper->wrapped; |
|
|
|
return wrapper->wrapped; |
|
|
|
} |
|
|
|
} |
|
|
|