crypt32: Abstract function used to read from reading a serialized store.
This commit is contained in:
parent
ceddc0ae1b
commit
51a1f5a642
|
@ -425,14 +425,18 @@ const void *CRYPT_ReadSerializedElement(const BYTE *pbElement, DWORD cbElement,
|
||||||
|
|
||||||
static const BYTE fileHeader[] = { 0, 0, 0, 0, 'C','E','R','T' };
|
static const BYTE fileHeader[] = { 0, 0, 0, 0, 'C','E','R','T' };
|
||||||
|
|
||||||
BOOL CRYPT_ReadSerializedStoreFromFile(HANDLE file, HCERTSTORE store)
|
typedef BOOL (*read_serialized_func)(void *handle, void *buffer,
|
||||||
|
DWORD bytesToRead, DWORD *bytesRead);
|
||||||
|
|
||||||
|
static BOOL CRYPT_ReadSerializedStore(void *handle,
|
||||||
|
read_serialized_func read_func, HCERTSTORE store)
|
||||||
{
|
{
|
||||||
BYTE fileHeaderBuf[sizeof(fileHeader)];
|
BYTE fileHeaderBuf[sizeof(fileHeader)];
|
||||||
DWORD read;
|
DWORD read;
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
|
|
||||||
/* Failure reading is non-critical, we'll leave the store empty */
|
/* Failure reading is non-critical, we'll leave the store empty */
|
||||||
ret = ReadFile(file, fileHeaderBuf, sizeof(fileHeaderBuf), &read, NULL);
|
ret = read_func(handle, fileHeaderBuf, sizeof(fileHeaderBuf), &read);
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
if (!read)
|
if (!read)
|
||||||
|
@ -448,7 +452,7 @@ BOOL CRYPT_ReadSerializedStoreFromFile(HANDLE file, HCERTSTORE store)
|
||||||
DWORD bufSize = 0;
|
DWORD bufSize = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
ret = ReadFile(file, &propHdr, sizeof(propHdr), &read, NULL);
|
ret = read_func(handle, &propHdr, sizeof(propHdr), &read);
|
||||||
if (ret && read == sizeof(propHdr))
|
if (ret && read == sizeof(propHdr))
|
||||||
{
|
{
|
||||||
if (contextInterface && context &&
|
if (contextInterface && context &&
|
||||||
|
@ -470,7 +474,7 @@ BOOL CRYPT_ReadSerializedStoreFromFile(HANDLE file, HCERTSTORE store)
|
||||||
}
|
}
|
||||||
if (buf)
|
if (buf)
|
||||||
{
|
{
|
||||||
ret = ReadFile(file, buf, propHdr.cb, &read, NULL);
|
ret = read_func(handle, buf, propHdr.cb, &read);
|
||||||
if (ret && read == propHdr.cb)
|
if (ret && read == propHdr.cb)
|
||||||
{
|
{
|
||||||
if (propHdr.propID == CERT_CERT_PROP_ID)
|
if (propHdr.propID == CERT_CERT_PROP_ID)
|
||||||
|
@ -519,6 +523,17 @@ BOOL CRYPT_ReadSerializedStoreFromFile(HANDLE file, HCERTSTORE store)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static BOOL read_file_wrapper(void *handle, void *buffer, DWORD bytesToRead,
|
||||||
|
DWORD *bytesRead)
|
||||||
|
{
|
||||||
|
return ReadFile(handle, buffer, bytesToRead, bytesRead, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL CRYPT_ReadSerializedStoreFromFile(HANDLE file, HCERTSTORE store)
|
||||||
|
{
|
||||||
|
return CRYPT_ReadSerializedStore(file, read_file_wrapper, store);
|
||||||
|
}
|
||||||
|
|
||||||
static BOOL WINAPI CRYPT_SerializeCertNoHash(PCCERT_CONTEXT pCertContext,
|
static BOOL WINAPI CRYPT_SerializeCertNoHash(PCCERT_CONTEXT pCertContext,
|
||||||
DWORD dwFlags, BYTE *pbElement, DWORD *pcbElement)
|
DWORD dwFlags, BYTE *pbElement, DWORD *pcbElement)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue