asn1-ut-octetstring.cpp revision a118ea84f7f14ee4c253a7f584f0b592caf74c4f
/* $Id$ */
/** @file
* IPRT - ASN.1, Octet String.
*
* @remarks This file should remain very similar to asn1-ut-bitstring.cpp.
*/
/*
* 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 *
*******************************************************************************/
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
typedef struct RTASN1OCTETSTRINGWRITERCTX
{
/** Pointer to the output buffer. */
/** The current buffer offset. */
/** The size of the buffer. */
/** @callback_method_impl{FNRTASN1ENCODEWRITER,
* Used to refresh the content of octet and bit strings. } */
static DECLCALLBACK(int) rtAsn1OctetStringEncodeWriter(const void *pvBuf, size_t cbToWrite, void *pvUser, PRTERRINFO pErrInfo)
{
return VINF_SUCCESS;
}
/** @callback_method_impl{FNRTASN1ENCODEWRITER,
* Used to compare the encoded raw content of an octet or bit string with the
* encapsulated object. } */
static DECLCALLBACK(int) rtAsn1OctetStringEncodeCompare(const void *pvBuf, size_t cbToWrite, void *pvUser, PRTERRINFO pErrInfo)
{
return VERR_NOT_EQUAL;
return VINF_SUCCESS;
}
/*
* ASN.1 OCTET STRING - Specific Methods
*/
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
/* Initialize the writer context. */
rc = RTAsn1EncodeWrite(pThis->pEncapsulated, fFlags, rtAsn1OctetStringEncodeWriter, &Ctx, pErrInfo);
if (RT_SUCCESS(rc))
{
return VINF_SUCCESS;
}
}
else
}
return rc;
}
{
if (pThis->pEncapsulated)
{
/* Check the encoded length of the octets. */
if (RT_FAILURE(rc))
return false;
return false;
/* Check the encoded bytes, if there are any. */
if (cbEncoded)
{
return false;
/* Check the other bytes. */
if (RT_FAILURE(rc))
return false;
}
}
return true;
}
/*
* ASN.1 OCTET STRING - Standard Methods.
*/
/** @interface_method_impl{FNRTASN1COREVTENCODEPREP} */
static DECLCALLBACK(int) RTAsn1OctetString_EncodePrep(PRTASN1CORE pThisCore, uint32_t fFlags, PRTERRINFO pErrInfo)
{
if (!pThis->pEncapsulated)
{
return VINF_SUCCESS;
}
/* Figure out the size of the encapsulated content. */
if (RT_SUCCESS(rc))
{
/* Free the bytes if they don't match up. */
{
if (!fMustFree)
{
}
if (fMustFree)
}
}
return rc;
}
/** @interface_method_impl{FNRTASN1COREVTENCODEWRITE} */
static DECLCALLBACK(int) RTAsn1OctetString_EncodeWrite(PRTASN1CORE pThisCore, uint32_t fFlags, PFNRTASN1ENCODEWRITER pfnWriter,
{
/*
* First the header.
*/
{
/*
* If nothing is encapsulated, the core points to the content (if we have any).
*/
if (!pThis->pEncapsulated)
{
}
/*
* Call upon the encapsulated content to serialize itself.
*/
else
}
return rc;
}
{
"OctetString",
sizeof(RTASN1OCTETSTRING),
0,
};
{
RTAsn1Core_InitEx(&pThis->Asn1Core, ASN1_TAG_OCTET_STRING, ASN1_TAGCLASS_UNIVERSAL | ASN1_TAGFLAG_PRIMITIVE,
/*pThis->pEncapsulated = NULL;*/
return VINF_SUCCESS;
}
RTDECL(int) RTAsn1OctetString_Clone(PRTASN1OCTETSTRING pThis, PCRTASN1OCTETSTRING pSrc, PCRTASN1ALLOCATORVTABLE pAllocator)
{
{
int rc;
if (!pSrc->pEncapsulated)
else
if (RT_FAILURE(rc))
return rc;
if (pSrc->pEncapsulated)
{
{
/* We can clone the decoded encapsulated object. */
rc = RTAsn1MemAllocZ(&pThis->EncapsulatedAllocation, (void **)&pThis->pEncapsulated, pOps->cbStruct);
if (RT_SUCCESS(rc))
{
if (RT_FAILURE(rc))
}
}
else
{
/* Borrow the encapsulated pointer and use RTAsn1OctetString_RefreshContent
to get an accurate copy of the bytes. */
}
if (RT_FAILURE(rc))
{
return rc;
}
}
}
return VINF_SUCCESS;
}
{
if ( pThis
{
/* Destroy the encapsulated object. */
if (pThis->pEncapsulated)
{
}
/* Delete content and wipe the content. */
}
}
RTDECL(int) RTAsn1OctetString_Enum(PRTASN1OCTETSTRING pThis, PFNRTASN1ENUMCALLBACK pfnCallback, uint32_t uDepth, void *pvUser)
{
Assert(pThis && (!RTAsn1OctetString_IsPresent(pThis) || pThis->Asn1Core.pOps == &g_RTAsn1OctetString_Vtable));
/* Enumerate the encapsulated object if present. */
if (pThis->pEncapsulated)
return VINF_SUCCESS;
}
{
Assert(pLeft && (!RTAsn1OctetString_IsPresent(pLeft) || pLeft->Asn1Core.pOps == &g_RTAsn1OctetString_Vtable));
Assert(pRight && (!RTAsn1OctetString_IsPresent(pRight) || pRight->Asn1Core.pOps == &g_RTAsn1OctetString_Vtable));
int iDiff;
{
{
/* Since it's really hard to tell whether encapsulated objects have
been modified or not, we might have to refresh both objects
while doing this compare. We'll try our best to avoid it though. */
{
if ( pLeft->pEncapsulated
&& pRight->pEncapsulated
else
{
/* No direct comparison of encapsulated objects possible,
make sure we've got the rigth bytes then. */
if ( pLeft->pEncapsulated
{
}
if ( pRight->pEncapsulated
{
}
/* Compare the content bytes. */
}
}
/*
* No encapsulated object, just compare the raw content bytes.
*/
else
}
else
iDiff = -1;
}
else
return iDiff;
}
RTDECL(int) RTAsn1OctetString_CheckSanity(PCRTASN1OCTETSTRING pThis, uint32_t fFlags, PRTERRINFO pErrInfo, const char *pszErrorTag)
{
if (pThis->pEncapsulated)
return pThis->pEncapsulated->pOps->pfnCheckSanity(pThis->pEncapsulated, fFlags & RTASN1_CHECK_SANITY_F_COMMON_MASK,
return VINF_SUCCESS;
}
/*
* Generate code for the associated collection types.
*/
#define RTASN1TMPL_TEMPLATE_FILE "../common/asn1/asn1-ut-octetstring-template.h"
#include <iprt/asn1-generator-internal-header.h>
#include <iprt/asn1-generator-core.h>
#include <iprt/asn1-generator-init.h>
#include <iprt/asn1-generator-sanity.h>