asn1-ut-string-decode.cpp revision 375c27aef516595a50459787463506d474668e8c
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * IPRT - ASN.1, XXX STRING Types, Decoding.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Copyright (C) 2006-2014 Oracle Corporation
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 * 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 * 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* Header Files *
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync*******************************************************************************/
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncRTDECL(int) RTAsn1String_DecodeAsn1(PRTASN1CURSOR pCursor, uint32_t fFlags, PRTASN1STRING pThis, const char *pszErrorTag)
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync AssertReturn(!(fFlags & RTASN1CURSOR_GET_F_IMPLICIT), VERR_INVALID_PARAMETER);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync int rc = RTAsn1CursorReadHdr(pCursor, &pThis->Asn1Core, pszErrorTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Do tag matching.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync rc = RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_TAG_MISMATCH,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "%s: Not a string object: fClass=%#x / uTag=%#x",
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pszErrorTag, pThis->Asn1Core.fClass, pThis->Asn1Core.uTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Match flags. CER/DER makes it complicated.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (pThis->Asn1Core.fClass == (ASN1_TAGCLASS_UNIVERSAL | ASN1_TAGFLAG_PRIMITIVE))
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Primitive strings are simple.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pThis->Asn1Core.fFlags |= RTASN1CORE_F_PRIMITE_TAG_STRUCT;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync RTAsn1CursorInitAllocation(pCursor, &pThis->Allocation);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* UTF-8 conversion is done lazily, upon request. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (pThis->Asn1Core.fClass == (ASN1_TAGCLASS_UNIVERSAL | ASN1_TAGFLAG_CONSTRUCTED))
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Constructed strings are not yet fully implemented.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync rc = RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_ILLEGAL_CONSTRUCTED_STRING,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "%s: DER encoding does not allow constructed strings (cb=%#x uTag=%#x fClass=%#x)",
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pszErrorTag, pThis->Asn1Core.cb, pThis->Asn1Core.uTag, pThis->Asn1Core.fClass);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync rc = RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_ILLEGAL_CONSTRUCTED_STRING,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "%s: Constructed strings only allowed for >1000 byte in CER encoding: cb=%#x uTag=%#x fClass=%#x",
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /** @todo implement constructed strings. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync rc = RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CONSTRUCTED_STRING_NOT_IMPL,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "%s: Support for constructed strings is not implemented", pszErrorTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync rc = RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CURSOR_TAG_FLAG_CLASS_MISMATCH,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "%s: Not a valid string object: fClass=%#x / uTag=%#x",
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pszErrorTag, pThis->Asn1Core.fClass, pThis->Asn1Core.uTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Common worker for the specific string type getters.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @returns IPRT status code
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param pCursor The cursor.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param fFlags The RTASN1CURSOR_GET_F_XXX flags.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param uTag The string tag.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param pThis The output object.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param pszErrorTag The error tag.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * @param pszWhat The string type name.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsyncstatic int rtAsn1XxxString_DecodeAsn1(PRTASN1CURSOR pCursor, uint32_t fFlags, uint8_t uTag, PRTASN1STRING pThis,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync int rc = RTAsn1CursorReadHdr(pCursor, &pThis->Asn1Core, pszErrorTag);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync rc = RTAsn1CursorMatchTagClassFlagsString(pCursor, &pThis->Asn1Core, uTag,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync if (!(pThis->Asn1Core.fClass & ASN1_TAGFLAG_CONSTRUCTED))
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync pThis->Asn1Core.fFlags |= RTASN1CORE_F_PRIMITE_TAG_STRUCT;
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync RTAsn1CursorInitAllocation(pCursor, &pThis->Allocation);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync /* UTF-8 conversion is done lazily, upon request. */
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync rc = RTAsn1CursorSetInfo(pCursor, VERR_ASN1_CONSTRUCTED_STRING_NOT_IMPL,
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync "%s: Constructed %s not implemented.", pszErrorTag, pszWhat);
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Generate code for the tag specific decoders.
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync RTDECL(int) RT_CONCAT(a_Api,_DecodeAsn1)(PRTASN1CURSOR pCursor, uint32_t fFlags, \
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync return rtAsn1XxxString_DecodeAsn1(pCursor, fFlags, a_uTag, pThis, pszErrorTag, a_szTag); \
13493ab7596e827b8d0caab2c89e635dd65f78f9vboxsync * Generate code for the associated collection types.