using System;
using System.Runtime.InteropServices;
using Vanara.Extensions;
using static Vanara.PInvoke.Crypt32;
namespace Vanara.PInvoke
{
public static partial class WinTrust
{
///
/// The PFN_CDF_PARSE_ERROR_CALLBACK function is called for Catalog Definition Function errors while parsing a catalog
/// definition file (CDF).
///
/// A value that indicates in which area of the CDF the error occurred.
/// A value that indicates the type of error.
///
/// This callback function does not return a value.
///
/// The dwErrorArea parameter can have the following possible values.
///
///
/// Value
/// Description
///
/// -
/// CRYPTCAT_E_AREA_HEADER
/// The header section of the CDF
///
/// -
/// CRYPTCAT_E_AREA_MEMBER
/// A member file entry in the CatalogFiles section of the CDF
///
/// -
/// CRYPTCAT_E_AREA_ATTRIBUTE
/// An attribute entry in the CDF
///
///
/// The dwLocalError parameter can have the following possible values.
///
///
/// Value
/// Description
///
/// -
/// CRYPTCAT_E_CDF_UNSUPPORTED
/// The function does not support the attribute.
///
/// -
/// CRYPTCAT_E_CDF_DUPLICATE
/// The file member already exists.
///
/// -
/// CRYPTCAT_E_CDF_TAGNOTFOUND
/// The CatalogHeader or Name tag is missing.
///
/// -
/// CRYPTCAT_E_CDF_MEMBER_FILE_PATH
/// The member file name or path is missing.
///
/// -
/// CRYPTCAT_E_CDF_MEMBER_INDIRECTDATA
/// The function failed to create a hash of the member subject.
///
/// -
/// CRYPTCAT_E_CDF_MEMBER_FILENOTFOUND
/// The function failed to find the member file.
///
/// -
/// CRYPTCAT_E_CDF_BAD_GUID_CONV
/// The function failed to convert the subject string to a GUID.
///
/// -
/// CRYPTCAT_E_CDF_ATTR_TOOFEWVALUES
///
/// The attribute line is missing one or more elements of its composition including type, object identifier (OID) or name, or value.
///
///
/// -
/// CRYPTCAT_E_CDF_ATTR_TYPECOMBO
/// The attribute contains an invalid OID, or the combination of type, name or OID, and value is not valid.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nc-mscat-pfn_cdf_parse_error_callback PFN_CDF_PARSE_ERROR_CALLBACK
// PfnCdfParseErrorCallback; void PfnCdfParseErrorCallback( IN DWORD dwErrorArea, IN DWORD dwLocalError, IN WCHAR *pwszLine ) {...}
[PInvokeData("mscat.h", MSDNShortId = "94c12ad7-dcb0-4099-8eba-da38367f0d79")]
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
public delegate void PfnCdfParseErrorCallback(CRYPTCAT_E dwErrorArea, CRYPTCAT_E dwLocalError, [In, MarshalAs(UnmanagedType.LPWStr)] string pwszLine);
/// CRYPTCATATTRIBUTE attributes and actions.
[PInvokeData("mscat.h", MSDNShortId = "41b91303-f3eb-4288-9ad2-98f170680988")]
[Flags]
public enum CRYPTCAT_ATTR : uint
{
/// The attribute is authenticated.
CRYPTCAT_ATTR_AUTHENTICATED = 0x10000000,
/// The attribute is unauthenticated.
CRYPTCAT_ATTR_UNAUTHENTICATED = 0x20000000,
/// The attribute is an ASCII string.
CRYPTCAT_ATTR_NAMEASCII = 0x00000001,
/// The attribute is a cryptographic object identifier (OID).
CRYPTCAT_ATTR_NAMEOBJID = 0x00000002,
/// The attribute contains simple ASCII characters that should not be decoded.
CRYPTCAT_ATTR_DATAASCII = 0x00010000,
/// The attribute is in base 64 format.
CRYPTCAT_ATTR_DATABASE64 = 0x00020000,
/// The attribute replaces the value for an existing attribute.
CRYPTCAT_ATTR_DATAREPLACE = 0x00040000,
}
/// Errors used by .
[PInvokeData("mscat.h", MSDNShortId = "94c12ad7-dcb0-4099-8eba-da38367f0d79")]
public enum CRYPTCAT_E
{
/// The header section of the CDF
CRYPTCAT_E_AREA_HEADER = 0x00000000,
/// A member file entry in the CatalogFiles section of the CDF
CRYPTCAT_E_AREA_MEMBER = 0x00010000,
/// An attribute entry in the CDF
CRYPTCAT_E_AREA_ATTRIBUTE = 0x00020000,
/// The function does not support the attribute.
CRYPTCAT_E_CDF_UNSUPPORTED = 0x00000001,
/// The file member already exists.
CRYPTCAT_E_CDF_DUPLICATE = 0x00000002,
/// The CatalogHeader or Name tag is missing.
CRYPTCAT_E_CDF_TAGNOTFOUND = 0x00000004,
/// The member file name or path is missing.
CRYPTCAT_E_CDF_MEMBER_FILE_PATH = 0x00010001,
/// The function failed to create a hash of the member subject.
CRYPTCAT_E_CDF_MEMBER_INDIRECTDATA = 0x00010002,
/// The function failed to find the member file.
CRYPTCAT_E_CDF_MEMBER_FILENOTFOUND = 0x00010004,
/// The function failed to convert the subject string to a GUID.
CRYPTCAT_E_CDF_BAD_GUID_CONV = 0x00020001,
///
/// The attribute line is missing one or more elements of its composition including type, object identifier (OID) or name, or value.
///
CRYPTCAT_E_CDF_ATTR_TOOFEWVALUES = 0x00020002,
/// The attribute contains an invalid OID, or the combination of type, name or OID, and value is not valid.
CRYPTCAT_E_CDF_ATTR_TYPECOMBO = 0x00020004,
}
/// Flags used by and .
[PInvokeData("mscat.h", MSDNShortId = "e81f3a3d-d5b7-4266-838d-b83e331c8594")]
[Flags]
public enum CRYPTCAT_OPEN : uint
{
/// Opens the file, if it exists, or creates a new file, if needed.
CRYPTCAT_OPEN_ALWAYS = 0x00000002,
/// A new catalog file is created. If a previously created file exists, it is overwritten.
CRYPTCAT_OPEN_CREATENEW = 0x00000001,
/// Opens the file, only if it exists.
CRYPTCAT_OPEN_EXISTING = 0x00000004,
/// Exclude page hashes in SPC_INDIRECT_DATA.
CRYPTCAT_OPEN_EXCLUDE_PAGE_HASHES = 0x00010000,
/// For all flags with a value in the upper word, set or clear the flag.
CRYPTCAT_OPEN_FLAGS_MASK = 0xffff0000,
///
/// Include page hashes in SPC_INDIRECT_DATA. The CRYPTCAT_OPEN_EXCLUDE_PAGE_HASHES flag takes precedence if it is also set.
///
CRYPTCAT_OPEN_INCLUDE_PAGE_HASHES = 0x00020000,
/// Open the file for decoding without detached content.
CRYPTCAT_OPEN_NO_CONTENT_HCRYPTMSG = 0x20000000,
/// Open the catalog with the entries sorted alphabetically by subject.
CRYPTCAT_OPEN_SORTED = 0x40000000,
/// Verify the signature hash but not the certificate chain.
CRYPTCAT_OPEN_VERIFYSIGHASH = 0x10000000,
}
/// Version values used by .
[PInvokeData("mscat.h", MSDNShortId = "e81f3a3d-d5b7-4266-838d-b83e331c8594")]
public enum CRYPTCAT_VERSION
{
/// Version 1 file format.
CRYPTCAT_VERSION_1 = 0x100,
///
/// Version 2 file format.
/// Windows 8 and Windows Server 2012: Support for this value begins.
///
CRYPTCAT_VERSION_2 = 0x200,
}
///
///
/// [The CryptCATAdminAcquireContext function is available for use in the operating systems specified in the Requirements
/// section. It may be altered or unavailable in subsequent versions.]
///
///
/// The CryptCATAdminAcquireContext function acquires a handle to a catalog administrator context. This handle can be used by
/// subsequent calls to the CryptCATAdminAddCatalog, CryptCATAdminEnumCatalogFromHash, and CryptCATAdminRemoveCatalog functions.
/// This function has no associated import library. You must use the LoadLibrary and GetProcAddress functions to dynamically link to Wintrust.dll.
///
///
///
/// A pointer to the catalog administrator context handle that is assigned by this function. When you have finished using the
/// handle, close it by calling the CryptCATAdminReleaseContext function.
///
///
/// A pointer to the GUID that identifies the subsystem. DRIVER_ACTION_VERIFY represents the subsystem for operating system
/// components and third party drivers. This is the subsystem used by most implementations.
///
/// Not used; set to zero.
///
/// The return value is TRUE if the function succeeds; FALSE if the function fails.
///
/// For extended error information, call the GetLastError function. For a complete list of error codes provided by the operating
/// system, see System Error Codes.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatadminacquirecontext BOOL CryptCATAdminAcquireContext(
// HCATADMIN *phCatAdmin, const GUID *pgSubsystem, DWORD dwFlags );
[DllImport(Lib.Wintrust, SetLastError = true, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "693af055-fa93-4526-aa9c-3a659f8ff78f")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CryptCATAdminAcquireContext(out SafeHCATADMIN phCatAdmin, in Guid pgSubsystem, uint dwFlags = 0);
///
///
/// The CryptCATAdminAcquireContext2 function acquires a handle to a catalog administrator context for a given hash algorithm
/// and hash policy.
///
/// You can use this handle in subsequent calls to the following functions:
///
/// -
/// CryptCATAdminAddCatalog
///
/// -
/// CryptCATAdminEnumCatalogFromHash
///
/// -
/// CryptCATAdminRemoveCatalog
///
///
///
/// This function has no associated import library. You must use the LoadLibrary and GetProcAddress functions to dynamically link to Wintrust.dll.
///
///
///
/// A pointer to the catalog administrator context handle that is assigned by this function. When you have finished using the
/// handle, close it by calling the CryptCATAdminReleaseContext function.
///
///
/// A pointer to the GUID that identifies the subsystem. DRIVER_ACTION_VERIFY represents the subsystem for operating system
/// components and third party drivers. This is the subsystem used by most implementations.
///
///
/// Optional null-terminated Unicode string that specifies the name of the hash algorithm to use when calculating and verifying
/// hashes. This value can be NULL. If it is NULL, the default hashing algorithm may be chosen, depending on the value
/// you set for the pStrongHashPolicy parameter. The default algorithm in Windows 8 is SHA1. The default may change in future
/// Windows versions. For more information, see Remarks.
///
///
/// Pointer to a CERT_STRONG_SIGN_PARA structure that contains the parameters used to check for strong signatures. The function
/// chooses the lowest common hashing algorithm that satisfies the specified policy and the algorithm specified by the
/// pwszHashAlgorithm parameter or the system default algorithm (if no algorithm is specified).
///
/// Reserved. This value must be zero.
///
/// If the function succeeds, the return value is nonzero ( TRUE).
/// If the function fails, the return value is zero ( FALSE). For extended error information, call GetLastError.
/// The following table lists the error codes most commonly returned by the GetLastError function.
///
///
/// Return code
/// Description
///
/// -
/// ERROR_INVALID_PARAMETER
/// The phCatAdmin parameter cannot be NULL. The dwFlags parameter must be zero (0).
///
/// -
/// ERROR_NOT_ENOUGH_MEMORY
/// There was insufficient memory to create a new catalog administrator object.
///
/// -
/// NTE_BAD_ALGID
/// The hash algorithm specified by the pwszHashAlgorithm parameter cannot be found.
///
///
///
///
/// This function enables you to choose, or chooses for you, the hash algorithm to be used in functions that require the catalog
/// administrator context. Although you can set the name of the hashing algorithm, we recommend that you let the function determine
/// the algorithm. Doing so protects your application from hard coding algorithms that may become untrusted in the future.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatadminacquirecontext2 BOOL CryptCATAdminAcquireContext2(
// HCATADMIN *phCatAdmin, const GUID *pgSubsystem, PCWSTR pwszHashAlgorithm, PCCERT_STRONG_SIGN_PARA pStrongHashPolicy, DWORD
// dwFlags );
[DllImport(Lib.Wintrust, SetLastError = true, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "B089217A-5C12-4C51-8E46-3A9243347B21")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CryptCATAdminAcquireContext2(out SafeHCATADMIN phCatAdmin, in Guid pgSubsystem, [MarshalAs(UnmanagedType.LPWStr), Optional] string pwszHashAlgorithm, in CERT_STRONG_SIGN_PARA pStrongHashPolicy, uint dwFlags = 0);
///
///
/// The CryptCATAdminAcquireContext2 function acquires a handle to a catalog administrator context for a given hash algorithm
/// and hash policy.
///
/// You can use this handle in subsequent calls to the following functions:
///
/// -
/// CryptCATAdminAddCatalog
///
/// -
/// CryptCATAdminEnumCatalogFromHash
///
/// -
/// CryptCATAdminRemoveCatalog
///
///
///
/// This function has no associated import library. You must use the LoadLibrary and GetProcAddress functions to dynamically link to Wintrust.dll.
///
///
///
/// A pointer to the catalog administrator context handle that is assigned by this function. When you have finished using the
/// handle, close it by calling the CryptCATAdminReleaseContext function.
///
///
/// A pointer to the GUID that identifies the subsystem. DRIVER_ACTION_VERIFY represents the subsystem for operating system
/// components and third party drivers. This is the subsystem used by most implementations.
///
///
/// Optional null-terminated Unicode string that specifies the name of the hash algorithm to use when calculating and verifying
/// hashes. This value can be NULL. If it is NULL, the default hashing algorithm may be chosen, depending on the value
/// you set for the pStrongHashPolicy parameter. The default algorithm in Windows 8 is SHA1. The default may change in future
/// Windows versions. For more information, see Remarks.
///
///
/// Pointer to a CERT_STRONG_SIGN_PARA structure that contains the parameters used to check for strong signatures. The function
/// chooses the lowest common hashing algorithm that satisfies the specified policy and the algorithm specified by the
/// pwszHashAlgorithm parameter or the system default algorithm (if no algorithm is specified).
///
/// Reserved. This value must be zero.
///
/// If the function succeeds, the return value is nonzero ( TRUE).
/// If the function fails, the return value is zero ( FALSE). For extended error information, call GetLastError.
/// The following table lists the error codes most commonly returned by the GetLastError function.
///
///
/// Return code
/// Description
///
/// -
/// ERROR_INVALID_PARAMETER
/// The phCatAdmin parameter cannot be NULL. The dwFlags parameter must be zero (0).
///
/// -
/// ERROR_NOT_ENOUGH_MEMORY
/// There was insufficient memory to create a new catalog administrator object.
///
/// -
/// NTE_BAD_ALGID
/// The hash algorithm specified by the pwszHashAlgorithm parameter cannot be found.
///
///
///
///
/// This function enables you to choose, or chooses for you, the hash algorithm to be used in functions that require the catalog
/// administrator context. Although you can set the name of the hashing algorithm, we recommend that you let the function determine
/// the algorithm. Doing so protects your application from hard coding algorithms that may become untrusted in the future.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatadminacquirecontext2 BOOL CryptCATAdminAcquireContext2(
// HCATADMIN *phCatAdmin, const GUID *pgSubsystem, PCWSTR pwszHashAlgorithm, PCCERT_STRONG_SIGN_PARA pStrongHashPolicy, DWORD
// dwFlags );
[DllImport(Lib.Wintrust, SetLastError = true, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "B089217A-5C12-4C51-8E46-3A9243347B21")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CryptCATAdminAcquireContext2(out SafeHCATADMIN phCatAdmin, [Optional] IntPtr pgSubsystem, [MarshalAs(UnmanagedType.LPWStr), Optional] string pwszHashAlgorithm, [Optional] IntPtr pStrongHashPolicy, uint dwFlags = 0);
///
///
/// [The CryptCATAdminAddCatalog function is available for use in the operating systems specified in the Requirements
/// section. It may be altered or unavailable in subsequent versions.]
///
///
/// The CryptCATAdminAddCatalog function adds a catalog to the catalog database. The catalog database is an index that
/// associates file hashes with the catalogs that contain them. It is used to speed the identification of the catalogs when
/// verifying the file signature. This function is the only supported way to programmatically add catalogs to the Windows catalog
/// database. The function has no associated import library. You must use the LoadLibrary and GetProcAddress functions to
/// dynamically link to Wintrust.dll.
///
///
/// Handle previously assigned by the CryptCATAdminAcquireContext function.
///
/// A pointer to a null-terminated string for the fully qualified path of the catalog to be added.
///
///
/// A pointer to a null-terminated string for the name of the catalog when it is stored. If the parameter is NULL,
/// then a unique name will be generated for the catalog.
///
///
/// If the CRYPTCAT_ADDCATALOG_HARDLINK (0x00000001) flag is specified, the catalog specified in the call will be hard-linked to
/// rather than copied. Hard-linking instead of copying a catalog reduces the amount of disk space required by Windows.
///
///
///
/// If the function succeeds, the return value is a handle to the catalog information context. If the function fails, the return
/// value is NULL. After you have finished using the returned handle, free it by calling the
/// CryptCATAdminReleaseCatalogContext function.
///
///
/// For extended error information, call the GetLastError function. For a complete list of error codes provided by the operating
/// system, see System Error Codes.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatadminaddcatalog HCATINFO CryptCATAdminAddCatalog(
// HCATADMIN hCatAdmin, PWSTR pwszCatalogFile, PWSTR pwszSelectBaseName, DWORD dwFlags );
[PInvokeData("mscat.h", MSDNShortId = "a227597c-a0af-4b86-bd29-03f478aef244")]
public static SafeHCATINFO CryptCATAdminAddCatalog(SafeHCATADMIN hCatAdmin, [MarshalAs(UnmanagedType.LPWStr)] string pwszCatalogFile, [MarshalAs(UnmanagedType.LPWStr), Optional] string pwszSelectBaseName, uint dwFlags) =>
new SafeHCATINFO(InternalCryptCATAdminAddCatalog(hCatAdmin, pwszCatalogFile, pwszSelectBaseName, dwFlags), hCatAdmin, true);
///
///
/// [The CryptCATAdminCalcHashFromFileHandle function is available for use in the operating systems specified in the
/// Requirements section. It may be altered or unavailable in subsequent versions.]
///
///
/// The CryptCATAdminCalcHashFromFileHandle function calculates the hash for a file. This function has no associated import
/// library. You must use the LoadLibrary and GetProcAddress functions to dynamically link to Wintrust.dll.
///
///
///
/// A handle to the file whose hash is being calculated. This parameter cannot be NULL and must be a valid file handle.
///
///
/// A pointer to a DWORD variable that contains the number of bytes in pbHash. Upon input, set pcbHash to the number of bytes
/// allocated for pbHash. Upon return, pcbHash contains the number of returned bytes in pbHash. If pbHash is passed as NULL,
/// then pcbHash contains the number of bytes to allocate for pbHash.
///
///
/// A pointer to a BYTE buffer that receives the hash. If this parameter is passed in as NULL, then pcbHash contains
/// the number of bytes to allocate for pbHash, and a subsequent call can be made to retrieve the hash.
///
/// This parameter is reserved for future use and must be set to zero.
///
/// The return value is TRUE if the function succeeds; FALSE if the function fails. If FALSE is returned, call
/// the GetLastError function to determine the reason for failure. If not enough memory has been allocated for pbHash, the
/// CryptCATAdminCalcHashFromFileHandle function will set the last error to ERROR_INSUFFICIENT_BUFFER.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatadmincalchashfromfilehandle BOOL
// CryptCATAdminCalcHashFromFileHandle( HANDLE hFile, DWORD *pcbHash, BYTE *pbHash, DWORD dwFlags );
[DllImport(Lib.Wintrust, SetLastError = true, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "4dc5688f-4b7a-4baf-9671-868cac7f1896")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CryptCATAdminCalcHashFromFileHandle(HFILE hFile, ref uint pcbHash, IntPtr pbHash, uint dwFlags = 0);
///
/// The CryptCATAdminCalcHashFromFileHandle2 function calculates the hash for a file by using the specified algorithm.
///
/// This function has no associated import library. You must use the LoadLibrary and GetProcAddress functions to dynamically link to Wintrust.dll.
///
///
/// Handle of an open catalog administrator context. For more information, see CryptCATAdminAcquireContext2.
///
/// A handle to the file whose hash is being calculated. This parameter cannot be NULL and must be a valid file handle.
///
///
/// Pointer to a DWORD variable that contains the number of bytes in the pbHash parameter. Upon input, set pcbHash to the
/// number of bytes allocated for pbHash. Upon return, pcbHash contains the number of returned bytes in pbHash. If pbHash is set to
/// NULL, then pcbHash contains the number of bytes to allocate for pbHash.
///
///
/// Pointer to a BYTE buffer that receives the hash. If you set this parameter to NULL, then pcbHash will contain the
/// number of bytes to allocate for pbHash, and a subsequent call can be made to retrieve the hash.
///
/// Reserved. This value must be zero.
///
/// If the function succeeds, the return value is nonzero ( TRUE).
/// If the function fails, the return value is zero ( FALSE). For extended error information, call GetLastError.
/// The following table lists the error codes most commonly returned by the GetLastError function.
///
///
/// Return code
/// Description
///
/// -
/// ERROR_INVALID_PARAMETER
///
/// The hFile parameter must not be NULL. The hFile parameter must be a valid file handle. The pcbHash parameter must not be NULL.
/// The dwFlags parameter must be zero (0).
///
///
/// -
/// ERROR_INSUFFICIENT_BUFFER
///
/// The buffer pointed to by the pbHash parameter was not NULL but was not large enough to be written. The correct size of the
/// required buffer is contained in the value pointed to by the pcbHash parameter.
///
///
/// -
/// NTE_BAD_ALGID
/// The hash algorithm specified by the pwszHashAlgorithm parameter cannot be found.
///
///
///
///
/// The amount of time this function takes to execute depends on the length of the file being hashed, the algorithm being used, and
/// the file location. For example, it takes several seconds to calculate the hash of a local file that is very large (a few hundred megabytes).
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatadmincalchashfromfilehandle2 BOOL
// CryptCATAdminCalcHashFromFileHandle2( HCATADMIN hCatAdmin, HANDLE hFile, DWORD *pcbHash, BYTE *pbHash, DWORD dwFlags );
[DllImport(Lib.Wintrust, SetLastError = true, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "CBFA60A8-5E5A-4FAD-8AD3-26539802CD53")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CryptCATAdminCalcHashFromFileHandle2(HCATADMIN hCatAdmin, HFILE hFile, ref uint pcbHash, IntPtr pbHash, uint dwFlags = 0);
///
///
/// [The CryptCATAdminEnumCatalogFromHash function is available for use in the operating systems specified in the
/// Requirements section. It may be altered or unavailable in subsequent versions.]
///
///
/// The CryptCATAdminEnumCatalogFromHash function enumerates the catalogs that contain a specified hash. The hash is
/// typically returned from the CryptCATAdminCalcHashFromFileHandle function. This function has no associated import library. You
/// must use the LoadLibrary and GetProcAddress functions to dynamically link to Wintrust.dll. After the final call to this
/// function, call CryptCATAdminReleaseCatalogContext to release allocated memory.
///
///
///
/// A handle to a catalog administrator context previously assigned by the CryptCATAdminAcquireContext function.
///
/// A pointer to the buffer that contains the hash retrieved by calling CryptCATAdminCalcHashFromFileHandle.
/// Number of bytes in the buffer allocated for pbHash.
/// This parameter is reserved for future use and must be set to zero.
///
/// A pointer to the handle to the previous catalog context or NULL, if an enumeration is re-queried. If NULL is
/// passed in for this parameter, then the caller gets information only for the first catalog that contains the hash; an enumeration
/// is not made. If phPrevCatInfo contains NULL, then an enumeration of the catalogs that contain the hash is started, and
/// subsequent calls to CryptCATAdminEnumCatalogFromHash must set phPrevCatInfo to the return value from the previous call.
///
///
/// The return value is a handle to the catalog context or NULL, if there are no more catalogs to enumerate or retrieve.
///
/// For extended error information, call the GetLastError function. For a complete list of error codes provided by the operating
/// system, see System Error Codes.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatadminenumcatalogfromhash HCATINFO
// CryptCATAdminEnumCatalogFromHash( HCATADMIN hCatAdmin, BYTE *pbHash, DWORD cbHash, DWORD dwFlags, HCATINFO *phPrevCatInfo );
[PInvokeData("mscat.h", MSDNShortId = "33ab2d01-94ab-4d23-a054-9da0731485d6")]
public static SafeHCATINFO CryptCATAdminEnumCatalogFromHash(SafeHCATADMIN hCatAdmin, IntPtr pbHash, uint cbHash, [Optional] uint dwFlags, ref HCATINFO phPrevCatInfo) =>
new SafeHCATINFO(InternalCryptCATAdminEnumCatalogFromHash(hCatAdmin, pbHash, cbHash, dwFlags, ref phPrevCatInfo), hCatAdmin, true);
///
///
/// [The CryptCATAdminReleaseCatalogContext function is available for use in the operating systems specified in the
/// Requirements section. It may be altered or unavailable in subsequent versions.]
///
///
/// The CryptCATAdminReleaseCatalogContext function releases a handle to a catalog context previously returned by the
/// CryptCATAdminAddCatalog function. This function has no associated import library. You must use the LoadLibrary and
/// GetProcAddress functions to dynamically link to Wintrust.dll.
///
///
/// Handle previously assigned by the CryptCATAdminAcquireContext function.
///
/// Handle previously assigned by the CryptCATAdminAddCatalog function or the CryptCATAdminEnumCatalogFromHash function.
///
/// This parameter is reserved for future use and must be set to zero.
/// The return value is TRUE if the function succeeds; FALSE if the function fails.
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatadminreleasecatalogcontext BOOL
// CryptCATAdminReleaseCatalogContext( IN HCATADMIN hCatAdmin, IN HCATINFO hCatInfo, IN DWORD dwFlags );
[DllImport(Lib.Wintrust, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "6cc13013-2c0a-4934-a866-30b69cbcf934")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CryptCATAdminReleaseCatalogContext(HCATADMIN hCatAdmin, HCATINFO hCatInfo, uint dwFlags = 0);
///
///
/// [The CryptCATAdminReleaseContext function is available for use in the operating systems specified in the Requirements
/// section. It may be altered or unavailable in subsequent versions.]
///
///
/// The CryptCATAdminReleaseContext function releases the handle previously assigned by the CryptCATAdminAcquireContext
/// function. This function has no associated import library. You must use the LoadLibrary and GetProcAddress functions to
/// dynamically link to Wintrust.dll.
///
///
///
/// Catalog administrator context handle previously assigned by a call to the CryptCATAdminAcquireContext function.
///
/// Not used; set to zero.
/// The return value is TRUE if the function succeeds; FALSE if the function fails.
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatadminreleasecontext BOOL CryptCATAdminReleaseContext(
// IN HCATADMIN hCatAdmin, IN DWORD dwFlags );
[DllImport(Lib.Wintrust, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "dff253dc-c444-46be-a383-41340d634cce")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CryptCATAdminReleaseContext([In] HCATADMIN hCatAdmin, [In] uint dwFlags = 0);
///
///
/// [The CryptCATAdminRemoveCatalog function is available for use in the operating systems specified in the Requirements
/// section. It may be altered or unavailable in subsequent versions.]
///
///
/// The CryptCATAdminRemoveCatalog function deletes a catalog file and removes that catalog's entry from the Windows catalog
/// database. This function is the only supported way to remove catalogs from the database while ensuring the integrity of the
/// database. The function has no associated import library. You must use the LoadLibrary and GetProcAddress functions to
/// dynamically link to Wintrust.dll.
///
///
/// Handle previously assigned by the CryptCATAdminAcquireContext function.
///
/// A pointer to a null-terminated string for the name of the catalog to remove. This string must contain only the name, without any
/// path information.
///
/// This parameter is reserved for future use and must be set to zero.
///
/// The return value is TRUE if the function succeeds; FALSE if the function fails.
///
/// For extended error information, call the GetLastError function. For a complete list of error codes provided by the operating
/// system, see System Error Codes.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatadminremovecatalog BOOL CryptCATAdminRemoveCatalog( IN
// HCATADMIN hCatAdmin, IN LPCWSTR pwszCatalogFile, IN DWORD dwFlags );
[DllImport(Lib.Wintrust, SetLastError = true, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "e09fe991-0e7a-45da-910a-8cb148bdff9a")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CryptCATAdminRemoveCatalog(HCATADMIN hCatAdmin, [MarshalAs(UnmanagedType.LPWStr)] string pwszCatalogFile, uint dwFlags = 0);
///
///
/// [The CryptCATAdminResolveCatalogPath function is available for use in the operating systems specified in the Requirements
/// section. It may be altered or unavailable in subsequent versions.]
///
/// The CryptCATAdminResolveCatalogPath function retrieves the fully qualified path of the specified catalog.
///
/// Note This function has no associated import library. You must use the LoadLibrary and GetProcAddress functions to
/// dynamically link to Wintrust.dll.
///
///
/// A handle that was previously assigned by the CryptCATAdminAcquireContext function.
/// The name of the catalog file for which to retrieve the fully qualified path.
///
/// A pointer to the CATALOG_INFO structure. This value cannot be NULL. Upon return from this function, the wszCatalogFile
/// member of the CATALOG_INFO structure contains the catalog file name.
///
/// This parameter is reserved and must be set to zero.
///
/// Returns nonzero if successful or zero otherwise.
///
/// For extended error information, call the GetLastError function. For a complete list of error codes provided by the operating
/// system, see System Error Codes.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatadminresolvecatalogpath BOOL
// CryptCATAdminResolveCatalogPath( HCATADMIN hCatAdmin, WCHAR *pwszCatalogFile, CATALOG_INFO *psCatInfo, DWORD dwFlags );
[DllImport(Lib.Wintrust, SetLastError = true, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "bdbfa02d-8801-40d4-84f4-bc5a449bce50")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CryptCATAdminResolveCatalogPath(HCATADMIN hCatAdmin, [MarshalAs(UnmanagedType.LPWStr)] string pwszCatalogFile, ref CATALOG_INFO psCatInfo, uint dwFlags = 0);
///
///
/// [The CryptCATCatalogInfoFromContext function is available for use in the operating systems specified in the Requirements
/// section. It may be altered or unavailable in subsequent versions.]
///
///
/// The CryptCATCatalogInfoFromContext function retrieves catalog information from a specified catalog context. This function
/// has no associated import library. You must use the LoadLibrary and GetProcAddress functions to dynamically link to Wintrust.dll.
///
///
/// A handle to the catalog context. This value cannot be NULL.
///
/// A pointer to the CATALOG_INFO structure. This value cannot be NULL. Upon return from this function, the wszCatalogFile
/// member of the CATALOG_INFO structure contains the catalog file name.
///
/// Unused; set to zero.
///
/// The return value is TRUE if the function succeeds; FALSE if the function fails.
///
/// For extended error information, call the GetLastError function. For a complete list of error codes provided by the operating
/// system, see System Error Codes.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatcataloginfofromcontext BOOL
// CryptCATCatalogInfoFromContext( HCATINFO hCatInfo, CATALOG_INFO *psCatInfo, DWORD dwFlags );
[DllImport(Lib.Wintrust, SetLastError = true, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "ec195fcc-1cff-4dd6-9075-c4904b653da7")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CryptCATCatalogInfoFromContext(HCATINFO hCatInfo, ref CATALOG_INFO psCatInfo, uint dwFlags = 0);
///
///
/// [The CryptCATCDFClose function is available for use in the operating systems specified in the Requirements section. It
/// may be altered or unavailable in subsequent versions.]
///
///
/// The CryptCATCDFClose function closes a catalog definition file (CDF) and frees the memory for the corresponding
/// CRYPTCATCDF structure. CryptCATCDFClose is called by MakeCat.
///
///
/// A pointer to a CRYPTCATCDF structure.
///
/// Upon success, this function returns TRUE. The CryptCATCDFClose function returns FALSE with an
/// ERROR_INVALID_PARAMETER error if it fails.
///
///
/// Before closing the catalog output file specified in pCDF, the CryptCATCDFClose function signs and persists it to the file system.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatcdfclose BOOL CryptCATCDFClose( IN CRYPTCATCDF *pCDF );
[DllImport(Lib.Wintrust, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "9f2a1175-f9fe-4f4d-bf6f-e4f4c59739ec")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CryptCATCDFClose(IntPtr pCDF);
///
///
/// [The CryptCATCDFEnumCatAttributes function is available for use in the operating systems specified in the Requirements
/// section. It may be altered or unavailable in subsequent versions.]
///
///
/// The CryptCATCDFEnumCatAttributes function enumerates catalog-level attributes within the CatalogHeader section of
/// a catalog definition file (CDF). CryptCATCDFEnumCatAttributes is called by MakeCat.
///
///
/// A pointer to a CRYPTCATCDF structure.
/// A pointer to a CRYPTCATATTRIBUTE structure for a catalog attribute in the CDF pointed to by pCDF.
/// A pointer to a user-defined function to handle file parse errors.
///
/// Upon success, this function returns a pointer to a CRYPTCATATTRIBUTE structure. The CryptCATCDFEnumCatAttributes function
/// returns a NULL pointer if it fails.
///
///
///
/// You typically call this function in a loop to enumerate all of the catalog header attributes in a CDF. Before entering the loop,
/// set pPrevAttr to NULL. The function returns a pointer to the first attribute. Set pPrevAttr to the return value of the
/// function for subsequent iterations of the loop.
///
/// Examples
/// The following example shows the correct sequence of assignments for the pPrevAttr parameter ().
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatcdfenumcatattributes CRYPTCATATTRIBUTE *
// CryptCATCDFEnumCatAttributes( CRYPTCATCDF *pCDF, CRYPTCATATTRIBUTE *pPrevAttr, PFN_CDF_PARSE_ERROR_CALLBACK pfnParseError );
[DllImport(Lib.Wintrust, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "01889cb9-7bf4-4591-9bb2-b263c4effe0c")]
public static extern IntPtr CryptCATCDFEnumCatAttributes(SafeCRYPTCATCDF pCDF, IntPtr pPrevAttr, PfnCdfParseErrorCallback pfnParseError);
///
///
/// [The CryptCATCDFOpen function is available for use in the operating systems specified in the Requirements section. It may
/// be altered or unavailable in subsequent versions.]
///
///
/// The CryptCATCDFOpen function opens an existing catalog definition file (CDF) for reading and initializes a CRYPTCATCDF
/// structure. CryptCATCDFOpen is called by MakeCat.
///
///
/// A pointer to a null-terminated string that contains the path of the CDF file to open.
/// A pointer to a user-defined function to handle file parse errors.
///
/// Upon success, this function returns a pointer to the newly created CRYPTCATCDF structure. The CryptCATCDFOpen function
/// returns a NULL pointer if it fails.
///
///
///
/// The following default values are used by the CryptCATCDFOpen function for given conditions in the CDF
/// CatalogHeader section.
///
///
///
/// CatalogHeader condition
/// Default value
///
/// -
/// No Name value is specified.
/// The file name in pwszFilePath is used for the catalog (.cat) output file.
///
/// -
/// No PublicVersion value is specified.
/// 0x00000001
///
/// -
/// No EncodingType value is specified.
/// PKCS_7_ASN_ENCODING or X509_ASN_ENCODING (0x00010001)
///
///
/// The following actions are performed by the CryptCATCDFOpen function for given error conditions.
///
///
/// Error condition
/// Action performed
///
/// -
/// No CatalogHeader or Name tags are found in CDF.
///
/// If specified by the caller, the CryptCATCDFOpen function calls the function specified by pfnParseError and returns a NULL pointer.
///
///
/// -
///
/// The CryptCATCDFOpen function calls the CryptCATOpen function to get a handle to the catalog (.cat) output file, but it gets an
/// invalid or NULL handle.
///
/// Calls the CryptCATCDFClose function and returns a NULL pointer.
///
///
///
///
/// Additional OIDs for the Catalog branch
/// Definition
///
/// -
/// szOID_CATALOG_LIST_MEMBER_V2
/// 1.3.6.1.4.1.311.12.1.3
///
/// -
/// CAT_MEMBERINFO2_OBJID
/// 1.3.6.1.4.1.311.12.2.3
///
///
///
/// Windows Server 2008 R2, Windows 7, Windows Server 2008, Windows Vista, Windows Server 2003 and Windows XP: The additional
/// Catalog OIDs are not available.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatcdfopen CRYPTCATCDF * CryptCATCDFOpen( LPWSTR
// pwszFilePath, PFN_CDF_PARSE_ERROR_CALLBACK pfnParseError );
[DllImport(Lib.Wintrust, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "d400d8bd-c0a0-41dc-9093-8e4fc758d82f")]
public static extern SafeCRYPTCATCDF CryptCATCDFOpen([MarshalAs(UnmanagedType.LPWStr)] string pwszFilePath, PfnCdfParseErrorCallback pfnParseError);
///
///
/// [The CryptCATClose function is available for use in the operating systems specified in the Requirements section. It may
/// be altered or unavailable in subsequent versions.]
///
///
/// The CryptCATClose function closes a catalog handle opened previously by the CryptCATOpen function. This function has no
/// associated import library. You must use the LoadLibrary and GetProcAddress functions to dynamically link to Wintrust.dll.
///
///
/// Handle opened previously by a call to the CryptCATOpen function.
/// The return value is TRUE if the function succeeds; FALSE if the function fails.
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatclose BOOL CryptCATClose( IN HANDLE hCatalog );
[DllImport(Lib.Wintrust, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "f6fa2d10-0049-4d5e-9688-566e5c11d64e")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CryptCATClose(HCATALOG hCatalog);
///
///
/// [The CryptCATEnumerateAttr function is available for use in the operating systems specified in the Requirements section.
/// It may be altered or unavailable in subsequent versions.]
///
///
/// The CryptCATEnumerateAttr function enumerates the attributes associated with a member of a catalog. This function has no
/// associated import library. You must use the LoadLibrary and GetProcAddress functions to dynamically link to Wintrust.dll.
///
///
/// Handle for the catalog that contains the member identified by pCatMember. This value cannot be NULL.
/// A pointer to the CRYPTCATMEMBER structure that identifies which member of the catalog is being enumerated.
///
/// A pointer to the previously returned value from this function or pointer to NULL to start the enumeration.
///
///
/// The return value is a pointer to the CRYPTCATATTRIBUTE structure that contains the attribute information or NULL, if no
/// more attributes are in the enumeration or if an error is encountered. The returned pointer is passed in as the pPrevAttr
/// parameter for subsequent calls to this function.
///
/// Do not free the returned pointer nor any of the members pointed to by the returned pointer.
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatenumerateattr CRYPTCATATTRIBUTE *
// CryptCATEnumerateAttr( IN HANDLE hCatalog, IN CRYPTCATMEMBER *pCatMember, IN CRYPTCATATTRIBUTE *pPrevAttr );
[DllImport(Lib.Wintrust, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "064e87db-4330-4b8b-9865-ba8b9714f6e4")]
public static extern IntPtr CryptCATEnumerateAttr(HCATALOG hCatalog, in CRYPTCATMEMBER pCatMember, IntPtr pPrevAttr);
///
///
/// [The CryptCATEnumerateCatAttr function is available for use in the operating systems specified in the Requirements
/// section. It may be altered or unavailable in subsequent versions.]
///
///
/// The CryptCATEnumerateCatAttr function enumerates the attributes associated with a catalog. This function has no
/// associated import library. You must use the LoadLibrary and GetProcAddress functions to dynamically link to Wintrust.dll.
///
///
/// Handle for the catalog whose attributes are being enumerated. This value cannot be NULL.
///
/// A pointer to the previously returned pointer to the CRYPTCATATTRIBUTE structure from this function or pointer to NULL to
/// start the enumeration.
///
///
/// The return value is a pointer to the CRYPTCATATTRIBUTE structure that contains the attribute information or NULL, if no
/// more attributes are in the enumeration or if an error is encountered. The returned pointer is passed in as the pPrevAttr
/// parameter for subsequent calls to this function.
///
/// Do not free the returned pointer nor any of the members pointed to by the returned pointer.
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatenumeratecatattr CRYPTCATATTRIBUTE *
// CryptCATEnumerateCatAttr( IN HANDLE hCatalog, IN CRYPTCATATTRIBUTE *pPrevAttr );
[DllImport(Lib.Wintrust, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "57b6ff5c-e47e-41ac-8ec8-01a47ea77acf")]
public static extern IntPtr CryptCATEnumerateCatAttr(HCATALOG hCatalog, IntPtr pPrevAttr);
///
///
/// [The CryptCATEnumerateMember function is available for use in the operating systems specified in the Requirements
/// section. It may be altered or unavailable in subsequent versions.]
///
/// The CryptCATEnumerateMember function enumerates the members of a catalog.
///
/// The handle of the catalog that contains the members to enumerate. This value cannot be NULL.
///
/// A pointer to a CRYPTCATMEMBER structure that identifies which member of the catalog was last retrieved. If this parameter is
/// NULL, this function will retrieve the first member of the catalog.
///
///
/// This function returns a pointer to a CRYPTCATMEMBER structure that represents the next member of the catalog. If there are no
/// more members in the catalog to enumerate, this function returns NULL.
///
///
/// Do not free the returned pointer nor any of the members pointed to by the returned pointer.
/// Examples
/// The following pseudocode example shows how to use this function to enumerate all of the members of a catalog.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatenumeratemember CRYPTCATMEMBER *
// CryptCATEnumerateMember( IN HANDLE hCatalog, IN CRYPTCATMEMBER *pPrevMember );
[DllImport(Lib.Wintrust, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "6bbfef11-a150-4255-8620-27c1b1587b48")]
public static extern IntPtr CryptCATEnumerateMember(HCATALOG hCatalog, IntPtr pPrevMember);
///
///
/// [The CryptCATGetAttrInfo function is available for use in the operating systems specified in the Requirements section. It
/// may be altered or unavailable in subsequent versions.]
///
/// The CryptCATGetAttrInfo function retrieves information about an attribute of a member of a catalog.
///
///
/// The handle of the catalog that contains the member to retrieve the attribute information for. This handle is obtained by calling
/// the CryptCATOpen function. This parameter is required and cannot be NULL.
///
///
/// A pointer to a CRYPTCATMEMBER structure that represents the member to retrieve the attribute information for. This can be
/// obtained by calling the CryptCATGetMemberInfo function. This parameter is required and cannot be NULL.
///
///
/// A pointer to a null-terminated Unicode string that contains the name of the attribute to retrieve the information for. This
/// parameter is required and cannot be NULL.
///
///
///
/// This function returns a pointer to a CRYPTCATATTRIBUTE structure that contains the attribute information. If the function fails,
/// it returns NULL.
///
/// Important Do not free the returned pointer nor any of the members pointed to by the returned pointer.
///
/// If this function returns NULL, additional error information can be obtained by calling the GetLastError function.
/// GetLastError will return one of the following error codes.
///
///
///
/// Return code
/// Description
///
/// -
/// CRYPT_E_NOT_FOUND
/// The member or the attribute could not be found.
///
/// -
/// ERROR_INVALID_PARAMETER
/// One or more of the parameters are not valid.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatgetattrinfo CRYPTCATATTRIBUTE * CryptCATGetAttrInfo( IN
// HANDLE hCatalog, IN CRYPTCATMEMBER *pCatMember, LPWSTR pwszReferenceTag );
[DllImport(Lib.Wintrust, SetLastError = true, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "e36966ea-741e-4380-85cd-5a3c9db38e6d")]
public static extern IntPtr CryptCATGetAttrInfo(HCATALOG hCatalog, in CRYPTCATMEMBER pCatMember, [MarshalAs(UnmanagedType.LPWStr)] string pwszReferenceTag);
///
///
/// [The CryptCATGetMemberInfo function is available for use in the operating systems specified in the Requirements section.
/// It may be altered or unavailable in subsequent versions.]
///
///
/// The CryptCATGetMemberInfo function retrieves member information from the catalog's PKCS #7. In addition to retrieving the
/// member information for a specified reference tag, this function opens a member context. This function has no associated import
/// library. You must use the LoadLibrary and GetProcAddress functions to dynamically link to Wintrust.dll.
///
///
/// A handle to the catalog. This parameter cannot be NULL.
///
/// A pointer to a null-terminated string that represents the reference tag for the member information being retrieved.
///
///
/// A pointer to the CRYPTCATMEMBER structure that contains the member information or NULL, if no information can be found.
///
/// Do not free the returned pointer nor any of the members pointed to by the returned pointer.
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatgetmemberinfo CRYPTCATMEMBER * CryptCATGetMemberInfo(
// IN HANDLE hCatalog, LPWSTR pwszReferenceTag );
[DllImport(Lib.Wintrust, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "ff265232-f57e-4ab0-ba07-05e6d6745ae3")]
public static extern IntPtr CryptCATGetMemberInfo(HCATALOG hCatalog, [MarshalAs(UnmanagedType.LPWStr)] string pwszReferenceTag);
///
///
/// [The CryptCATHandleFromStore function is available for use in the operating systems specified in the Requirements
/// section. It may be altered or unavailable in subsequent versions.]
///
/// The CryptCATHandleFromStore function retrieves a catalog handle from memory.
///
/// A pointer to a CRYPTCATSTORE structure that contains the handle to retrieve.
/// A handle to the catalog.
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcathandlefromstore HANDLE CryptCATHandleFromStore( IN
// CRYPTCATSTORE *pCatStore );
[DllImport(Lib.Wintrust, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "e9aedc2d-9492-4ed7-9f2d-891997f85f6f")]
public static extern SafeHCATALOG CryptCATHandleFromStore(in CRYPTCATSTORE pCatStore);
///
///
/// [The CryptCATOpen function is available for use in the operating systems specified in the Requirements section. It may be
/// altered or unavailable in subsequent versions.]
///
/// The CryptCATOpen function opens a catalog and returns a context handle to the open catalog.
///
/// Note Some older versions of Wintrust.lib do not contain the export information for this function. In this case, you must
/// use the LoadLibrary and GetProcAddress functions to dynamically link to Wintrust.dll.
///
///
/// A pointer to a null-terminated string for the catalog file name.
///
/// Zero, to open an existing catalog file, or a bitwise combination of one or more of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// CRYPTCAT_OPEN_ALWAYS
/// Opens the file, if it exists, or creates a new file, if needed.
///
/// -
/// CRYPTCAT_OPEN_CREATENEW
/// A new catalog file is created. If a previously created file exists, it is overwritten.
///
///
///
/// A handle to a cryptographic service provider (CSP).
///
/// Version of the file. This can be one of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// CRYPTCAT_VERSION_1 0x100
/// Version 1 file format.
///
/// -
/// CRYPTCAT_VERSION_2 0x200
/// Version 2 file format. Windows 8 and Windows Server 2012: Support for this value begins.
///
///
///
///
/// Encoding type used for the file. If this value is 0, then the encoding type is set to PKCS_7_ASN_ENCODING | X509_ASN_ENCODING.
///
///
/// Upon success, this function returns a handle to the open catalog. When you have finished using the handle, close it by calling
/// the CryptCATClose function. The CryptCATOpen function returns INVALID_HANDLE_VALUE if it fails.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatopen HANDLE CryptCATOpen( LPWSTR pwszFileName, IN DWORD
// fdwOpenFlags, IN HCRYPTPROV hProv, IN DWORD dwPublicVersion, IN DWORD dwEncodingType );
[DllImport(Lib.Wintrust, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "e81f3a3d-d5b7-4266-838d-b83e331c8594")]
public static extern SafeHCATALOG CryptCATOpen([MarshalAs(UnmanagedType.LPWStr)] string pwszFileName, CRYPTCAT_OPEN fdwOpenFlags, [In] HCRYPTPROV hProv, [In] CRYPTCAT_VERSION dwPublicVersion, CertEncodingType dwEncodingType);
///
///
/// [The CryptCATPersistStore function is available for use in the operating systems specified in the Requirements section.
/// It may be altered or unavailable in subsequent versions.]
///
/// The CryptCATPersistStore function saves the information in the specified catalog store to an unsigned catalog file.
///
///
/// A handle to the catalog obtained from CryptCATHandleFromStore or CryptCATOpen function. Beginning with Windows 8 you must use
/// only CryptCATOpen to retrieve a handle.
///
///
/// The return value is TRUE if the function succeeds; otherwise, FALSE.
///
/// If this function returns FALSE, additional error information can be obtained by calling the GetLastError function.
/// GetLastError will return the following error code.
///
///
///
/// Return code
/// Description
///
/// -
/// ERROR_INVALID_PARAMETER
/// One or more of the parameters are not valid.
///
/// -
/// ERROR_NOT_SUPPORTED
///
/// Beginning with Windows 8 and Windows Server 2012, you must retrieve a handle by calling the CryptCATOpen function with the
/// dwPublicVersion parameter set to 0x100 or 0x200. For more information, see Remarks.
///
///
///
///
///
/// The pwszP7File member of the CRYPTCATSTORE structure must be initialized before you call CryptCATPersistStore.
/// Beginning with Windows 8 and Windows Server 2012, the following changes apply to this function:
///
/// -
/// If CryptCATOpen was called with a dwPublicVersion parameter of 0x200, the catalog is written by using the v2 format.
///
/// -
/// If CryptCATOpen was called with a dwPublicVersion parameter of 0x100, the catalog is written by using the v1 format.
///
/// -
///
/// If CryptCATOpen was called with a dwPublicVersion parameter other than 0x200 or 0x100, the CryptCATPersistStore function
/// returns FALSE and the error code is set to ERROR_NOT_SUPPORTED.
///
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatpersiststore BOOL CryptCATPersistStore( IN HANDLE
// hCatalog );
[DllImport(Lib.Wintrust, SetLastError = true, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "2a564b0e-fcc6-4702-8173-d18df7064e53")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CryptCATPersistStore([In] HCATALOG hCatalog);
///
///
/// [The CryptCATPutAttrInfo function is available for use in the operating systems specified in the Requirements section. It
/// may be altered or unavailable in subsequent versions.]
///
/// The CryptCATPutAttrInfo function allocates memory for an attribute and adds it to a catalog member.
///
/// A handle to the catalog obtained from the CryptCATOpen or CryptCATHandleFromStore function.
/// A pointer to a CRYPTCATMEMBER structure that contains the catalog member.
/// A pointer to a null-terminated string that contains the name of the attribute.
///
///
/// A value that represents a bitwise combination of the following flags. The caller must at least specify
/// CRYPTCAT_ATTR_DATABASE64 or CRYPTCAT_ATTR_DATAASCII.
///
///
///
/// Value
/// Meaning
///
/// -
/// CRYPTCAT_ATTR_AUTHENTICATED 0x10000000
/// The attribute is authenticated.
///
/// -
/// CRYPTCAT_ATTR_UNAUTHENTICATED 0x20000000
/// The attribute is unauthenticated.
///
/// -
/// CRYPTCAT_ATTR_NAMEASCII 0x00000001
/// The attribute is an ASCII string.
///
/// -
/// CRYPTCAT_ATTR_NAMEOBJID 0x00000002
/// The attribute is a cryptographic object identifier (OID).
///
/// -
/// CRYPTCAT_ATTR_DATAASCII 0x00010000
/// The attribute contains simple ASCII characters that should not be decoded.
///
/// -
/// CRYPTCAT_ATTR_DATABASE64 0x00020000
/// The attribute is in base 64 format.
///
/// -
/// CRYPTCAT_ATTR_DATAREPLACE 0x00040000
/// The attribute replaces the value for an existing attribute.
///
///
///
/// A value that specifies the number of bytes in the pbData buffer.
/// A pointer to a memory buffer that contains the attribute value.
///
///
/// Upon success, this function returns a pointer to a CRYPTCATATTRIBUTE structure that contains the assigned attribute. The caller
/// must not free this pointer or any of its members.
///
///
/// If this function returns NULL, additional error information can be obtained by calling the GetLastError function.
/// GetLastError will return one of the following error codes.
///
///
///
/// Return code
/// Description
///
/// -
/// ERROR_INVALID_PARAMETER
/// One or more of the parameters are not valid.
///
/// -
/// ERROR_NOT_ENOUGH_MEMORY
/// The operating system ran out of memory during the operation.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatputattrinfo CRYPTCATATTRIBUTE * CryptCATPutAttrInfo( IN
// HANDLE hCatalog, IN CRYPTCATMEMBER *pCatMember, LPWSTR pwszReferenceTag, IN DWORD dwAttrTypeAndAction, IN DWORD cbData, IN BYTE
// *pbData );
[DllImport(Lib.Wintrust, SetLastError = true, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "13d5cdb4-2a15-4442-9e11-c3f76ca03f7e")]
public static extern IntPtr CryptCATPutAttrInfo([In] HCATALOG hCatalog, in CRYPTCATMEMBER pCatMember, [MarshalAs(UnmanagedType.LPWStr)] string pwszReferenceTag, [In] CRYPTCAT_ATTR dwAttrTypeAndAction, [In] uint cbData, [In] IntPtr pbData);
///
///
/// [The CryptCATPutCatAttrInfo function is available for use in the operating systems specified in the Requirements section.
/// It may be altered or unavailable in subsequent versions.]
///
/// The CryptCATPutCatAttrInfo function allocates memory for a catalog file attribute and adds it to the catalog.
///
/// A handle to the catalog obtained from the CryptCATOpen or CryptCATHandleFromStore functions.
/// A pointer to a null-terminated string for the name of the attribute.
///
///
/// A value that represents a bitwise combination of the following flags. The caller must at least specify
/// CRYPTCAT_ATTR_DATAASCII or CRYPTCAT_ATTR_DATABASE64.
///
///
///
/// Value
/// Meaning
///
/// -
/// CRYPTCAT_ATTR_AUTHENTICATED 0x10000000
/// The attribute is authenticated.
///
/// -
/// CRYPTCAT_ATTR_UNAUTHENTICATED 0x20000000
/// The attribute is unauthenticated.
///
/// -
/// CRYPTCAT_ATTR_NAMEASCII 0x00000001
/// The attribute is an ASCII string.
///
/// -
/// CRYPTCAT_ATTR_NAMEOBJID 0x00000002
/// The attribute is a cryptographic object identifier (OID).
///
/// -
/// CRYPTCAT_ATTR_DATAASCII 0x00010000
/// The attribute contains simple ASCII characters that should not be decoded.
///
/// -
/// CRYPTCAT_ATTR_DATABASE64 0x00020000
/// The attribute is in base 64 format.
///
/// -
/// CRYPTCAT_ATTR_DATAREPLACE 0x00040000
/// The attribute replaces the value for an existing attribute.
///
///
///
/// A value that specifies the number of bytes in the pbData buffer.
/// A pointer to a memory buffer that contains the attribute value.
///
///
/// A pointer to a CRYPTCATATTRIBUTE structure that contains the catalog attribute. The caller must not free this pointer or any of
/// its members.
///
///
/// If this function returns NULL, additional error information can be obtained by calling the GetLastError function.
/// GetLastError will return one of the following error codes.
///
///
///
/// Return code
/// Description
///
/// -
/// ERROR_INVALID_PARAMETER
/// One or more of the parameters are not valid.
///
/// -
/// ERROR_NOT_ENOUGH_MEMORY
/// The operating system ran out of memory during the operation.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatputcatattrinfo CRYPTCATATTRIBUTE *
// CryptCATPutCatAttrInfo( IN HANDLE hCatalog, LPWSTR pwszReferenceTag, IN DWORD dwAttrTypeAndAction, IN DWORD cbData, IN BYTE
// *pbData );
[DllImport(Lib.Wintrust, SetLastError = true, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "16bb8560-d4fc-4c81-8eed-21a2da7f396d")]
public static extern IntPtr CryptCATPutCatAttrInfo(HCATALOG hCatalog, [MarshalAs(UnmanagedType.LPWStr)] string pwszReferenceTag, [In] CRYPTCAT_ATTR dwAttrTypeAndAction, [In] uint cbData, [In] IntPtr pbData);
///
///
/// [The CryptCATPutMemberInfo function is available for use in the operating systems specified in the Requirements section.
/// It may be altered or unavailable in subsequent versions.]
///
/// The CryptCATPutMemberInfo function allocates memory for a catalog member and adds it to the catalog.
///
/// A handle to the catalog obtained from the CryptCATOpen or CryptCATHandleFromStore function.
/// A pointer to a null-terminated string for the catalog file name.
/// A pointer to a null-terminated string that contains the name of the member.
/// A GUID for the subject type of the member.
/// A value that specifies the certificate version.
/// A value that specifies the number of bytes in the pbSIPIndirectData buffer.
/// A pointer to a memory buffer for subject interface package (SIP)-indirect data.
///
///
/// A pointer to a CRYPTCATMEMBER structure that contains the assigned member. The caller must not free this pointer or any of its members.
///
///
/// If this function returns NULL, additional error information can be obtained by calling the GetLastError function.
/// GetLastError will return one of the following error codes.
///
///
///
/// Return code
/// Description
///
/// -
/// ERROR_INVALID_PARAMETER
/// One or more of the parameters are not valid.
///
/// -
/// ERROR_NOT_ENOUGH_MEMORY
/// The operating system ran out of memory during the operation.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatputmemberinfo CRYPTCATMEMBER * CryptCATPutMemberInfo(
// IN HANDLE hCatalog, LPWSTR pwszFileName, LPWSTR pwszReferenceTag, IN GUID *pgSubjectType, IN DWORD dwCertVersion, IN DWORD
// cbSIPIndirectData, IN BYTE *pbSIPIndirectData );
[DllImport(Lib.Wintrust, SetLastError = true, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "bfc10577-e32e-4b2e-ad24-1d0a85c6730a")]
public static extern IntPtr CryptCATPutMemberInfo([In] HCATALOG hCatalog, [MarshalAs(UnmanagedType.LPWStr)] string pwszFileName, [MarshalAs(UnmanagedType.LPWStr)] string pwszReferenceTag, in Guid pgSubjectType, [In] uint dwCertVersion, [In] uint cbSIPIndirectData, [In] IntPtr pbSIPIndirectData);
///
///
/// [The CryptCATStoreFromHandle function is available for use in the operating systems specified in the Requirements
/// section. It may be altered or unavailable in subsequent versions.]
///
/// The CryptCATStoreFromHandle function retrieves a CRYPTCATSTORE structure from a catalog handle.
///
/// A handle to the catalog obtained from the CryptCATOpen or CryptCATHandleFromStore function.
///
/// A pointer to a CRYPTCATSTORE structure that contains the catalog store. The caller must not free this pointer or any of its members.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-cryptcatstorefromhandle CRYPTCATSTORE *
// CryptCATStoreFromHandle( IN HANDLE hCatalog );
[DllImport(Lib.Wintrust, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "ce4fe972-0ed5-4b18-8ec5-9883af326335")]
public static extern IntPtr CryptCATStoreFromHandle([In] HCATALOG hCatalog);
///
///
/// [The IsCatalogFile function is available for use in the operating systems specified in the Requirements section. It may
/// be altered or unavailable in subsequent versions.]
///
/// The IsCatalogFile function retrieves a Boolean value that indicates whether the specified file is a catalog file.
///
/// Note This function has no associated import library. You must use the LoadLibrary and GetProcAddress functions to
/// dynamically link to Wintrust.dll.
///
///
///
/// A handle to the file to check. This parameter is optional, but it must contain a valid handle if the pwszFileName parameter is NULL.
///
///
/// A pointer to a null-terminated wide character string that contains the name of the file to check. This parameter is optional,
/// but it must contain a valid file name if the hFile parameter is NULL.
///
/// Returns nonzero if the specified file is a catalog file or zero otherwise.
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/nf-mscat-iscatalogfile BOOL IsCatalogFile( IN HANDLE hFile, WCHAR
// *pwszFileName );
[DllImport(Lib.Wintrust, SetLastError = false, ExactSpelling = true)]
[PInvokeData("mscat.h", MSDNShortId = "eeba34d4-08aa-456a-8fdc-16795cbce36a")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool IsCatalogFile([In] HFILE hFile, [MarshalAs(UnmanagedType.LPWStr)] string pwszFileName);
[DllImport(Lib.Wintrust, SetLastError = true, EntryPoint = "CryptCATAdminAddCatalog")]
private static extern IntPtr InternalCryptCATAdminAddCatalog(HCATADMIN hCatAdmin, [MarshalAs(UnmanagedType.LPWStr)] string pwszCatalogFile, [MarshalAs(UnmanagedType.LPWStr), Optional] string pwszSelectBaseName, uint dwFlags);
[DllImport(Lib.Wintrust, SetLastError = true, EntryPoint = "CryptCATAdminEnumCatalogFromHash")]
private static extern IntPtr InternalCryptCATAdminEnumCatalogFromHash(HCATADMIN hCatAdmin, IntPtr pbHash, uint cbHash, [Optional] uint dwFlags, ref HCATINFO phPrevCatInfo);
///
///
/// [The CATALOG_INFO structure is available for use in the operating systems specified in the Requirements section. It may
/// be altered or unavailable in subsequent versions.]
///
///
/// The CATALOG_INFO structure contains the name of a catalog file. This structure is used by the
/// CryptCATCatalogInfoFromContext function.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/ns-mscat-catalog_info typedef struct CATALOG_INFO_ { DWORD cbStruct;
// WCHAR wszCatalogFile[MAX_PATH]; } CATALOG_INFO;
[PInvokeData("mscat.h", MSDNShortId = "f6e66412-3ed2-48d9-a377-5df11500db59")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct CATALOG_INFO
{
/// Specifies the size, in bytes, of this structure.
public uint cbStruct;
/// Name of the catalog file.
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string wszCatalogFile;
}
///
///
/// [The CRYPTCATATTRIBUTE structure is available for use in the operating systems specified in the Requirements section. It
/// may be altered or unavailable in subsequent versions.]
///
///
/// The CRYPTCATATTRIBUTE structure defines a catalog attribute. This structure is used by the CryptCATEnumerateAttr and
/// CryptCATEnumerateCatAttr functions.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/ns-mscat-cryptcatattribute typedef struct CRYPTCATATTRIBUTE_ { DWORD
// cbStruct; LPWSTR pwszReferenceTag; DWORD dwAttrTypeAndAction; DWORD cbValue; BYTE *pbValue; DWORD dwReserved; } CRYPTCATATTRIBUTE;
[PInvokeData("mscat.h", MSDNShortId = "41b91303-f3eb-4288-9ad2-98f170680988")]
[StructLayout(LayoutKind.Sequential)]
public struct CRYPTCATATTRIBUTE
{
/// The size, in bytes, of this structure.
public uint cbStruct;
/// A pointer to a null-terminated string that contains the reference tag value.
[MarshalAs(UnmanagedType.LPWStr)] public string pwszReferenceTag;
///
/// Bitwise combination of the following flags.
///
///
/// Value
/// Meaning
///
/// -
/// CRYPTCAT_ATTR_AUTHENTICATED 0x10000000
/// The attribute is authenticated.
///
/// -
/// CRYPTCAT_ATTR_UNAUTHENTICATED 0x20000000
/// The attribute is unauthenticated.
///
/// -
/// CRYPTCAT_ATTR_NAMEASCII 0x00000001
/// The attribute is an ASCII string.
///
/// -
/// CRYPTCAT_ATTR_NAMEOBJID 0x00000002
/// The attribute is a cryptographic object identifier (OID).
///
/// -
/// CRYPTCAT_ATTR_DATAASCII 0x00010000
/// The attribute contains simple ASCII characters that should not be decoded.
///
/// -
/// CRYPTCAT_ATTR_DATABASE64 0x00020000
/// The attribute is in base 64 format.
///
/// -
/// CRYPTCAT_ATTR_DATAREPLACE 0x00040000
/// The attribute replaces the value for an existing attribute.
///
///
///
public CRYPTCAT_ATTR dwAttrTypeAndAction;
/// Number of bytes used by pbValue.
public uint cbValue;
/// A pointer to the encoded bytes.
public IntPtr pbValue;
/// Reserved; do not use.
public uint dwReserved;
}
///
///
/// [The CRYPTCATCDF structure is available for use in the operating systems specified in the Requirements section. It may be
/// altered or unavailable in subsequent versions.]
///
///
/// The CRYPTCATCDF structure contains information used to create a signed catalog file (.cat) from a catalog definition file
/// (CDF). This structure is used by the MakeCat tool.
///
///
///
/// A parser can update dwCurFilePos and dwLastMemberOffset as it reads the CDF. A user-defined callback function can use this
/// information for recoverable parse errors in the CDF.
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/ns-mscat-cryptcatcdf typedef struct CRYPTCATCDF_ { DWORD cbStruct;
// HANDLE hFile; DWORD dwCurFilePos; DWORD dwLastMemberOffset; BOOL fEOF; LPWSTR pwszResultDir; HANDLE hCATStore; } CRYPTCATCDF;
[PInvokeData("mscat.h", MSDNShortId = "15d5710a-d4df-4e45-b161-5d4f7509ba29")]
[StructLayout(LayoutKind.Sequential)]
public struct CRYPTCATCDF
{
/// The size, in bytes, of this structure.
public uint cbStruct;
/// A handle to the catalog definition file (.cdf).
public HFILE hFile;
///
/// A value that specifies the current position of the parser measured in bytes from the beginning of the catalog definition file.
///
public uint dwCurFilePos;
///
/// A value that specifies the number of bytes to the position of the last member parsed in the catalog definition file.
///
public uint dwLastMemberOffset;
///
/// An integer that indicates whether the parser finished reading the file. TRUE indicates that the last read operation
/// returned zero bytes.
///
[MarshalAs(UnmanagedType.Bool)] public bool fEOF;
///
/// A pointer to a null-terminated string that contains the name of a directory where the catalog file (.cat) will be written.
///
[MarshalAs(UnmanagedType.LPWStr)] public string pwszResultDir;
/// A handle to the catalog file (.cat).
public HANDLE hCATStore;
}
///
///
/// [The CRYPTCATMEMBER structure is available for use in the operating systems specified in the Requirements section. It may
/// be altered or unavailable in subsequent versions.]
///
///
/// The CRYPTCATMEMBER structure provides information about a catalog member. This structure is used by the
/// CryptCATGetMemberInfo and CryptCATEnumerateAttr functions.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/ns-mscat-cryptcatmember typedef struct CRYPTCATMEMBER_ { DWORD cbStruct;
// LPWSTR pwszReferenceTag; LPWSTR pwszFileName; GUID gSubjectType; DWORD fdwMemberFlags; struct SIP_INDIRECT_DATA_ *pIndirectData;
// DWORD dwCertVersion; DWORD dwReserved; HANDLE hReserved; CRYPT_ATTR_BLOB sEncodedIndirectData; CRYPT_ATTR_BLOB
// sEncodedMemberInfo; } CRYPTCATMEMBER;
[PInvokeData("mscat.h", MSDNShortId = "08f663d9-9dc2-4ac9-95c5-7f2ed972eb9b")]
[StructLayout(LayoutKind.Sequential)]
public struct CRYPTCATMEMBER
{
/// The size, in bytes, of this structure.
public uint cbStruct;
/// A pointer to a null-terminated string that contains the reference tag value.
[MarshalAs(UnmanagedType.LPWStr)] public string pwszReferenceTag;
/// A pointer to a null-terminated string that contains the file name.
[MarshalAs(UnmanagedType.LPWStr)] public string pwszFileName;
/// GUID that identifies the subject type.
public Guid gSubjectType;
/// Value that specifies the member flags.
public uint fdwMemberFlags;
/// A pointer to a SIP_INDIRECT_DATA structure.
public IntPtr pIndirectData;
/// Value that specifies the certificate version.
public uint dwCertVersion;
/// Reserved; do not use.
public uint dwReserved;
/// Reserved; do not use.
public HANDLE hReserved;
/// A CRYPT_ATTR_BLOB structure that contains encoded indirect data.
public CRYPTOAPI_BLOB sEncodedIndirectData;
/// A CRYPT_ATTR_BLOB structure that contains encoded member information.
public CRYPTOAPI_BLOB sEncodedMemberInfo;
}
///
///
/// [The CRYPTCATSTORE structure is available for use in the operating systems specified in the Requirements section. It may
/// be altered or unavailable in subsequent versions.]
///
///
/// The CRYPTCATSTORE structure represents a catalog file. The CryptCATStoreFromHandle function populates this structure by
/// using the handle returned by CryptCATOpen.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/mscat/ns-mscat-cryptcatstore typedef struct CRYPTCATSTORE_ { DWORD cbStruct;
// DWORD dwPublicVersion; LPWSTR pwszP7File; HCRYPTPROV hProv; DWORD dwEncodingType; DWORD fdwStoreFlags; HANDLE hReserved; HANDLE
// hAttrs; HCRYPTMSG hCryptMsg; HANDLE hSorted; } CRYPTCATSTORE;
[PInvokeData("mscat.h", MSDNShortId = "65a15797-453c-4f47-8ea1-c92e616b50aa")]
[StructLayout(LayoutKind.Sequential)]
public struct CRYPTCATSTORE
{
/// The size, in bytes, of this structure.
public uint cbStruct;
/// A value that specifies the "PublicVersion" of the catalog file.
public uint dwPublicVersion;
///
/// A pointer to a null-terminated string that contains the name of the catalog file. This member must be initialized before a
/// call to the CryptCATPersistStore function.
///
[MarshalAs(UnmanagedType.LPWStr)] public string pwszP7File;
/// A handle to the cryptographic service provider (CSP).
public HCRYPTPROV hProv;
///
/// A value that specifies the encoding type used for the file. Currently, only X509_ASN_ENCODING and PKCS_7_ASN_ENCODING are
/// being used; however, additional encoding types may be added in the future. For either current encoding type, use:
/// X509_ASN_ENCODING | PKCS_7_ASN_ENCODING.
///
public CertEncodingType dwEncodingType;
///
/// A bitwise combination of the following values.
///
///
/// Value
/// Meaning
///
/// -
/// CRYPTCAT_OPEN_EXCLUDE_PAGE_HASHES 0x00010000
/// Exclude page hashes in SPC_INDIRECT_DATA.
///
/// -
/// CRYPTCAT_OPEN_FLAGS_MASK 0xffff0000
/// For all flags with a value in the upper word, set or clear the flag.
///
/// -
/// CRYPTCAT_OPEN_INCLUDE_PAGE_HASHES 0x00020000
///
/// Include page hashes in SPC_INDIRECT_DATA. The CRYPTCAT_OPEN_EXCLUDE_PAGE_HASHES flag takes precedence if it is also set.
///
///
/// -
/// CRYPTCAT_OPEN_NO_CONTENT_HCRYPTMSG 0x20000000
/// Open the file for decoding without detached content.
///
/// -
/// CRYPTCAT_OPEN_SORTED 0x40000000
/// Open the catalog with the entries sorted alphabetically by subject.
///
/// -
/// CRYPTCAT_OPEN_VERIFYSIGHASH 0x10000000
/// Verify the signature hash but not the certificate chain.
///
///
///
public CRYPTCAT_OPEN fdwStoreFlags;
/// This member is reserved and must be NULL.
public HANDLE hReserved;
/// This member is reserved and must be NULL.
public HANDLE hAttrs;
///
/// A handle to the decoded bytes. This member is only set if the file was opened with the
/// CRYPTCAT_OPEN_NO_CONTENT_HCRYPTMSG flag set.
///
public HCRYPTMSG hCryptMsg;
/// This member is reserved and must be NULL.
public HANDLE hSorted;
}
/// Provides a handle to a catalog.
[StructLayout(LayoutKind.Sequential)]
public struct HCATALOG : IHandle
{
private IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HCATALOG(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HCATALOG NULL => new HCATALOG(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HCATALOG h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HCATALOG(IntPtr h) => new HCATALOG(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HCATALOG h1, HCATALOG h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HCATALOG h1, HCATALOG h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HCATALOG h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a handle to a catalog information context.
[StructLayout(LayoutKind.Sequential)]
public struct HCATINFO : IHandle
{
private readonly IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public HCATINFO(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Returns an invalid handle by instantiating a object with .
public static HCATINFO NULL => new HCATINFO(IntPtr.Zero);
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(HCATINFO h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator HCATINFO(IntPtr h) => new HCATINFO(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(HCATINFO h1, HCATINFO h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(HCATINFO h1, HCATINFO h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is HCATINFO h ? handle == h.handle : false;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// Provides a for that is disposed using .
public class SafeCRYPTCATCDF : SafeHANDLE
{
/// Initializes a new instance of the class and assigns an existing handle.
/// An object that represents the pre-existing handle to use.
///
/// to reliably release the handle during the finalization phase; otherwise, (not recommended).
///
public SafeCRYPTCATCDF(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { }
/// Initializes a new instance of the class.
private SafeCRYPTCATCDF() : base() { }
///
/// Gets the structure with the data behind this handle. If the handle is invalid, this value is the default for the structure.
///
public CRYPTCATCDF Value => IsInvalid ? default : handle.ToStructure();
/// Performs an implicit conversion from to .
/// The safe handle instance.
/// The result of the conversion.
public static implicit operator CRYPTCATCDF(SafeCRYPTCATCDF h) => h.Value;
///
protected override bool InternalReleaseHandle() => CryptCATCDFClose(handle);
}
/// Provides a for that is disposed using .
public class SafeHCATADMIN : SafeHANDLE
{
/// Initializes a new instance of the class and assigns an existing handle.
/// An object that represents the pre-existing handle to use.
///
/// to reliably release the handle during the finalization phase; otherwise, (not recommended).
///
public SafeHCATADMIN(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { }
/// Initializes a new instance of the class.
private SafeHCATADMIN() : base() { }
/// Performs an implicit conversion from to .
/// The safe handle instance.
/// The result of the conversion.
public static implicit operator HCATADMIN(SafeHCATADMIN h) => h.handle;
///
protected override bool InternalReleaseHandle() => CryptCATAdminReleaseContext(handle);
}
/// Provides a for that is disposed using .
public class SafeHCATALOG : SafeHANDLE
{
/// Initializes a new instance of the class and assigns an existing handle.
/// An object that represents the pre-existing handle to use.
///
/// to reliably release the handle during the finalization phase; otherwise, (not recommended).
///
public SafeHCATALOG(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { }
/// Initializes a new instance of the class.
private SafeHCATALOG() : base() { }
/// Performs an implicit conversion from to .
/// The safe handle instance.
/// The result of the conversion.
public static implicit operator HCATALOG(SafeHCATALOG h) => h.handle;
///
protected override bool InternalReleaseHandle() => CryptCATClose(handle);
}
/// Provides a for that is disposed using .
public class SafeHCATINFO : SafeHANDLE
{
private readonly SafeHCATADMIN hAdmin;
/// Initializes a new instance of the class and assigns an existing handle.
/// An object that represents the pre-existing handle to use.
/// A handle to Category Administrator context.
///
/// to reliably release the handle during the finalization phase; otherwise, (not recommended).
///
public SafeHCATINFO(IntPtr preexistingHandle, SafeHCATADMIN hCatAdmin, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) =>
hAdmin = hCatAdmin ?? throw new ArgumentNullException(nameof(hCatAdmin));
/// Initializes a new instance of the class.
private SafeHCATINFO() : base() { }
/// Performs an implicit conversion from to .
/// The safe handle instance.
/// The result of the conversion.
public static implicit operator HCATINFO(SafeHCATINFO h) => h.handle;
///
protected override bool InternalReleaseHandle() => CryptCATAdminReleaseCatalogContext(hAdmin, handle);
}
}
}