Add migrated to .NET 8.0 variant of Hcs.Client

This commit is contained in:
2025-09-26 19:48:32 +09:00
parent da127df8f6
commit 6cd2fb82e9
503 changed files with 223796 additions and 0 deletions

View File

@ -0,0 +1,76 @@
using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
namespace GostCryptography.Native
{
/// <summary>
/// Дескриптор криптографического провайдера
/// </summary>
[SecurityCritical]
public sealed class SafeProvHandleImpl : SafeHandleZeroOrMinusOneIsInvalid
{
public static SafeProvHandleImpl InvalidHandle => new SafeProvHandleImpl(IntPtr.Zero);
public SafeProvHandleImpl() : base(true)
{
}
public SafeProvHandleImpl(IntPtr handle) : base(true)
{
SetHandle(handle);
}
public SafeProvHandleImpl(IntPtr handle, bool addref) : base(true)
{
if (!addref)
{
SetHandle(handle);
}
else
{
bool success;
int errorCode;
// Обеспечивает атомарность блока finally
RuntimeHelpers.PrepareConstrainedRegions();
try { }
finally
{
success = CryptoApi.CryptContextAddRef(handle, null, 0);
errorCode = Marshal.GetLastWin32Error();
if (success)
{
SetHandle(handle);
}
}
if (!success)
{
throw ExceptionUtility.CryptographicException(errorCode);
}
}
}
public bool DeleteOnClose { get; set; }
[SecurityCritical]
protected override bool ReleaseHandle()
{
if (DeleteOnClose)
{
CryptoApi.CryptSetProvParam2(handle, Constants.PP_DELETE_KEYSET, null, 0);
}
else
{
CryptoApi.CryptReleaseContext(handle, 0);
}
return true;
}
}
}