13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/* $Id$ */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** @file
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * IPRT - ASN.1, Basic Operations.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/*
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Copyright (C) 2006-2014 Oracle Corporation
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * available from http://www.virtualbox.org. This file is free software;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * you can redistribute it and/or modify it under the terms of the GNU
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * General Public License (GPL) as published by the Free Software
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * The contents of this file may alternatively be used under the terms
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * of the Common Development and Distribution License Version 1.0
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * VirtualBox OSE distribution, in which case the provisions of the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * CDDL are applicable instead of those of the GPL.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * You may elect to license modified versions of this file under the
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * terms and conditions of either the GPL or the CDDL or both.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/*******************************************************************************
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync* Header Files *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync*******************************************************************************/
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#include "internal/iprt.h"
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#include <iprt/asn1.h>
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#include <iprt/alloca.h>
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#include <iprt/err.h>
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#include <iprt/string.h>
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#include <iprt/ctype.h>
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync#include <iprt/formats/asn1.h>
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync/*******************************************************************************
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync* Defined Constants And Macros *
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync*******************************************************************************/
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync/** @def RTASN1_MAX_NESTING
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync * The maximum nesting depth we allow. This limit is enforced to avoid running
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync * out of stack due to malformed ASN.1 input.
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync *
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync * For reference, 'RTSignTool verify-exe RTSignTool.exe', requires a value of 15
4ee2f4fc8e99dc69ba5d63fd7dd3f52a38d0501evboxsync * to work without hitting the limit for signatures with simple timestamps, and
4ee2f4fc8e99dc69ba5d63fd7dd3f52a38d0501evboxsync * 23 (amd64/rel = ~3KB) for the new microsoft timestamp counter signatures.
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync */
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync#ifdef IN_RING3
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync# define RTASN1_MAX_NESTING 64
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync#else
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync# define RTASN1_MAX_NESTING 32
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync#endif
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/*******************************************************************************
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync* Global Variables *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync*******************************************************************************/
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncstatic char const g_achDigits[11] = "0123456789";
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(PRTASN1CURSOR) RTAsn1CursorInitPrimary(PRTASN1CURSORPRIMARY pPrimaryCursor, void const *pvFirst, uint32_t cb,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync PRTERRINFO pErrInfo, PCRTASN1ALLOCATORVTABLE pAllocator, uint32_t fFlags,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync const char *pszErrorTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pPrimaryCursor->Cursor.pbCur = (uint8_t const *)pvFirst;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pPrimaryCursor->Cursor.cbLeft = cb;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pPrimaryCursor->Cursor.fFlags = fFlags;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pPrimaryCursor->Cursor.cDepth = 0;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pPrimaryCursor->Cursor.abReserved[0] = 0;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pPrimaryCursor->Cursor.abReserved[1] = 0;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pPrimaryCursor->Cursor.pPrimary = pPrimaryCursor;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pPrimaryCursor->Cursor.pUp = NULL;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pPrimaryCursor->Cursor.pszErrorTag = pszErrorTag;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pPrimaryCursor->pErrInfo = pErrInfo;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pPrimaryCursor->pAllocator = pAllocator;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return &pPrimaryCursor->Cursor;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsyncRTDECL(int) RTAsn1CursorInitSub(PRTASN1CURSOR pParent, uint32_t cb, PRTASN1CURSOR pChild, const char *pszErrorTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync AssertReturn(pParent->pPrimary, VERR_ASN1_INTERNAL_ERROR_1);
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync AssertReturn(pParent->pbCur, VERR_ASN1_INTERNAL_ERROR_2);
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pChild->pbCur = pParent->pbCur;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pChild->cbLeft = cb;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pChild->fFlags = pParent->fFlags;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pChild->cDepth = pParent->cDepth + 1;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync AssertReturn(pChild->cDepth < RTASN1_MAX_NESTING, VERR_ASN1_TOO_DEEPLY_NESTED);
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pChild->abReserved[0] = 0;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pChild->abReserved[1] = 0;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pChild->pPrimary = pParent->pPrimary;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pChild->pUp = pParent;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pChild->pszErrorTag = pszErrorTag;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync AssertReturn(pParent->cbLeft >= cb, VERR_ASN1_INTERNAL_ERROR_3);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pParent->pbCur += cb;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pParent->cbLeft -= cb;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync return VINF_SUCCESS;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsyncRTDECL(int) RTAsn1CursorInitSubFromCore(PRTASN1CURSOR pParent, PRTASN1CORE pAsn1Core,
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync PRTASN1CURSOR pChild, const char *pszErrorTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync AssertReturn(pParent->pPrimary, VERR_ASN1_INTERNAL_ERROR_1);
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync AssertReturn(pParent->pbCur, VERR_ASN1_INTERNAL_ERROR_2);
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pChild->pbCur = pAsn1Core->uData.pu8;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pChild->cbLeft = pAsn1Core->cb;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pChild->fFlags = pParent->fFlags;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pChild->cDepth = pParent->cDepth + 1;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync AssertReturn(pChild->cDepth < RTASN1_MAX_NESTING, VERR_ASN1_TOO_DEEPLY_NESTED);
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pChild->abReserved[0] = 0;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pChild->abReserved[1] = 0;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pChild->pPrimary = pParent->pPrimary;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pChild->pUp = pParent;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pChild->pszErrorTag = pszErrorTag;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync return VINF_SUCCESS;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1CursorSetInfoV(PRTASN1CURSOR pCursor, int rc, const char *pszMsg, va_list va)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync PRTERRINFO pErrInfo = pCursor->pPrimary->pErrInfo;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (pErrInfo)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync {
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* Format the message. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync RTErrInfoSetV(pErrInfo, rc, pszMsg, va);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* Add the prefixes. This isn't the fastest way, but it's the one
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync which eats the least stack. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync char *pszBuf = pErrInfo->pszMsg;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync size_t cbBuf = pErrInfo->cbMsg;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (pszBuf && cbBuf > 32)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync {
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync size_t cbMove = strlen(pszBuf) + 1;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* Make sure there is a ': '. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync bool fFirst = false;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (pszMsg[0] != '%' || pszMsg[1] != 's' || pszMsg[2] != ':')
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync {
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (cbMove + 2 < cbBuf)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync {
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync memmove(pszBuf + 2, pszBuf, cbMove);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pszBuf[0] = ':';
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pszBuf[1] = ' ';
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync cbMove += 2;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync fFirst = true;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync }
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync }
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* Add the prefixes from the cursor chain. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync while (pCursor)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync {
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (pCursor->pszErrorTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync {
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync size_t cchErrorTag = strlen(pCursor->pszErrorTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (cchErrorTag + !fFirst + cbMove > cbBuf)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync break;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync memmove(pszBuf + cchErrorTag + !fFirst, pszBuf, cbMove);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync memcpy(pszBuf, pCursor->pszErrorTag, cchErrorTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (!fFirst)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pszBuf[cchErrorTag] = '.';
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync cbMove += cchErrorTag + !fFirst;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync fFirst = false;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync }
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pCursor = pCursor->pUp;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync }
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync }
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync }
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return rc;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1CursorSetInfo(PRTASN1CURSOR pCursor, int rc, const char *pszMsg, ...)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync va_list va;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync va_start(va, pszMsg);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync rc = RTAsn1CursorSetInfoV(pCursor, rc, pszMsg, va);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync va_end(va);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return rc;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1CursorCheckEnd(PRTASN1CURSOR pCursor)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (pCursor->cbLeft == 0)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return VINF_SUCCESS;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_NOT_AT_END,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "%u (%#x) bytes left over", pCursor->cbLeft, pCursor->cbLeft);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(PRTASN1ALLOCATION) RTAsn1CursorInitAllocation(PRTASN1CURSOR pCursor, PRTASN1ALLOCATION pAllocation)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAllocation->cbAllocated = 0;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAllocation->cReallocs = 0;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAllocation->uReserved0 = 0;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAllocation->pAllocator = pCursor->pPrimary->pAllocator;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return pAllocation;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1CursorReadHdr(PRTASN1CURSOR pCursor, PRTASN1CORE pAsn1Core, const char *pszErrorTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /*
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Initialize the return structure in case of failure.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAsn1Core->uTag = 0;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAsn1Core->fClass = 0;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAsn1Core->uRealTag = 0;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAsn1Core->fRealClass = 0;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAsn1Core->cbHdr = 0;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAsn1Core->cb = 0;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAsn1Core->fFlags = 0;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAsn1Core->uData.pv = NULL;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAsn1Core->pOps = NULL;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /*
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * The header has at least two bytes: Type & length.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (pCursor->cbLeft >= 2)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync {
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync uint32_t uTag = pCursor->pbCur[0];
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync uint32_t cb = pCursor->pbCur[1];
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pCursor->cbLeft -= 2;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pCursor->pbCur += 2;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAsn1Core->uRealTag = pAsn1Core->uTag = uTag & ASN1_TAG_MASK;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAsn1Core->fRealClass = pAsn1Core->fClass = uTag & ~ASN1_TAG_MASK;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAsn1Core->cbHdr = 2;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if ((uTag & ASN1_TAG_MASK) == ASN1_TAG_USE_LONG_FORM)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_LONG_TAG,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "%s: Implement parsing of tags > 30: %#x (length=%#x)", pszErrorTag, uTag, cb);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* Extended length field? */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (cb & RT_BIT(7))
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync {
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (cb != RT_BIT(7))
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync {
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* Definite form. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync uint8_t cbEnc = cb & 0x7f;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (cbEnc > pCursor->cbLeft)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_BAD_LENGTH_ENCODING,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "%s: Extended BER length field longer than available data: %#x vs %#x (uTag=%#x)",
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pszErrorTag, cbEnc, pCursor->cbLeft, uTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync switch (cbEnc)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync {
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync case 1:
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync cb = pCursor->pbCur[0];
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync break;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync case 2:
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync cb = RT_MAKE_U16(pCursor->pbCur[1], pCursor->pbCur[0]);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync break;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync case 3:
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync cb = RT_MAKE_U32_FROM_U8(pCursor->pbCur[2], pCursor->pbCur[1], pCursor->pbCur[0], 0);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync break;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync case 4:
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync cb = RT_MAKE_U32_FROM_U8(pCursor->pbCur[3], pCursor->pbCur[2], pCursor->pbCur[1], pCursor->pbCur[0]);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync break;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync default:
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_BAD_LENGTH_ENCODING,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "%s: Too long/short extended BER length field: %#x (uTag=%#x)",
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pszErrorTag, cbEnc, uTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync }
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pCursor->cbLeft -= cbEnc;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pCursor->pbCur += cbEnc;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAsn1Core->cbHdr += cbEnc;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* Check the length encoding efficiency (T-REC-X.690-200811 10.1, 9.1). */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (pCursor->fFlags & (RTASN1CURSOR_FLAGS_DER | RTASN1CURSOR_FLAGS_CER))
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync {
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (cb <= 0x7f)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_BAD_LENGTH_ENCODING,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "%s: Invalid DER/CER length encoding: cbEnc=%u cb=%#x uTag=%#x",
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pszErrorTag, cbEnc, cb, uTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync uint8_t cbNeeded;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (cb <= 0x000000ff) cbNeeded = 1;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync else if (cb <= 0x0000ffff) cbNeeded = 2;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync else if (cb <= 0x00ffffff) cbNeeded = 3;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync else cbNeeded = 4;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (cbNeeded != cbEnc)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_BAD_LENGTH_ENCODING,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "%s: Invalid DER/CER length encoding: cb=%#x uTag=%#x cbEnc=%u cbNeeded=%u",
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pszErrorTag, cb, uTag, cbEnc, cbNeeded);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync }
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync }
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* Indefinite form. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync else if (pCursor->fFlags & RTASN1CURSOR_FLAGS_DER)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_ILLEGAL_IDEFINITE_LENGTH,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "%s: Indefinite length form not allowed in DER mode (uTag=%#x).", pszErrorTag, uTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync else
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_IDEFINITE_LENGTH_NOT_SUP,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "%s: Indefinite BER/CER length not supported (uTag=%#x)", pszErrorTag, uTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync }
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* Check if the length makes sense. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (cb > pCursor->cbLeft)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_BAD_LENGTH,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "%s: BER value length out of bounds: %#x (max=%#x uTag=%#x)",
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pszErrorTag, cb, pCursor->cbLeft, uTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAsn1Core->fFlags |= RTASN1CORE_F_PRESENT | RTASN1CORE_F_DECODED_CONTENT;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAsn1Core->cb = cb;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAsn1Core->uData.pv = (void *)pCursor->pbCur;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return VINF_SUCCESS;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync }
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (pCursor->cbLeft)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_TOO_LITTLE_DATA_LEFT,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "%s: Too little data left to form a valid BER header", pszErrorTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_NO_MORE_DATA,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "%s: No more data reading BER header", pszErrorTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1CursorMatchTagClassFlagsEx(PRTASN1CURSOR pCursor, PRTASN1CORE pAsn1Core, uint32_t uTag, uint32_t fClass,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync bool fString, uint32_t fFlags, const char *pszErrorTag, const char *pszWhat)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (pAsn1Core->uTag == uTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync {
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (pAsn1Core->fClass == fClass)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return VINF_SUCCESS;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if ( fString
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync && pAsn1Core->fClass == (fClass | ASN1_TAGFLAG_CONSTRUCTED))
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync {
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (!(pCursor->fFlags & (RTASN1CURSOR_FLAGS_DER | RTASN1CURSOR_FLAGS_CER)))
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return VINF_SUCCESS;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (pCursor->fFlags & RTASN1CURSOR_FLAGS_CER)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync {
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (pAsn1Core->cb > 1000)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return VINF_SUCCESS;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_ILLEGAL_CONSTRUCTED_STRING,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "%s: Constructed %s only allowed for >1000 byte in CER encoding: cb=%#x uTag=%#x fClass=%#x",
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pszErrorTag, pszWhat, pAsn1Core->cb, pAsn1Core->uTag, pAsn1Core->fClass);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync }
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_ILLEGAL_CONSTRUCTED_STRING,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "%s: DER encoding does not allow constructed %s (cb=%#x uTag=%#x fClass=%#x)",
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pszErrorTag, pszWhat, pAsn1Core->cb, pAsn1Core->uTag, pAsn1Core->fClass);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync }
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync }
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (fFlags & RTASN1CURSOR_GET_F_IMPLICIT)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync {
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAsn1Core->fFlags |= RTASN1CORE_F_TAG_IMPLICIT;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAsn1Core->uRealTag = uTag;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAsn1Core->fRealClass = fClass;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return VINF_SUCCESS;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync }
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1CursorSetInfo(pCursor, pAsn1Core->uTag != uTag ? VERR_ASN1_CURSOR_TAG_MISMATCH : VERR_ASN1_CURSOR_TAG_FLAG_CLASS_MISMATCH,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "%s: Unexpected %s type/flags: %#x/%#x (expected %#x/%#x)",
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pszErrorTag, pszWhat, pAsn1Core->uTag, pAsn1Core->fClass, uTag, fClass);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncstatic int rtAsn1CursorGetXxxxCursor(PRTASN1CURSOR pCursor, uint32_t fFlags, uint32_t uTag, uint8_t fClass,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync PRTASN1CORE pAsn1Core, PRTASN1CURSOR pRetCursor,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync const char *pszErrorTag, const char *pszWhat)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync int rc = RTAsn1CursorReadHdr(pCursor, pAsn1Core, pszErrorTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (RT_SUCCESS(rc))
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync {
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if ( pAsn1Core->uTag == uTag
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync && pAsn1Core->fClass == fClass)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync rc = VINF_SUCCESS;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync else if (fFlags & RTASN1CURSOR_GET_F_IMPLICIT)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync {
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAsn1Core->fFlags |= RTASN1CORE_F_TAG_IMPLICIT;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAsn1Core->uRealTag = uTag;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pAsn1Core->fRealClass = fClass;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync rc = VINF_SUCCESS;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync }
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync else
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_ILLEGAL_CONSTRUCTED_STRING,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "%s: Unexpected %s type/flags: %#x/%#x (expected %#x/%#x)",
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pszErrorTag, pszWhat, pAsn1Core->uTag, pAsn1Core->fClass, uTag, fClass);
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync rc = RTAsn1CursorInitSub(pCursor, pAsn1Core->cb, pRetCursor, pszErrorTag);
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync if (RT_SUCCESS(rc))
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync {
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync pAsn1Core->fFlags |= RTASN1CORE_F_PRIMITE_TAG_STRUCT;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync return VINF_SUCCESS;
b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1vboxsync }
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync }
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return rc;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1CursorGetSequenceCursor(PRTASN1CURSOR pCursor, uint32_t fFlags,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync PRTASN1SEQUENCECORE pSeqCore, PRTASN1CURSOR pSeqCursor, const char *pszErrorTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return rtAsn1CursorGetXxxxCursor(pCursor, fFlags, ASN1_TAG_SEQUENCE, ASN1_TAGCLASS_UNIVERSAL | ASN1_TAGFLAG_CONSTRUCTED,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync &pSeqCore->Asn1Core, pSeqCursor, pszErrorTag, "sequence");
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1CursorGetSetCursor(PRTASN1CURSOR pCursor, uint32_t fFlags,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync PRTASN1SETCORE pSetCore, PRTASN1CURSOR pSetCursor, const char *pszErrorTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return rtAsn1CursorGetXxxxCursor(pCursor, fFlags, ASN1_TAG_SET, ASN1_TAGCLASS_UNIVERSAL | ASN1_TAGFLAG_CONSTRUCTED,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync &pSetCore->Asn1Core, pSetCursor, pszErrorTag, "set");
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1CursorGetContextTagNCursor(PRTASN1CURSOR pCursor, uint32_t fFlags, uint32_t uExpectedTag,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync PRTASN1CONTEXTTAG pCtxTag, PRTASN1CURSOR pCtxTagCursor, const char *pszErrorTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return rtAsn1CursorGetXxxxCursor(pCursor, fFlags, uExpectedTag, ASN1_TAGCLASS_CONTEXT | ASN1_TAGFLAG_CONSTRUCTED,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync &pCtxTag->Asn1Core, pCtxTagCursor, pszErrorTag, "ctx tag");
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1CursorPeek(PRTASN1CURSOR pCursor, PRTASN1CORE pAsn1Core)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync uint32_t cbSavedLeft = pCursor->cbLeft;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync uint8_t const *pbSavedCur = pCursor->pbCur;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync PRTERRINFO pErrInfo = pCursor->pPrimary->pErrInfo;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pCursor->pPrimary->pErrInfo = NULL;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync int rc = RTAsn1CursorReadHdr(pCursor, pAsn1Core, "peek");
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pCursor->pPrimary->pErrInfo = pErrInfo;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pCursor->pbCur = pbSavedCur;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pCursor->cbLeft = cbSavedLeft;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return rc;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(bool) RTAsn1CursorIsNextEx(PRTASN1CURSOR pCursor, uint32_t uTag, uint8_t fClass)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync RTASN1CORE Asn1Core;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync int rc = RTAsn1CursorPeek(pCursor, &Asn1Core);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (RT_SUCCESS(rc))
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return uTag == Asn1Core.uTag
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync && fClass == Asn1Core.fClass;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return false;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** @name Legacy Interfaces.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @{ */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1CursorGetCore(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1CORE pAsn1Core, const char *pszErrorTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1Core_DecodeAsn1(pCursor, fFlags, pAsn1Core, pszErrorTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1CursorGetNull(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1NULL pNull, const char *pszErrorTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1Null_DecodeAsn1(pCursor, fFlags, pNull, pszErrorTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1CursorGetInteger(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1INTEGER pInteger, const char *pszErrorTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1Integer_DecodeAsn1(pCursor, fFlags, pInteger, pszErrorTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1CursorGetBoolean(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1BOOLEAN pBoolean, const char *pszErrorTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1Boolean_DecodeAsn1(pCursor, fFlags, pBoolean, pszErrorTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1CursorGetObjId(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1OBJID pObjId, const char *pszErrorTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1ObjId_DecodeAsn1(pCursor, fFlags, pObjId, pszErrorTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1CursorGetTime(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1TIME pTime, const char *pszErrorTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1Time_DecodeAsn1(pCursor, fFlags, pTime, pszErrorTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1CursorGetBitStringEx(PRTASN1CURSOR pCursor, uint32_t fFlags, uint32_t cMaxBits, PRTASN1BITSTRING pBitString,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync const char *pszErrorTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1BitString_DecodeAsn1Ex(pCursor, fFlags, cMaxBits, pBitString, pszErrorTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1CursorGetBitString(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1BITSTRING pBitString, const char *pszErrorTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1BitString_DecodeAsn1(pCursor, fFlags, pBitString, pszErrorTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1CursorGetOctetString(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1OCTETSTRING pOctetString,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync const char *pszErrorTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1OctetString_DecodeAsn1(pCursor, fFlags, pOctetString, pszErrorTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1CursorGetString(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1STRING pString, const char *pszErrorTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1String_DecodeAsn1(pCursor, fFlags, pString, pszErrorTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1CursorGetIa5String(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1STRING pString, const char *pszErrorTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1Ia5String_DecodeAsn1(pCursor, fFlags, pString, pszErrorTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1CursorGetUtf8String(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1STRING pString, const char *pszErrorTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1Utf8String_DecodeAsn1(pCursor, fFlags, pString, pszErrorTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1CursorGetBmpString(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1STRING pString, const char *pszErrorTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1BmpString_DecodeAsn1(pCursor, fFlags, pString, pszErrorTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1CursorGetDynType(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1DYNTYPE pDynType, const char *pszErrorTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync{
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return RTAsn1DynType_DecodeAsn1(pCursor, fFlags, pDynType, pszErrorTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync}
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync/** @} */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync