8000 Merge pull request #507 from slavikus/master · libgit2/objective-git@f26c5c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit f26c5c2

Browse files
committed
Merge pull request #507 from slavikus/master
Added support for git_cred_ssh_key_memory_new GTCredentials
2 parents bde1713 + 3fc761a commit f26c5c2

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

ObjectiveGit/GTCredential.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ NS_ASSUME_NONNULL_BEGIN
7474
/// Return a new GTCredential instance, or nil if an error occurred
7575
+ (nullable instancetype)credentialWithUserName:(NSString *)userName publicKeyURL:(nullable NSURL *)publicKeyURL privateKeyURL:(NSURL *)privateKeyURL passphrase:(nullable NSString *)passphrase error:(NSError **)error;
7676

77+
/// Create a credential object from a SSH keyfile data string
78+
///
79+
/// userName - The username to authenticate as.
80+
/// publicKeyString - The string containing the public key for that user.
81+
/// Can be omitted to reconstruct the public key from the private key.
82+
/// privateKeyString - The URL to the private key for that user.
83+
/// passphrase - The passPhrase for the private key. Optional if the private key has no password.
84+
/// error - If not NULL, set to any errors that occur.
85+
///
86+
/// Return a new GTCredential instance, or nil if an error occurred
87+
+ (nullable instancetype)credentialWithUserName:(NSString *)userName publicKeyString:(nullable NSString *)publicKeyString privateKeyString:(NSString *)privateKeyString passphrase:(nullable NSString *)passphrase error:(NSError **)error;
88+
7789
/// The underlying `git_cred` object.
7890
- (git_cred *)git_cred __attribute__((objc_returns_inner_pointer));
7991

ObjectiveGit/GTCredential.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ + (instancetype)credentialWithUserName:(NSString *)userName publicKeyURL:(NSURL
7171
return [[self alloc] initWithGitCred:cred];
7272
}
7373

74+
+ (instancetype)credentialWithUserName:(NSString *)userName publicKeyString:(NSString *)publicKeyString privateKeyString:(NSString *)privateKeyString passphrase:(NSString *)passphrase error:(NSError **)error {
75+
NSParameterAssert(privateKeyString != nil);
76+
77+
git_cred *cred;
78+
int gitError = git_cred_ssh_key_memory_new(&cred, userName.UTF8String, publicKeyString.UTF8String, privateKeyString.UTF8String, passphrase.UTF8String);
79+
if (gitError != GIT_OK) {
80+
if (error) *error = [NSError git_errorFor:gitError description:@"Failed to create credentials object" failureReason:@"There was an error creating a credential object for username %@ with the provided public/private key pair.\nPublic key: %@\nPrivate key: %@", userName, publicKeyString, privateKeyString];
81+
return nil;
82+
}
83+
84+
return [[self alloc] initWithGitCred:cred];
85+
}
86+
7487
- (instancetype)initWithGitCred:(git_cred *)cred {
7588
NSParameterAssert(cred != nil);
7689
self = [self init];

0 commit comments

Comments
 (0)
0