我正在使用 libgit2 库以 swift 语言克隆 iOS 中的存储库。我可以通过传递用户名和密码来克隆存储库
internal func credentialsCallback(
cred: UnsafeMutablePointer<UnsafeMutablePointer<git_cred>?>?,
url: UnsafePointer<CChar>?,
username: UnsafePointer<CChar>?,
_: UInt32,
payload: UnsafeMutableRawPointer? ) -> Int32 {
let result: Int32
// Find username_from_url
let name = username.map(String.init(cString:))
switch Credentials.fromPointer(payload!) ?? .default{
case .default:
result = git_cred_default_new(cred)
case .sshAgent:
result = git_cred_ssh_key_from_agent(cred, name!)
case .plaintext(let username, let password):
result = git_cred_userpass_plaintext_new(cred, username, password)
case .sshMemory(let username, let publicKey, let privateKey, let passphrase):
result = git_cred_ssh_key_memory_new(cred, username, publicKey, privateKey, passphrase)
}
return (result != GIT_OK.rawValue) ? -1 : 0
}
如果我使用纯文本并提供用户名、密码以及类似https://myUserName@bitbucket.org/name/repo.git
. 但是,如果我尝试使用 sshgit@bitbucket.org:name/repo.git
和 sshMemory 获取相同的存储库,其中我提供了用户名、公钥和私钥,那么它就无法正常工作。
let creds = Credentials.sshMemory(username: userName, publicKey: pubkeyData, privateKey: privateKeyData, passphrase: "mypassphrase")
不管用。
有人用 libgit2 尝试过 SSH 吗?