forked from libgit2/libgit2sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCertificateX509.cs
More file actions
51 lines (44 loc) · 1.45 KB
/
Copy pathCertificateX509.cs
File metadata and controls
51 lines (44 loc) · 1.45 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
using System;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using LibGit2Sharp.Core;
namespace LibGit2Sharp
{
/// <summary>
/// Conains a X509 certificate
/// </summary>
public class CertificateX509 : Certificate
{
/// <summary>
/// For mocking purposes
/// </summary>
protected CertificateX509()
{ }
/// <summary>
/// The certificate.
/// </summary>
public virtual X509Certificate Certificate { get; private set; }
internal CertificateX509(GitCertificateX509 cert)
{
int len = checked((int) cert.len.ToUInt32());
byte[] data = new byte[len];
Marshal.Copy(cert.data, data, 0, len);
Certificate = new X509Certificate(data);
}
internal IntPtr ToPointers(out IntPtr dataPtr)
{
var certData = Certificate.Export(X509ContentType.Cert);
dataPtr = Marshal.AllocHGlobal(certData.Length);
Marshal.Copy(certData, 0, dataPtr, certData.Length);
var gitCert = new GitCertificateX509()
{
cert_type = GitCertificateType.X509,
data = dataPtr,
len = (UIntPtr)certData.LongLength,
};
var ptr = Marshal.AllocHGlobal(Marshal.SizeOf(gitCert));
Marshal.StructureToPtr(gitCert, ptr, false);
return ptr;
}
}
}