|
| 1 | +using System; |
| 2 | +using LibGit2Sharp.Core; |
| 3 | + |
| 4 | +namespace LibGit2Sharp |
| 5 | +{ |
| 6 | + /// <summary> |
| 7 | + /// Class that holds ssh username with key credentials for remote repository access. |
| 8 | + /// </summary> |
| 9 | + public sealed class SshUserKeyCredentials : Credentials |
| 10 | + { |
| 11 | + /// <summary> |
| 12 | + /// Callback to acquire a credential object. |
| 13 | + /// </summary> |
| 14 | + /// <param name="cred">The newly created credential object.</param> |
| 15 | + /// <param name="url">The resource for which we are demanding a credential.</param> |
| 16 | + /// <param name="usernameFromUrl">The username that was embedded in a "user@host"</param> |
| 17 | + /// <param name="types">A bitmask stating which cred types are OK to return.</param> |
| 18 | + /// <param name="payload">The payload provided when specifying this callback.</param> |
| 19 | + /// <returns>0 for success, < 0 to indicate an error, > 0 to indicate no credential was acquired.</returns> |
| 20 | + protected internal override int GitCredentialHandler(out IntPtr cred, IntPtr url, IntPtr usernameFromUrl, GitCredentialType types, IntPtr payload) |
| 21 | + { |
| 22 | + if (Username == null || PublicKey == null || PrivateKey == null || Passphrase == null) |
| 23 | + { |
| 24 | + throw new InvalidOperationException("SshCredentials contains a null Username or Key or Passphrase."); |
| 25 | + } |
| 26 | + |
| 27 | + return NativeMethods.git_cred_ssh_key_new(out cred, Username, PublicKey, PrivateKey, Passphrase); |
| 28 | + } |
| 29 | + |
| 30 | + /// <summary> |
| 31 | + /// Username for SSH authentication. |
| 32 | + /// </summary> |
| 33 | + public string Username { get; set; } |
| 34 | + |
| 35 | + /// <summary> |
| 36 | + /// Public key file location for SSH authentication. |
| 37 | + /// </summary> |
| 38 | + public string PublicKey { get; set; } |
| 39 | + |
| 40 | + /// <summary> |
| 41 | + /// Private key file location for SSH authentication. |
| 42 | + /// </summary> |
| 43 | + public string PrivateKey { get; set; } |
| 44 | + |
| 45 | + /// <summary> |
| 46 | + /// Passphrase for SSH authentication. |
| 47 | + /// </summary> |
| 48 | + public string Passphrase { get; set; } |
| 49 | + } |
| 50 | +} |
0 commit comments