asn1-dump.cpp revision 30d5bd8604e5b514b0e4f6360c0384ab1c7851fe
/* $Id$ */
/** @file
* IPRT - ASN.1, Structure Dumper.
*/
/*
* Copyright (C) 2006-2014 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 *
*******************************************************************************/
#ifdef IN_RING3
#endif
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* Dump data structure.
*/
typedef struct RTASN1DUMPDATA
{
/** RTASN1DUMP_F_XXX. */
/** The printfv like output function. */
/** PrintfV user argument. */
void *pvUser;
/** Pointer to a dump data structure. */
typedef RTASN1DUMPDATA *PRTASN1DUMPDATA;
/**
* Wrapper around FNRTASN1DUMPPRINTFV.
*
* @param pData The dump data structure.
* @param pszFormat Format string.
* @param ... Format arguments.
*/
{
}
/**
* Prints indentation.
*
* @param pData The dump data structure.
* @param uDepth The indentation depth.
*/
{
uint32_t i = 0;
uDepth *= 2;
while (i < uDepth)
{
static char const s_szSpaces[] = " ";
i += cch;
}
}
/**
* Dumps UTC TIME and GENERALIZED TIME
*
* @param pData The dump data structure.
* @param pAsn1Core The ASN.1 core object representation.
* @param pszType The time type name.
*/
{
{
}
else
}
/**
* Dumps strings sharing the RTASN1STRING structure.
*
* @param pData The dump data structure.
* @param pAsn1Core The ASN.1 core object representation.
* @param pszType The string type name.
* @param uDepth The current identation level.
*/
static void rtAsn1DumpString(PRTASN1DUMPDATA pData, PCRTASN1CORE pAsn1Core, const char *pszType, uint32_t uDepth)
{
const char *pszPostfix = "'\n";
bool fUtf8 = false;
{
fUtf8 = true;
pszPostfix = "' -- utf-8\n";
}
else
{
if (cch >= 48)
{
}
/** @todo Handle BMP and UNIVERSIAL strings specially. */
do
{
while ( cch > 0
&& *pch != '\'')
while ( cch > 0
{
cch--;
pch++;
}
} while (cch > 0);
}
}
/**
* Returns a name for the given object ID.
*
* This is just to make some of the dumps a little easier to read. It's no our
* intention to have the whole ODI repository encoded here.
*
* @returns Name if available, NULL if not.
* @param pszObjId The dotted object identifier string.
*/
static const char *rtAsn1DumpLookupObjIdName(const char *pszObjId)
{
( pszObjId[a_off] == (a_uValue) / 10 + '0' && pszObjId[a_off + 1] == (a_uValue) % 10 + '0' && pszObjId[a_off + 2] == '.' )
( pszObjId[a_off] == (a_uValue) / 10 + '0' && pszObjId[a_off + 1] == (a_uValue) % 10 + '0' && !pszObjId[a_off + 2] )
if (STARTS_WITH_1(0, 0)) /* ITU-T assigned - top level 0. */
{
}
{
{
/* */
}
{
{
{
{
{
}
{
}
}
{
}
}
}
}
{
{
{
{
{
{
{
}
{
{
}
{
}
}
{
{
}
}
{
{
}
{
}
{
}
}
{
}
{
}
}
}
}
{
{
{
{
}
{
}
{
}
}
}
}
}
}
{
{
{
}
}
}
}
}
{
{
}
{
{
}
{
{
}
}
}
{
if (0)
{
}
{
{
{
{
{
{
}
{
}
}
}
}
{
{
}
{
}
}
{
{
{
}
{
{
}
}
{
}
{
}
{
}
}
}
}
}
}
}
return NULL;
}
/**
* Dumps the type and value of an universal ASN.1 type.
*
* @returns True if it opens a child, false if not.
* @param pData The dumper data.
* @param pAsn1Core The ASN.1 object to dump.
* @param uDepth The current depth (for indentation).
*/
static bool rtAsn1DumpUniversalTypeAndValue(PRTASN1DUMPDATA pData, PCRTASN1CORE pAsn1Core, uint32_t uDepth)
{
const char *pszValuePrefix = "-- value:";
const char *pszDefault = "";
{
pszValuePrefix = "DEFAULT";
pszDefault = "DEFAULT ";
}
bool fOpen = false;
{
case ASN1_TAG_BOOLEAN:
rtAsn1DumpPrintf(pData, "BOOLEAN %s %RTbool\n", pszValuePrefix, ((PCRTASN1BOOLEAN)pAsn1Core)->fValue);
else
break;
case ASN1_TAG_INTEGER:
rtAsn1DumpPrintf(pData, "INTEGER %s %.*Rhxs\n", pszValuePrefix, (size_t)pAsn1Core->cb, pAsn1Core->uData.pu8);
else
rtAsn1DumpPrintf(pData, "INTEGER %s\n%.*Rhxd\n", pszValuePrefix, (size_t)pAsn1Core->cb, pAsn1Core->uData.pu8);
break;
case ASN1_TAG_BIT_STRING:
{
else
}
else
break;
case ASN1_TAG_OCTET_STRING:
break;
case ASN1_TAG_NULL:
break;
case ASN1_TAG_OID:
{
if (pszObjIdName)
else
rtAsn1DumpPrintf(pData, "OBJECT IDENTIFIER %s'%s'\n", pszDefault, ((PCRTASN1OBJID)pAsn1Core)->szObjId);
}
else
break;
break;
case ASN1_TAG_EXTERNAL:
break;
case ASN1_TAG_REAL:
break;
case ASN1_TAG_ENUMERATED:
break;
case ASN1_TAG_EMBEDDED_PDV:
break;
case ASN1_TAG_UTF8_STRING:
break;
case ASN1_TAG_RELATIVE_OID:
break;
case ASN1_TAG_SEQUENCE:
fOpen = true;
break;
case ASN1_TAG_SET:
fOpen = true;
break;
case ASN1_TAG_NUMERIC_STRING:
break;
break;
case ASN1_TAG_T61_STRING:
break;
case ASN1_TAG_VIDEOTEX_STRING:
break;
case ASN1_TAG_IA5_STRING:
break;
case ASN1_TAG_GRAPHIC_STRING:
break;
case ASN1_TAG_VISIBLE_STRING:
break;
case ASN1_TAG_GENERAL_STRING:
break;
break;
case ASN1_TAG_BMP_STRING:
break;
case ASN1_TAG_UTC_TIME:
break;
break;
break;
default:
break;
}
return fOpen;
}
/** @callback_method_impl{FNRTASN1ENUMCALLBACK} */
static DECLCALLBACK(int) rtAsn1DumpEnumCallback(PRTASN1CORE pAsn1Core, const char *pszName, uint32_t uDepth, void *pvUser)
{
return VINF_SUCCESS;
bool fOpen = false;
{
case ASN1_TAGCLASS_UNIVERSAL:
break;
case ASN1_TAGCLASS_CONTEXT:
{
}
else
{
fOpen = true;
}
break;
{
}
else
{
fOpen = true;
}
break;
case ASN1_TAGCLASS_PRIVATE:
if (RTASN1CORE_IS_DUMMY(pAsn1Core))
else
{
fOpen = true;
}
break;
}
/** @todo {} */
/*
* Recurse.
*/
return VINF_SUCCESS;
}
RTDECL(int) RTAsn1Dump(PCRTASN1CORE pAsn1Core, uint32_t fFlags, uint32_t uLevel, PFNRTDUMPPRINTFV pfnPrintfV, void *pvUser)
{
{
}
return VINF_SUCCESS;
}