spc-asn1-decoder.cpp revision b1f3a2dc94cfa582803b349a7ce9c7b2f94e58f1
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync/* $Id$ */
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync/** @file
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * IPRT - Crypto - Microsoft SPC / Authenticode, Decoder for ASN.1.
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync */
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync/*
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2006-2014 Oracle Corporation
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync *
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * available from http://www.virtualbox.org. This file is free software;
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * you can redistribute it and/or modify it under the terms of the GNU
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * General Public License (GPL) as published by the Free Software
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync *
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * The contents of this file may alternatively be used under the terms
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * of the Common Development and Distribution License Version 1.0
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * VirtualBox OSE distribution, in which case the provisions of the
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * CDDL are applicable instead of those of the GPL.
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync *
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * You may elect to license modified versions of this file under the
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * terms and conditions of either the GPL or the CDDL or both.
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync */
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync/*******************************************************************************
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync* Header Files *
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync*******************************************************************************/
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync#include "internal/iprt.h"
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync#include <iprt/crypto/spc.h>
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync#include <iprt/err.h>
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync#include <iprt/string.h>
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync#include <iprt/uuid.h>
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync#include "spc-internal.h"
4bd3e7685494afe7c303fc131c66e685023b6b4avboxsync
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync/*
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync * One SPC Serialized Object Attribute.
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync */
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync/** Decode the content of the octet string value if known. */
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsyncstatic int rtCrSpcSerializedObject_DecodeMore(PRTASN1CURSOR pCursor, uint32_t fFlags,
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync PRTCRSPCSERIALIZEDOBJECT pThis, const char *pszErrorTag)
4bd3e7685494afe7c303fc131c66e685023b6b4avboxsync
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync{
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync int rc;
4bd3e7685494afe7c303fc131c66e685023b6b4avboxsync RTASN1CURSOR SubCursor;
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync if (RTUuidCompareStr(pThis->Uuid.Asn1Core.uData.pUuid, RTCRSPCSERIALIZEDOBJECT_UUID_STR) == 0)
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync {
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync rc = RTAsn1MemAllocZ(&pThis->SerializedData.EncapsulatedAllocation, (void **)&pThis->u.pData, sizeof(*pThis->u.pData));
4bd3e7685494afe7c303fc131c66e685023b6b4avboxsync if (RT_SUCCESS(rc))
4bd3e7685494afe7c303fc131c66e685023b6b4avboxsync {
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync pThis->SerializedData.pEncapsulated = (PRTASN1CORE)pThis->u.pData;
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync pThis->enmType = RTCRSPCSERIALIZEDOBJECTTYPE_ATTRIBUTES;
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync rc = RTAsn1CursorInitSubFromCore(pCursor, &pThis->SerializedData.Asn1Core, &SubCursor, "SerializedData");
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync if (RT_SUCCESS(rc))
4bd3e7685494afe7c303fc131c66e685023b6b4avboxsync rc = RTCrSpcSerializedObjectAttributes_DecodeAsn1(&SubCursor, 0, pThis->u.pData, "SD");
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync }
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync }
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync else
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync return VINF_SUCCESS;
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync if (RT_SUCCESS(rc))
cb6fa623dea342f8cdb056585d3237e0bffd970avboxsync rc = RTAsn1CursorCheckEnd(&SubCursor);
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync return rc;
4bd3e7685494afe7c303fc131c66e685023b6b4avboxsync}
4bd3e7685494afe7c303fc131c66e685023b6b4avboxsync
4bd3e7685494afe7c303fc131c66e685023b6b4avboxsync/*
cb6fa623dea342f8cdb056585d3237e0bffd970avboxsync * Generate the code.
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync */
4bd3e7685494afe7c303fc131c66e685023b6b4avboxsync#include <iprt/asn1-generator-asn1-decoder.h>
cb6fa623dea342f8cdb056585d3237e0bffd970avboxsync
354c88062085b9c03e4ea164f29c461b2ea842d6vboxsync