8000 Add serialization capabilities to the certificates · leoniDEV/libgit2sharp@a9d2f76 · GitHub
[go: up one dir, main page]

Skip to content

Commit a9d2f76

Browse files
committed
Add serialization capabilities to the certificates
1 parent 2f2b684 commit a9d2f76

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

LibGit2Sharp/CertificateSsh.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using LibGit2Sharp.Core;
2+
using System;
3+
using System.Runtime.InteropServices;
24

35
namespace LibGit2Sharp
46
{
@@ -49,5 +51,31 @@ internal CertificateSsh(GitCertificateSsh cert)
4951
HashSHA1 = new byte[20];
5052
cert.HashSHA1.CopyTo(HashSHA1, 0);
5153
}
54+
55+
internal IntPtr ToPointer()
56+
{
57+
GitCertificateSshType sshCertType = 0;
58+
if (HasMD5)
59+
{
60+
sshCertType |= GitCertificateSshType.MD5;
61+
}
62+
if (HasSHA1)
63+
{
64+
sshCertType |= GitCertificateSshType.SHA1;
65+
}
66+
67+
var gitCert = new GitCertificateSsh
68+
{
69+
cert_type = GitCertificateType.Hostkey,
70+
type = sshCertType,
71+
};
72+
HashMD5.CopyTo(gitCert.HashMD5, 0);
73+
HashSHA1.CopyTo(gitCert.HashSHA1, 0);
74+
75+
var ptr = Marshal.AllocHGlobal(Marshal.SizeOf(gitCert));
76+
Marshal.StructureToPtr(gitCert, ptr, false);
77+
78+
return ptr;
79+
}
5280
}
5381
}

LibGit2Sharp/CertificateX509.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Runtime.InteropServices;
1+
using System;
2+
using System.Runtime.InteropServices;
23
using System.Security.Cryptography.X509Certificates;
34
using LibGit2Sharp.Core;
45

@@ -28,5 +29,23 @@ internal CertificateX509(GitCertificateX509 cert)
2829
Marshal.Copy(cert.data, data, 0, len);
2930
Certificate = new X509Certificate(data);
3031
}
32+
33+
internal IntPtr ToPointers(out IntPtr dataPtr)
34+
{
35+
var certData = Certificate.Export(X509ContentType.Cert);
36+
dataPtr = Marshal.AllocHGlobal(certData.Length);
37+
Marshal.Copy(certData, 0, dataPtr, certData.Length);
38+
var gitCert = new GitCertificateX509()
39+
{
40+
cert_type = GitCertificateType.X509,
41+
data = dataPtr,
42+
len = (UIntPtr)certData.LongLength,
43+
};
44+
45+
var ptr = Marshal.AllocHGlobal(Marshal.SizeOf(gitCert));
46+
Marshal.StructureToPtr(gitCert, ptr, false);
47+
48+
return ptr;
49+
}
3150
}
3251
}

0 commit comments

Comments
 (0)
0