Skip to content

Commit 2209188

Browse files
authored
Merge pull request libgit2#322 from calavera/ssh_memory_credentials
Add NewCredSshKeyFromMemory to the credentials helpers.
2 parents a3c2ac1 + a2f93e9 commit 2209188

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

credentials.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,38 @@ func NewCredUserpassPlaintext(username string, password string) (int, Cred) {
4444
return int(ret), cred
4545
}
4646

47-
func NewCredSshKey(username string, publickey string, privatekey string, passphrase string) (int, Cred) {
47+
// NewCredSshKey creates new ssh credentials reading the public and private keys
48+
// from the file system.
49+
func NewCredSshKey(username string, publicKeyPath string, privateKeyPath string, passphrase string) (int, Cred) {
4850
cred := Cred{}
4951
cusername := C.CString(username)
5052
defer C.free(unsafe.Pointer(cusername))
51-
cpublickey := C.CString(publickey)
53+
cpublickey := C.CString(publicKeyPath)
5254
defer C.free(unsafe.Pointer(cpublickey))
53-
cprivatekey := C.CString(privatekey)
55+
cprivatekey := C.CString(privateKeyPath)
5456
defer C.free(unsafe.Pointer(cprivatekey))
5557
cpassphrase := C.CString(passphrase)
5658
defer C.free(unsafe.Pointer(cpassphrase))
5759
ret := C.git_cred_ssh_key_new(&cred.ptr, cusername, cpublickey, cprivatekey, cpassphrase)
5860
return int(ret), cred
5961
}
6062

63+
// NewCredSshKeyFromMemory creates new ssh credentials using the publicKey and privateKey
64+
// arguments as the values for the public and private keys.
65+
func NewCredSshKeyFromMemory(username string, publicKey string, privateKey string, passphrase string) (int, Cred) {
66+
cred := Cred{}
67+
cusername := C.CString(username)
68+
defer C.free(unsafe.Pointer(cusername))
69+
cpublickey := C.CString(publicKey)
70+
defer C.free(unsafe.Pointer(cpublickey))
71+
cprivatekey := C.CString(privateKey)
72+
defer C.free(unsafe.Pointer(cprivatekey))
73+
cpassphrase := C.CString(passphrase)
74+
defer C.free(unsafe.Pointer(cpassphrase))
75+
ret := C.git_cred_ssh_key_memory_new(&cred.ptr, cusername, cpublickey, cprivatekey, cpassphrase)
76+
return int(ret), cred
77+
}
78+
6179
func NewCredSshKeyFromAgent(username string) (int, Cred) {
6280
cred := Cred{}
6381
cusername := C.CString(username)

0 commit comments

Comments
 (0)