﻿// Decompiled with JetBrains decompiler
// Type: Microsoft.Win32.SafeHandles.SafeNCryptKeyHandle
// Assembly: System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: BA37026F-1371-4849-854A-E2CCE7CAD02B
// Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Core.dll

using System;
using System.Runtime;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;

namespace Microsoft.Win32.SafeHandles
{
  /// <summary>
  /// Provides a safe handle that represents a key (NCRYPT_KEY_HANDLE).
  /// </summary>
  [SecurityCritical(SecurityCriticalScope.Everything)]
  [HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
  [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
  public sealed class SafeNCryptKeyHandle : SafeNCryptHandle
  {
    /// <summary>
    /// Initializes a new instance of the <see cref="T:Microsoft.Win32.SafeHandles.SafeNCryptKeyHandle"/> class.
    /// </summary>
    [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
    public SafeNCryptKeyHandle()
    {
    }

    [SuppressUnmanagedCodeSecurity]
    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
    [DllImport("ncrypt.dll")]
    private static extern int NCryptFreeObject(IntPtr hObject);

    protected override bool ReleaseNativeHandle()
    {
      return SafeNCryptKeyHandle.NCryptFreeObject(this.handle) == 0;
    }

    internal SafeNCryptKeyHandle Duplicate()
    {
      return this.Duplicate<SafeNCryptKeyHandle>();
    }
  }
}
