asn1-dump.cpp revision 4ee2f4fc8e99dc69ba5d63fd7dd3f52a38d0501e
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott * IPRT - ASN.1, Structure Dumper.
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott * Copyright (C) 2006-2014 Oracle Corporation
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott * This file is part of VirtualBox Open Source Edition (OSE), as
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott * available from http://www.virtualbox.org. This file is free software;
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott * you can redistribute it and/or modify it under the terms of the GNU
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott * General Public License (GPL) as published by the Free Software
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott * Foundation, in version 2 as it comes in the "COPYING" file of the
c9f1d3043c1f8394a35ebfd5aad3bdeb841e55dfPhill Cunnington * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott * The contents of this file may alternatively be used under the terms
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott * of the Common Development and Distribution License Version 1.0
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott * VirtualBox OSE distribution, in which case the provisions of the
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott * CDDL are applicable instead of those of the GPL.
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott * You may elect to license modified versions of this file under the
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott * terms and conditions of either the GPL or the CDDL or both.
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott/*******************************************************************************
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott* Header Files *
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott*******************************************************************************/
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott/*******************************************************************************
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott* Structures and Typedefs *
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott*******************************************************************************/
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott * Dump data structure.
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott /** RTASN1DUMP_F_XXX. */
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott /** The printfv like output function. */
3cf8f706326bda47e94caecf3edf58153fcab100Andrew Forrest /** PrintfV user argument. */
3cf8f706326bda47e94caecf3edf58153fcab100Andrew Forrest/** Pointer to a dump data structure. */
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott * Wrapper around FNRTASN1DUMPPRINTFV.
3cf8f706326bda47e94caecf3edf58153fcab100Andrew Forrest * @param pData The dump data structure.
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott * @param pszFormat Format string.
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott * @param ... Format arguments.
3cf8f706326bda47e94caecf3edf58153fcab100Andrew Forreststatic void rtAsn1DumpPrintf(PRTASN1DUMPDATA pData, const char *pszFormat, ...)
3cf8f706326bda47e94caecf3edf58153fcab100Andrew Forrest pData->pfnPrintfV(pData->pvUser, pszFormat, va);
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott * Prints indentation.
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott * @param pData The dump data structure.
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott * @param uDepth The indentation depth.
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshottstatic void rtAsn1DumpPrintIdent(PRTASN1DUMPDATA pData, uint32_t uDepth)
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott uint32_t cch = RT_MIN(cchLeft, sizeof(s_szSpaces) - 1);
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott rtAsn1DumpPrintf(pData, &s_szSpaces[sizeof(s_szSpaces) - 1 - cch]);
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott * Dumps UTC TIME and GENERALIZED TIME
c9017e00251ffc95555d06319dd89fe1df9a2724Robert Wapshott * @param pData The dump data structure.
c9017e00251ffc95555d06319dd89fe1df9a2724Robert Wapshott * @param pAsn1Core The ASN.1 core object representation.
c9017e00251ffc95555d06319dd89fe1df9a2724Robert Wapshott * @param pszType The time type name.
c9017e00251ffc95555d06319dd89fe1df9a2724Robert Wapshottstatic void rtAsn1DumpTime(PRTASN1DUMPDATA pData, PCRTASN1CORE pAsn1Core, const char *pszType)
c9017e00251ffc95555d06319dd89fe1df9a2724Robert Wapshott if ((pAsn1Core->fFlags & RTASN1CORE_F_PRIMITE_TAG_STRUCT))
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott PCRTASN1TIME pTime = (PCRTASN1TIME)pAsn1Core;
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott rtAsn1DumpPrintf(pData, "%s -- %04u-%02u-%02u %02u:%02u:%02.%09Z\n",
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott pTime->Time.i32Year, pTime->Time.u8Month, pTime->Time.u8MonthDay,
e87637336bc6799910991bebc7cda8d7966eb4d5Robert Wapshott pTime->Time.u8Hour, pTime->Time.u8Minute, pTime->Time.u8Second,
static void rtAsn1DumpString(PRTASN1DUMPDATA pData, PCRTASN1CORE pAsn1Core, const char *pszType, uint32_t uDepth)
bool fUtf8 = false;
fUtf8 = true;
while ( cch > 0
while ( cch > 0
cch--;
pch++;
} while (cch > 0);
( 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] )
return NULL;
static bool rtAsn1DumpUniversalTypeAndValue(PRTASN1DUMPDATA pData, PCRTASN1CORE pAsn1Core, uint32_t uDepth)
bool fOpen = false;
case ASN1_TAG_BOOLEAN:
rtAsn1DumpPrintf(pData, "BOOLEAN %s %RTbool\n", pszValuePrefix, ((PCRTASN1BOOLEAN)pAsn1Core)->fValue);
case ASN1_TAG_INTEGER:
rtAsn1DumpPrintf(pData, "INTEGER %s %.*Rhxs\n", pszValuePrefix, (size_t)pAsn1Core->cb, pAsn1Core->uData.pu8);
rtAsn1DumpPrintf(pData, "INTEGER %s\n%.*Rhxd\n", pszValuePrefix, (size_t)pAsn1Core->cb, pAsn1Core->uData.pu8);
case ASN1_TAG_BIT_STRING:
case ASN1_TAG_OCTET_STRING:
case ASN1_TAG_NULL:
case ASN1_TAG_OID:
if (pszObjIdName)
rtAsn1DumpPrintf(pData, "OBJECT IDENTIFIER %s'%s'\n", pszDefault, ((PCRTASN1OBJID)pAsn1Core)->szObjId);
case ASN1_TAG_EXTERNAL:
case ASN1_TAG_REAL:
case ASN1_TAG_ENUMERATED:
case ASN1_TAG_EMBEDDED_PDV:
case ASN1_TAG_UTF8_STRING:
case ASN1_TAG_RELATIVE_OID:
case ASN1_TAG_SEQUENCE:
fOpen = true;
case ASN1_TAG_SET:
fOpen = true;
case ASN1_TAG_NUMERIC_STRING:
case ASN1_TAG_T61_STRING:
case ASN1_TAG_VIDEOTEX_STRING:
case ASN1_TAG_IA5_STRING:
case ASN1_TAG_GRAPHIC_STRING:
case ASN1_TAG_VISIBLE_STRING:
case ASN1_TAG_GENERAL_STRING:
case ASN1_TAG_BMP_STRING:
case ASN1_TAG_UTC_TIME:
return fOpen;
static DECLCALLBACK(int) rtAsn1DumpEnumCallback(PRTASN1CORE pAsn1Core, const char *pszName, uint32_t uDepth, void *pvUser)
return VINF_SUCCESS;
bool fOpen = false;
case ASN1_TAGCLASS_UNIVERSAL:
case ASN1_TAGCLASS_CONTEXT:
fOpen = true;
fOpen = true;
case ASN1_TAGCLASS_PRIVATE:
fOpen = true;
return VINF_SUCCESS;
RTDECL(int) RTAsn1Dump(PCRTASN1CORE pAsn1Core, uint32_t fFlags, uint32_t uLevel, PFNRTDUMPPRINTFV pfnPrintfV, void *pvUser)
return VINF_SUCCESS;