asn1-ut-integer.cpp revision 13493ab7596e827b8d0caab2c89e635dd65f78f9
/* $Id$ */
/** @file
* IPRT - ASN.1, INTEGER Type.
*/
/*
* 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 *
*******************************************************************************/
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** Fixed on-byte constants for small numbers.
* Good for structure version values and such. */
{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
};
/*
* ASN.1 INTEGER - Special Methods.
*/
/**
* Updates the native value we keep in RTASN1INTEGER::uValue.
*
* @param pThis The integer.
*/
{
{
default:
}
}
RTDECL(int) RTAsn1Integer_InitU64(PRTASN1INTEGER pThis, uint64_t uValue, PCRTASN1ALLOCATORVTABLE pAllocator)
{
/*
* Initialize the core and the native value.
*/
/*
* Use one of the constants if possible.
*/
{
}
else
{
/*
* Need to turn uValue into a big endian number without any
* unnecessary leading zero bytes.
*/
/* Figure the size. */
if (uValue <= UINT32_MAX)
{
if (uValue <= UINT16_MAX)
{
cb = 1;
else
cb = 2;
}
else
{
cb = 3;
else
cb = 4;
}
}
else
{
{
cb = 5;
else
cb = 6;
}
else
{
cb = 7;
else
cb = 8;
}
}
/* Allocate space. */
if (RT_FAILURE(rc))
{
return rc;
}
/* Serialize the number in MSB order. */
while (cb-- > 0)
{
uValue >>= 8;
}
}
return VINF_SUCCESS;
}
RTDECL(int) RTAsn1Integer_InitDefault(PRTASN1INTEGER pThis, uint64_t uValue, PCRTASN1ALLOCATORVTABLE pAllocator)
{
if (RT_SUCCESS(rc))
{
}
return rc;
}
{
while (cb-- > 0)
{
if (b)
{
else Assert(b == 0x01);
return iRet;
}
}
return -1;
}
{
Assert(pLeft && (!RTAsn1Integer_IsPresent(pLeft) || pLeft->Asn1Core.pOps == &g_RTAsn1Integer_Vtable));
Assert(pRight && (!RTAsn1Integer_IsPresent(pRight) || pRight->Asn1Core.pOps == &g_RTAsn1Integer_Vtable));
int iDiff;
if (RTAsn1Integer_IsPresent(pLeft))
{
{
{
if (i > 8)
{
for (;;)
{
if (--i <= 8)
break;
pbLeft++;
pbRight++;
}
}
}
iDiff = 0;
else
}
else
iDiff = -1;
}
else
return iDiff;
}
{
int iDiff;
if (RTAsn1Integer_IsPresent(pThis))
{
{
if (iLast >= 64)
return 1;
}
iDiff = 0;
else
}
else
iDiff = 1;
return iDiff;
}
{
int iDiff;
if (RTAsn1Integer_IsPresent(pThis))
{
{
if (iLast >= 32)
return 1;
}
iDiff = 0;
else
}
else
iDiff = 1;
return iDiff;
}
{
AssertReturn(!(fBigNumInit & ~( RTBIGNUMINIT_F_SENSITIVE | RTBIGNUMINIT_F_UNSIGNED | RTBIGNUMINIT_F_SIGNED
}
RTDECL(int) RTAsn1Integer_FromBigNum(PRTASN1INTEGER pThis, PCRTBIGNUM pBigNum, PCRTASN1ALLOCATORVTABLE pAllocator)
{
/* Be nice and auto init the object. */
if (!RTAsn1Integer_IsPresent(pThis))
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
}
return rc;
}
/*
* ASN.1 INTEGER - Standard Methods.
*/
{
"RTAsn1Integer",
sizeof(RTASN1INTEGER),
0,
NULL,
NULL,
};
{
return VINF_SUCCESS;
}
RTDECL(int) RTAsn1Integer_Clone(PRTASN1INTEGER pThis, PCRTASN1INTEGER pSrc, PCRTASN1ALLOCATORVTABLE pAllocator)
{
if (RTAsn1Integer_IsPresent(pSrc))
{
int rc;
{
/* Value is too large, copy it. */
if (RT_FAILURE(rc))
return rc;
}
else
{
/* Use one of the const values. */
if (RT_FAILURE(rc))
return rc;
}
}
return VINF_SUCCESS;
}
{
if ( pThis
{
}
}
RTDECL(int) RTAsn1Integer_Enum(PRTASN1INTEGER pThis, PFNRTASN1ENUMCALLBACK pfnCallback, uint32_t uDepth, void *pvUser)
{
Assert(pThis && (!RTAsn1Integer_IsPresent(pThis) || pThis->Asn1Core.pOps == &g_RTAsn1Integer_Vtable));
/* No children to enumerate. */
return VINF_SUCCESS;
}
{
}
RTDECL(int) RTAsn1Integer_CheckSanity(PCRTASN1INTEGER pThis, uint32_t fFlags, PRTERRINFO pErrInfo, const char *pszErrorTag)
{
return VINF_SUCCESS;
}
/*
* Generate code for the associated collection types.
*/
#define RTASN1TMPL_TEMPLATE_FILE "../common/asn1/asn1-ut-integer-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>