@@ -11,6 +11,7 @@ extern VALUE rb_mRugged;
11
11
VALUE rb_mRuggedCred ;
12
12
VALUE rb_cRuggedCredUserPassword ;
13
13
VALUE rb_cRuggedCredSshKey ;
14
+ VALUE rb_cRuggedCredSshKeyFromMemory ;
14
15
VALUE rb_cRuggedCredSshKeyFromAgent ;
15
16
VALUE rb_cRuggedCredDefault ;
16
17
@@ -55,6 +56,31 @@ static void rugged_cred_extract_ssh_key(git_cred **cred, VALUE rb_credential)
55
56
);
56
57
}
57
58
59
+ static void rugged_cred_extract_ssh_key_from_memory (git_cred * * cred , VALUE rb_credential )
60
+ {
61
+ VALUE rb_username = rb_iv_get (rb_credential , "@username" );
62
+ VALUE rb_publickey = rb_iv_get (rb_credential , "@publickey" );
63
+ VALUE rb_privatekey = rb_iv_get (rb_credential , "@privatekey" );
64
+ VALUE rb_passphrase = rb_iv_get (rb_credential , "@passphrase" );
65
+
66
+ Check_Type (rb_username , T_STRING );
67
+ Check_Type (rb_privatekey , T_STRING );
68
+
69
+ if (!NIL_P (rb_publickey ))
70
+ Check_Type (rb_publickey , T_STRING );
71
+ if (!NIL_P (rb_passphrase ))
72
+ Check_Type (rb_passphrase , T_STRING );
73
+
74
+ rugged_exception_check (
75
+ git_cred_ssh_key_memory_new (cred ,
76
+ StringValueCStr (rb_username ),
77
+ NIL_P (rb_publickey ) ? NULL : StringValueCStr (rb_publickey ),
78
+ StringValueCStr (rb_privatekey ),
79
+ NIL_P (rb_passphrase ) ? NULL : StringValueCStr (rb_passphrase )
80
+ )
81
+ );
82
+ }
83
+
58
84
static void rugged_credential_extract_ssh_key_from_agent (git_cred * * cred , VALUE rb_credential )
59
85
{
60
86
VALUE rb_username = rb_iv_get (rb_credential , "@username" );
@@ -101,6 +127,16 @@ void rugged_cred_extract(git_cred **cred, int allowed_types, VALUE rb_credential
101
127
rb_raise (rb_eArgError , "Invalid credential type" );
102
128
103
129
rugged_cred_extract_ssh_key (cred , rb_credential );
130
+ } else if (rb_obj_is_kind_of (rb_credential , rb_cRuggedCredSshKeyFromMemory )) {
131
+ if (allowed_types & GIT_CREDTYPE_USERNAME ) {
132
+ rugged_cred_extract_username (cred , rb_credential );
133
+ return ;
134
+ }
135
+
136
+ if (!(allowed_types & GIT_CREDTYPE_SSH_KEY ))
137
+ rb_raise (rb_eArgError , "Invalid credential type" );
138
+
139
+ rugged_cred_extract_ssh_key_from_memory (cred , rb_credential );
104
140
} else if (rb_obj_is_kind_of (rb_credential , rb_cRuggedCredSshKeyFromAgent )) {
105
141
if (allowed_types & GIT_CREDTYPE_USERNAME ) {
106
142
rugged_cred_extract_username (cred , rb_credential );
@@ -122,10 +158,11 @@ void rugged_cred_extract(git_cred **cred, int allowed_types, VALUE rb_credential
122
158
123
159
void Init_rugged_cred (void )
124
160
{
125
- rb_mRuggedCred = rb_define_module_under (rb_mRugged , "Credentials" );
161
+ rb_mRuggedCred = rb_define_module_under (rb_mRugged , "Credentials" );
126
162
127
- rb_cRuggedCredUserPassword = rb_define_class_under (rb_mRuggedCred , "UserPassword" , rb_cObject );
128
- rb_cRuggedCredSshKey = rb_define_class_under (rb_mRuggedCred , "SshKey" , rb_cObject );
129
- rb_cRuggedCredSshKeyFromAgent = rb_define_class_under (rb_mRuggedCred , "SshKeyFromAgent" , rb_cObject );
130
- rb_cRuggedCredDefault = rb_define_class_under (rb_mRuggedCred , "Default" , rb_cObject );
163
+ rb_cRuggedCredUserPassword = rb_define_class_under (rb_mRuggedCred , "UserPassword" , rb_cObject );
164
+ rb_cRuggedCredSshKey = rb_define_class_under (rb_mRuggedCred , "SshKey" , rb_cObject );
165
+ rb_cRuggedCredSshKeyFromMemory = rb_define_class_under (rb_mRuggedCred , "SshKeyFromMemory" , rb_cObject );
166
+ rb_cRuggedCredSshKeyFromAgent = rb_define_class_under (rb_mRuggedCred , "SshKeyFromAgent" , rb_cObject );
167
+ rb_cRuggedCredDefault = rb_define_class_under (rb_mRuggedCred , "Default" , rb_cObject );
131
168
}
0 commit comments