Add NewCredSshKeyFromMemory to the credentials helpers.
Allowing to use public and private keys from memory without reading them from disk and without using an ssh agent. Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
8eaae73f85
commit
a2f93e91d2
|
@ -44,13 +44,15 @@ func NewCredUserpassPlaintext(username string, password string) (int, Cred) {
|
||||||
return int(ret), 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{}
|
cred := Cred{}
|
||||||
cusername := C.CString(username)
|
cusername := C.CString(username)
|
||||||
defer C.free(unsafe.Pointer(cusername))
|
defer C.free(unsafe.Pointer(cusername))
|
||||||
cpublickey := C.CString(publickey)
|
cpublickey := C.CString(publicKeyPath)
|
||||||
defer C.free(unsafe.Pointer(cpublickey))
|
defer C.free(unsafe.Pointer(cpublickey))
|
||||||
cprivatekey := C.CString(privatekey)
|
cprivatekey := C.CString(privateKeyPath)
|
||||||
defer C.free(unsafe.Pointer(cprivatekey))
|
defer C.free(unsafe.Pointer(cprivatekey))
|
||||||
cpassphrase := C.CString(passphrase)
|
cpassphrase := C.CString(passphrase)
|
||||||
defer C.free(unsafe.Pointer(cpassphrase))
|
defer C.free(unsafe.Pointer(cpassphrase))
|
||||||
|
@ -58,6 +60,22 @@ func NewCredSshKey(username string, publickey string, privatekey string, passphr
|
||||||
return int(ret), cred
|
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) {
|
func NewCredSshKeyFromAgent(username string) (int, Cred) {
|
||||||
cred := Cred{}
|
cred := Cred{}
|
||||||
cusername := C.CString(username)
|
cusername := C.CString(username)
|
||||||
|
|
Loading…
Reference in New Issue