tstRTDigest.cpp revision fc659761c3e27dad0ce26752ed131bd4b7763b3b
/* $Id$ */
/** @file
* IPRT Testcase - RTSha*, RTMd5, RTCrc*.
*/
/*
* Copyright (C) 2009-2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/initterm.h>
{
char szName[RTPATH_MAX];
return 1;
}
static int MyReadFile(RTFILE hFile, void *pvBuf, size_t cbToRead, size_t *pcbRead, uint64_t *pcbMaxLeft)
{
int rc = VINF_SUCCESS;
if (*pcbMaxLeft > 0)
{
if (cbToRead > *pcbMaxLeft)
if (RT_SUCCESS(rc))
*pcbMaxLeft -= *pcbRead;
}
else
*pcbRead = 0;
return rc;
}
static char *MyGetNextSignificantLine(PRTSTREAM pFile, char *pszBuf, size_t cbBuf, uint32_t *piLine, int *prc)
{
for (;;)
{
*pszBuf = '\0';
if (RT_FAILURE(rc))
{
{
return NULL;
}
if (!*pszBuf)
return NULL;
}
*piLine += 1;
/* Significant? */
return pszStart;
}
}
{
const char *pszDigestType = "NotSpecified";
enum
{
} enmMethod = kMethod_Block;
bool fTestcase = false;
static const RTGETOPTDEF s_aOptions[] =
{
};
int ch;
RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, RTGETOPTINIT_FLAGS_OPTS_FIRST);
{
switch (ch)
{
case 't':
{
pszDigestType = "CRC32";
}
{
pszDigestType = "CRC64";
}
{
pszDigestType = "MD2";
}
{
pszDigestType = "MD5";
}
{
pszDigestType = "SHA-1";
}
{
pszDigestType = "SHA-224";
}
{
pszDigestType = "SHA-256";
}
{
pszDigestType = "SHA-384";
}
{
pszDigestType = "SHA-512";
}
{
pszDigestType = "SHA-512/224";
}
{
pszDigestType = "SHA-512/256";
}
else
{
return 1;
}
break;
case 'm':
else
{
return 1;
}
break;
case 'l':
break;
case 'o':
break;
case 'x':
fTestcase = true;
break;
case 'h':
RTPrintf("usage: tstRTDigest -t <digest-type> [-o <offset>] [-l <length>] [-x] file [file2 [..]]\n");
return 1;
case VINF_GETOPT_NOT_OPTION:
{
if (enmDigestType == RTDIGESTTYPE_INVALID)
return Error("No digest type was specified\n");
switch (enmMethod)
{
case kMethod_Full:
return Error("Full file method is not implemented\n");
case kMethod_File:
return Error("The -l and -o options do not work with the 'file' method.");
switch (enmDigestType)
{
case RTDIGESTTYPE_SHA1:
{
char *pszDigest;
if (RT_FAILURE(rc))
break;
}
case RTDIGESTTYPE_SHA256:
{
char *pszDigest;
if (RT_FAILURE(rc))
break;
}
default:
return Error("The file method isn't implemented for this digest\n");
}
break;
case kMethod_Block:
{
if (RT_FAILURE(rc))
if (offStart != 0)
{
if (RT_FAILURE(rc))
}
switch (enmDigestType)
{
case RTDIGESTTYPE_CRC32:
{
for (;;)
{
break;
}
break;
}
case RTDIGESTTYPE_CRC64:
{
for (;;)
{
break;
}
break;
}
case RTDIGESTTYPE_MD2:
{
for (;;)
{
break;
}
break;
}
case RTDIGESTTYPE_MD5:
{
for (;;)
{
break;
}
break;
}
case RTDIGESTTYPE_SHA1:
{
RTSha1Init(&Ctx);
for (;;)
{
break;
}
break;
}
case RTDIGESTTYPE_SHA256:
{
RTSha256Init(&Ctx);
for (;;)
{
break;
}
break;
}
case RTDIGESTTYPE_SHA512:
{
RTSha512Init(&Ctx);
for (;;)
{
break;
}
break;
}
default:
return Error("Internal error #1\n");
}
{
}
if (!fTestcase)
else if (offStart)
RTPrintf(" { &g_abRandom72KB[%#4llx], %5llu, \"%s\", \"%s %llu bytes @%llu\" },\n",
else
RTPrintf(" { &g_abRandom72KB[0], %5llu, \"%s\", \"%s %llu bytes\" },\n",
break;
}
/*
* Process a SHS response file:
*/
case kMethod_CVAS:
{
if (RT_FAILURE(rc))
if (RT_FAILURE(rc))
/*
* Parse the input file.
* ASSUME order: Len, Msg, MD.
*/
char *psz;
for (;;)
{
if (!psz)
break;
/* Skip [L = 20] stuff. */
if (*psz == '[')
continue;
/* Message length. */
if (rc != VINF_SUCCESS)
/* The message text. */
if (!psz)
if (cbMessage > 0)
{
if (rc != VINF_SUCCESS)
return Error("%s(%d): Error parsing message '%.10s...': %Rrc\n",
}
/* The message digest. */
if (!psz)
if (rc != VINF_SUCCESS)
return Error("%s(%d): Error parsing message digest '%.10s...': %Rrc\n",
/*
* Do the testing.
*/
if (rc != VINF_SUCCESS)
if (rc != VINF_SUCCESS)
if (rc != VINF_SUCCESS)
cPassed++;
else
{
Error("%s(%d): Message digest mismatch. Expected %.*RThxs, got %.*RThxs.",
cErrors++;
}
}
if (cErrors > 0)
if (RT_FAILURE(rc))
break;
}
default:
return Error("Internal error #2\n");
}
break;
}
default:
}
}
return 0;
}