using System;
using System.Security;
using Microsoft.Win32.SafeHandles;
namespace Alphaleonis.Win32.Filesystem
{
/// Represents a wrapper class for a handle used by the FindFirstFile/FindNextFile Win32 API functions.
[SecurityCritical]
internal sealed class SafeEncryptedFileRawHandle : SafeHandleZeroOrMinusOneIsInvalid
{
/// Constructor that prevents a default instance of this class from being created.
private SafeEncryptedFileRawHandle()
: base(true)
{
}
/// Constructor that prevents a default instance of this class from being created.
/// The handle.
/// true to reliably release the handle during the finalization phase; false to prevent
/// reliable release (not recommended).
public SafeEncryptedFileRawHandle(IntPtr handle, bool ownsHandle)
: base(ownsHandle)
{
SetHandle(handle);
}
/// When overridden in a derived class, executes the code required to free the handle.
/// if the handle is released successfully; otherwise, in the event of a catastrophic failure, . In this case, it generates a ReleaseHandleFailed Managed Debugging Assistant.
protected override bool ReleaseHandle()
{
NativeMethods.CloseEncryptedFileRaw(handle);
return true;
}
}
}