forked from libgit2/libgit2sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCertificateSsh.cs
More file actions
81 lines (67 loc) · 2.27 KB
/
CertificateSsh.cs
File metadata and controls
81 lines (67 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using LibGit2Sharp.Core;
using System;
using System.Runtime.InteropServices;
namespace LibGit2Sharp
{
/// <summary>
/// This class represents the hostkey which is avaiable when connecting to a SSH host.
/// </summary>
public class CertificateSsh : Certificate
{
/// <summary>
/// For mocking purposes
/// </summary>
protected CertificateSsh()
{ }
/// <summary>
/// The MD5 hash of the host. Meaningful if <see cref="HasMD5"/> is true
/// </summary>
public readonly byte[] HashMD5;
/// <summary>
/// The SHA1 hash of the host. Meaningful if <see cref="HasSHA1"/> is true
/// </summary>
public readonly byte[] HashSHA1;
/// <summary>
/// True if we have the MD5 hostkey hash from the server
/// </summary>
public readonly bool HasMD5;
/// <summary>
/// True if we have the SHA1 hostkey hash from the server
/// </summary>
public readonly bool HasSHA1;
/// <summary>
/// True if we have the SHA1 hostkey hash from the server
/// </summary>public readonly bool HasSHA1;
internal CertificateSsh(GitCertificateSsh cert)
{
HasMD5 = cert.type.HasFlag(GitCertificateSshType.MD5);
HasSHA1 = cert.type.HasFlag(GitCertificateSshType.SHA1);
HashMD5 = new byte[16];
cert.HashMD5.CopyTo(HashMD5, 0);
HashSHA1 = new byte[20];
cert.HashSHA1.CopyTo(HashSHA1, 0);
}
internal IntPtr ToPointer()
{
GitCertificateSshType sshCertType = 0;
if (HasMD5)
{
sshCertType |= GitCertificateSshType.MD5;
}
if (HasSHA1)
{
sshCertType |= GitCertificateSshType.SHA1;
}
var gitCert = new GitCertificateSsh
{
cert_type = GitCertificateType.Hostkey,
type = sshCertType,
};
HashMD5.CopyTo(gitCert.HashMD5, 0);
HashSHA1.CopyTo(gitCert.HashSHA1, 0);
var ptr = Marshal.AllocHGlobal(Marshal.SizeOf(gitCert));
Marshal.StructureToPtr(gitCert, ptr, false);
return ptr;
}
}
}