summaryrefslogtreecommitdiff
path: root/credentials.go
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2016-10-03 02:39:58 -0700
committerGitHub <[email protected]>2016-10-03 02:39:58 -0700
commit22091886372e73de5d66168e8665775676ec13c5 (patch)
treee568103a7aded4ef753ce794948948a9dc831b0c /credentials.go
parenta3c2ac18dc9bbb4d98f335fd74b65603c9f90295 (diff)
parenta2f93e91d253d9ac29e666fd7d3d9508a2b23134 (diff)
Merge pull request #322 from calavera/ssh_memory_credentials
Add NewCredSshKeyFromMemory to the credentials helpers.
Diffstat (limited to 'credentials.go')
-rw-r--r--credentials.go24
1 files changed, 21 insertions, 3 deletions
diff --git a/credentials.go b/credentials.go
index bb0ec41..4e42b6e 100644
--- a/credentials.go
+++ b/credentials.go
@@ -44,13 +44,15 @@ func NewCredUserpassPlaintext(username string, password string) (int, Cred) {
return int(ret), cred
}
-func NewCredSshKey(username string, publickey string, privatekey string, passphrase string) (int, Cred) {
+// NewCredSshKey creates new ssh credentials reading the public and private keys
+// from the file system.
+func NewCredSshKey(username string, publicKeyPath string, privateKeyPath string, passphrase string) (int, Cred) {
cred := Cred{}
cusername := C.CString(username)
defer C.free(unsafe.Pointer(cusername))
- cpublickey := C.CString(publickey)
+ cpublickey := C.CString(publicKeyPath)
defer C.free(unsafe.Pointer(cpublickey))
- cprivatekey := C.CString(privatekey)
+ cprivatekey := C.CString(privateKeyPath)
defer C.free(unsafe.Pointer(cprivatekey))
cpassphrase := C.CString(passphrase)
defer C.free(unsafe.Pointer(cpassphrase))
@@ -58,6 +60,22 @@ func NewCredSshKey(username string, publickey string, privatekey string, passphr
return int(ret), cred
}
+// NewCredSshKeyFromMemory creates new ssh credentials using the publicKey and privateKey
+// arguments as the values for the public and private keys.
+func NewCredSshKeyFromMemory(username string, publicKey string, privateKey string, passphrase string) (int, Cred) {
+ cred := Cred{}
+ cusername := C.CString(username)
+ defer C.free(unsafe.Pointer(cusername))
+ cpublickey := C.CString(publicKey)
+ defer C.free(unsafe.Pointer(cpublickey))
+ cprivatekey := C.CString(privateKey)
+ defer C.free(unsafe.Pointer(cprivatekey))
+ cpassphrase := C.CString(passphrase)
+ defer C.free(unsafe.Pointer(cpassphrase))
+ ret := C.git_cred_ssh_key_memory_new(&cred.ptr, cusername, cpublickey, cprivatekey, cpassphrase)
+ return int(ret), cred
+}
+
func NewCredSshKeyFromAgent(username string) (int, Cred) {
cred := Cred{}
cusername := C.CString(username)