Skip to content

Commit e4cfeb6

Browse files
committed
Fix native binary interface
1 parent 677e025 commit e4cfeb6

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

LibGit2Sharp/CertificateSsh.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ protected CertificateSsh()
2525
/// </summary>
2626
public readonly byte[] HashSHA1;
2727

28+
/// <summary>
29+
/// The SHA256 hash of the host. Meaningful if <see cref="HasSHA256"/> is true
30+
/// </summary>
31+
public readonly byte[] HashSHA256;
32+
2833
/// <summary>
2934
/// True if we have the MD5 hostkey hash from the server
3035
/// </summary>
@@ -35,11 +40,17 @@ protected CertificateSsh()
3540
/// </summary>
3641
public readonly bool HasSHA1;
3742

43+
/// <summary>
44+
/// True if we have the SHA256 hostkey hash from the server
45+
/// </summary>
46+
public readonly bool HasSHA256;
47+
3848
internal unsafe CertificateSsh(git_certificate_ssh* cert)
3949
{
4050

4151
HasMD5 = cert->type.HasFlag(GitCertificateSshType.MD5);
4252
HasSHA1 = cert->type.HasFlag(GitCertificateSshType.SHA1);
53+
HasSHA256 = cert->type.HasFlag(GitCertificateSshType.SHA256);
4354

4455
HashMD5 = new byte[16];
4556
for (var i = 0; i < HashMD5.Length; i++)
@@ -52,6 +63,12 @@ internal unsafe CertificateSsh(git_certificate_ssh* cert)
5263
{
5364
HashSHA1[i] = cert->HashSHA1[i];
5465
}
66+
67+
HashSHA256 = new byte[32];
68+
for (var i = 0; i < HashSHA256.Length; i++)
69+
{
70+
HashSHA256[i] = cert->HashSHA256[i];
71+
}
5572
}
5673

5774
internal unsafe IntPtr ToPointer()
@@ -65,6 +82,10 @@ internal unsafe IntPtr ToPointer()
6582
{
6683
sshCertType |= GitCertificateSshType.SHA1;
6784
}
85+
if (HasSHA256)
86+
{
87+
sshCertType |= GitCertificateSshType.SHA256;
88+
}
6889

6990
var gitCert = new git_certificate_ssh()
7091
{
@@ -88,6 +109,14 @@ internal unsafe IntPtr ToPointer()
88109
}
89110
}
90111

112+
fixed (byte* p = &HashSHA256[0])
113+
{
114+
for (var i = 0; i < HashSHA256.Length; i++)
115+
{
116+
gitCert.HashSHA256[i] = p[i];
117+
}
118+
}
119+
91120
var ptr = Marshal.AllocHGlobal(Marshal.SizeOf(gitCert));
92121
Marshal.StructureToPtr(gitCert, ptr, false);
93122

LibGit2Sharp/Core/GitCertificateSsh.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal unsafe struct git_certificate_ssh
2525
public unsafe fixed byte HashSHA256[32];
2626

2727
public int raw_type;
28-
public char* hostkey;
28+
public byte* hostkey;
2929
public UIntPtr hostkey_len;
3030
}
3131
}

LibGit2Sharp/Core/GitCertificateSshType.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ internal enum GitCertificateSshType
77
{
88
MD5 = (1 << 0),
99
SHA1 = (1 << 1),
10+
SHA256 = (1 << 2),
1011
}
1112
}

LibGit2Sharp/Core/SshExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal static extern int git_cred_ssh_key_new(
1616
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string privatekey,
1717
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string passphrase);
1818

19-
[DllImport(libgit2)]
19+
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
2020
internal static extern int git_cred_ssh_key_memory_new(
2121
out IntPtr cred,
2222
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string username,

0 commit comments

Comments
 (0)