@@ -11,6 +11,7 @@ extern VALUE rb_mRugged;
1111VALUE rb_mRuggedCred ;
1212VALUE rb_cRuggedCredUserPassword ;
1313VALUE rb_cRuggedCredSshKey ;
14+ VALUE rb_cRuggedCredSshKeyFromMemory ;
1415VALUE rb_cRuggedCredSshKeyFromAgent ;
1516VALUE rb_cRuggedCredDefault ;
1617
@@ -55,6 +56,31 @@ static void rugged_cred_extract_ssh_key(git_cred **cred, VALUE rb_credential)
5556 );
5657}
5758
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+
5884static void rugged_credential_extract_ssh_key_from_agent (git_cred * * cred , VALUE rb_credential )
5985{
6086 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
101127 rb_raise (rb_eArgError , "Invalid credential type" );
102128
103129 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 );
104140 } else if (rb_obj_is_kind_of (rb_credential , rb_cRuggedCredSshKeyFromAgent )) {
105141 if (allowed_types & GIT_CREDTYPE_USERNAME ) {
106142 rugged_cred_extract_username (cred , rb_credential );
@@ -122,10 +158,11 @@ void rugged_cred_extract(git_cred **cred, int allowed_types, VALUE rb_credential
122158
123159void Init_rugged_cred (void )
124160{
125- rb_mRuggedCred = rb_define_module_under (rb_mRugged , "Credentials" );
161+ rb_mRuggedCred = rb_define_module_under (rb_mRugged , "Credentials" );
126162
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 );
131168}
0 commit comments