using System;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
{
/// Access flags.
[PInvokeData("winnt.h")]
[StructLayout(LayoutKind.Sequential)]
public partial struct ACCESS_MASK : IEquatable
{
[Flags]
private enum _ACCESS_MASK : uint
{
DELETE = 0x00010000,
READ_CONTROL = 0x00020000,
WRITE_DAC = 0x00040000,
WRITE_OWNER = 0x00080000,
SYNCHRONIZE = 0x00100000,
STANDARD_RIGHTS_REQUIRED = 0x000F0000,
STANDARD_RIGHTS_READ = 0x00020000,
STANDARD_RIGHTS_WRITE = 0x00020000,
STANDARD_RIGHTS_EXECUTE = 0x00020000,
STANDARD_RIGHTS_ALL = 0x001F0000,
SPECIFIC_RIGHTS_ALL = 0x0000FFFF,
ACCESS_SYSTEM_SECURITY = 0x01000000,
MAXIMUM_ALLOWED = 0x02000000,
GENERIC_READ = 0x80000000,
GENERIC_WRITE = 0x40000000,
GENERIC_EXECUTE = 0x20000000,
GENERIC_ALL = 0x10000000
}
///
/// Controls the ability to get or set the SACL in an object's security descriptor. The system grants this access right only if the
/// SE_SECURITY_NAME privilege is enabled in the access token of the requesting thread.
///
public const uint ACCESS_SYSTEM_SECURITY = (uint)_ACCESS_MASK.ACCESS_SYSTEM_SECURITY;
/// The right to delete the object.
public const uint DELETE = (uint)_ACCESS_MASK.DELETE;
/// All possible access rights.
public const uint GENERIC_ALL = (uint)_ACCESS_MASK.GENERIC_ALL;
/// Execute access.
public const uint GENERIC_EXECUTE = (uint)_ACCESS_MASK.GENERIC_EXECUTE;
/// Read access.
public const uint GENERIC_READ = (uint)_ACCESS_MASK.GENERIC_READ;
/// Write access.
public const uint GENERIC_WRITE = (uint)_ACCESS_MASK.GENERIC_WRITE;
/// Request that the object be opened with all the access rights that are valid for the caller.
public const uint MAXIMUM_ALLOWED = (uint)_ACCESS_MASK.MAXIMUM_ALLOWED;
///
/// The right to read the information in the object's security descriptor, not including the information in the system access control
/// list (SACL).
///
public const uint READ_CONTROL = (uint)_ACCESS_MASK.READ_CONTROL;
/// The specific rights all
public const uint SPECIFIC_RIGHTS_ALL = (uint)_ACCESS_MASK.SPECIFIC_RIGHTS_ALL;
/// Combines DELETE, READ_CONTROL, WRITE_DAC, WRITE_OWNER, and SYNCHRONIZE access.
public const uint STANDARD_RIGHTS_ALL = (uint)_ACCESS_MASK.STANDARD_RIGHTS_ALL;
/// Currently defined to equal READ_CONTROL.
public const uint STANDARD_RIGHTS_EXECUTE = (uint)_ACCESS_MASK.STANDARD_RIGHTS_EXECUTE;
/// Currently defined to equal READ_CONTROL.
public const uint STANDARD_RIGHTS_READ = (uint)_ACCESS_MASK.STANDARD_RIGHTS_READ;
/// Combines DELETE, READ_CONTROL, WRITE_DAC, and WRITE_OWNER access.
public const uint STANDARD_RIGHTS_REQUIRED = (uint)_ACCESS_MASK.STANDARD_RIGHTS_REQUIRED;
/// Currently defined to equal READ_CONTROL.
public const uint STANDARD_RIGHTS_WRITE = (uint)_ACCESS_MASK.STANDARD_RIGHTS_WRITE;
///
/// The right to use the object for synchronization. This enables a thread to wait until the object is in the signaled state. Some
/// object types do not support this access right.
///
public const uint SYNCHRONIZE = (uint)_ACCESS_MASK.SYNCHRONIZE;
/// The right to modify the discretionary access control list (DACL) in the object's security descriptor.
public const uint WRITE_DAC = (uint)_ACCESS_MASK.WRITE_DAC;
/// The right to change the owner in the object's security descriptor.
public const uint WRITE_OWNER = (uint)_ACCESS_MASK.WRITE_OWNER;
private readonly uint value;
/// Initializes a new instance of the struct.
/// The value.
public ACCESS_MASK(uint val) => value = val;
/// Initializes a new instance of the struct.
/// The mask.
public ACCESS_MASK(IConvertible mask) : this(mask.ToUInt32(null)) { }
/// Gets the raw value.
/// The value.
public uint Value => value;
/// Creates an from an enum value.
/// The type of the enum.
/// The enum value.
/// The converted ACCESS_MASK value.
public static ACCESS_MASK FromEnum(TEnum @enum) where TEnum : System.Enum => new ACCESS_MASK(@enum);
/// Performs an implicit conversion from to .
/// The value.
/// The result of the conversion.
public static implicit operator ACCESS_MASK(int value) => new ACCESS_MASK(unchecked((uint)value));
/// Performs an implicit conversion from to .
/// The value.
/// The result of the conversion.
public static implicit operator ACCESS_MASK(uint value) => new ACCESS_MASK(value);
/// Performs an explicit conversion from to .
/// The value.
/// The result of the conversion.
public static explicit operator int(ACCESS_MASK value) => value.ToInt32();
/// Performs an implicit conversion from to .
/// The value.
/// The result of the conversion.
public static implicit operator uint(ACCESS_MASK value) => value.Value;
/// Implements the operator ==.
/// The left.
/// The right.
/// The result of the operator.
public static bool operator ==(ACCESS_MASK left, ACCESS_MASK right) => left.value.Equals(right.value);
/// Implements the operator !=.
/// The left.
/// The right.
/// The result of the operator.
public static bool operator !=(ACCESS_MASK left, ACCESS_MASK right) => !left.value.Equals(right.value);
/// Implements the operator &.
/// The left.
/// The right.
/// The result of the operator.
public static ACCESS_MASK operator &(ACCESS_MASK left, ACCESS_MASK right) => left.value & right.value;
/// Implements the operator |.
/// The left.
/// The right.
/// The result of the operator.
public static ACCESS_MASK operator |(ACCESS_MASK left, ACCESS_MASK right) => left.value | right.value;
/// Implements the operator ^.
/// The left.
/// The right.
/// The result of the operator.
public static ACCESS_MASK operator ^(ACCESS_MASK left, ACCESS_MASK right) => left.value ^ right.value;
/// Implements the operator ~.
/// The value.
/// The result of the operator.
public static ACCESS_MASK operator ~(ACCESS_MASK val) => ~val.value;
/// Indicates whether the current object is equal to another object of the same type.
/// An object to compare with this object.
/// true if the current object is equal to the parameter; otherwise, false.
///
public bool Equals(ACCESS_MASK other) => value.Equals(other.value);
/// Determines whether the specified , is equal to this instance.
/// The to compare with this instance.
/// true if the specified is equal to this instance; otherwise, false.
///
public override bool Equals(object obj) => obj is ACCESS_MASK am ? Equals(am) : base.Equals(obj);
/// Returns a hash code for this instance.
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
///
public override int GetHashCode() => ToInt32();
/// Determines whether [is flag set] [the specified mask].
/// The mask.
/// true if [is flag set] [the specified mask]; otherwise, false.
public bool IsFlagSet(ACCESS_MASK mask) => (value & (uint)mask) != 0;
/// Converts to int32.
///
public int ToInt32() => unchecked((int)value);
/// Converts to string.
/// A that represents this instance.
///
public override string ToString() => ((_ACCESS_MASK)value).ToString();
/// Converts to uint32.
///
public uint ToUInt32() => value;
}
}