diff options
| author | lhchavez <[email protected]> | 2021-09-05 17:04:40 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-09-05 17:04:40 -0700 |
| commit | 70e5e419cf0cab31553b106267a0296f3cd672d9 (patch) | |
| tree | b8bed08c5cc6236e542f09c18d3823e34e161968 /credentials.go | |
| parent | b983e1daebf528443e2a3954cd595fa3664ec93f (diff) | |
Add support for managed SSH transport #minor (#814)
This change drops the (hard) dependency on libssh2 and instead uses Go's
implementation of SSH when libgit2 is not built with it.
Diffstat (limited to 'credentials.go')
| -rw-r--r-- | credentials.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/credentials.go b/credentials.go index 273de2f..2fb65d5 100644 --- a/credentials.go +++ b/credentials.go @@ -120,6 +120,21 @@ func (o *Credential) GetUserpassPlaintext() (username, password string, err erro return } +// GetSSHKey returns the SSH-specific key information from the Cred object. +func (o *Credential) GetSSHKey() (username, publickey, privatekey, passphrase string, err error) { + if o.Type() != CredentialTypeSSHKey && o.Type() != CredentialTypeSSHMemory { + err = fmt.Errorf("credential is not an SSH key: %v", o.Type()) + return + } + + sshKeyCredPtr := (*C.git_cred_ssh_key)(unsafe.Pointer(o.ptr)) + username = C.GoString(sshKeyCredPtr.username) + publickey = C.GoString(sshKeyCredPtr.publickey) + privatekey = C.GoString(sshKeyCredPtr.privatekey) + passphrase = C.GoString(sshKeyCredPtr.passphrase) + return +} + func NewCredentialUsername(username string) (*Credential, error) { runtime.LockOSThread() defer runtime.UnlockOSThread() |
