RTDECL(int) RTAsn1Boolean_InitDefault(PRTASN1BOOLEAN pThis, bool fValue, PCRTASN1ALLOCATORVTABLE pAllocator)
{
    RTAsn1Core_InitEx(&pThis->Asn1Core, ASN1_TAG_BOOLEAN, ASN1_TAGCLASS_UNIVERSAL | ASN1_TAGFLAG_PRIMITIVE,
                      &g_RTAsn1Boolean_Vtable, RTASN1CORE_F_DEFAULT | RTASN1CORE_F_PRIMITE_TAG_STRUCT);
    pThis->fValue = fValue;
    pThis->Asn1Core.uData.pv = (void *)(fValue ? &g_bTrue : &g_bFalse);
    return VINF_SUCCESS;
}
RTDECL(int) RTAsn1Boolean_Init(PRTASN1BOOLEAN pThis, PCRTASN1ALLOCATORVTABLE pAllocator)
{
    RTAsn1Core_InitEx(&pThis->Asn1Core, ASN1_TAG_BOOLEAN, ASN1_TAGCLASS_UNIVERSAL | ASN1_TAGFLAG_PRIMITIVE,
                      &g_RTAsn1Boolean_Vtable, RTASN1CORE_F_PRESENT | RTASN1CORE_F_PRIMITE_TAG_STRUCT);
    pThis->fValue = true;
    pThis->Asn1Core.cb = 1;
    pThis->Asn1Core.uData.pv = (void *)&g_bTrue;
    return VINF_SUCCESS;
}
예제 #3
0
RTDECL(int) RTAsn1Integer_Init(PRTASN1INTEGER pThis, PCRTASN1ALLOCATORVTABLE pAllocator)
{
    RTAsn1Core_InitEx(&pThis->Asn1Core,
                      ASN1_TAG_INTEGER,
                      ASN1_TAGCLASS_UNIVERSAL | ASN1_TAGFLAG_PRIMITIVE,
                      &g_RTAsn1Integer_Vtable,
                      RTASN1CORE_F_PRESENT | RTASN1CORE_F_PRIMITE_TAG_STRUCT);
    pThis->uValue.u = 1;
    pThis->Asn1Core.cb = 1;
    pThis->Asn1Core.uData.pv = (void *)&g_abSmall[0];
    return VINF_SUCCESS;
}
RTDECL(int) RTAsn1Time_InitEx(PRTASN1TIME pThis, uint32_t uTag, PCRTASN1ALLOCATORVTABLE pAllocator)
{
    AssertReturn(uTag == ASN1_TAG_UTC_TIME || uTag == ASN1_TAG_GENERALIZED_TIME, VERR_INVALID_PARAMETER);
    RTAsn1Core_InitEx(&pThis->Asn1Core,
                      uTag,
                      ASN1_TAGCLASS_UNIVERSAL | ASN1_TAGFLAG_PRIMITIVE,
                      &g_RTAsn1Time_Vtable,
                      RTASN1CORE_F_PRESENT | RTASN1CORE_F_PRIMITE_TAG_STRUCT);
    if (uTag == ASN1_TAG_UTC_TIME)
    {
        pThis->Asn1Core.cb = sizeof(g_szEpochUtc) - 1;
        pThis->Asn1Core.uData.pv = &g_szEpochUtc[0];
    }
    else
    {
        pThis->Asn1Core.cb = sizeof(g_szEpochGeneralized) - 1;
        pThis->Asn1Core.uData.pv = &g_szEpochGeneralized[0];
    }
    return VINF_SUCCESS;
}
예제 #5
0
RTDECL(int) RTAsn1Integer_InitU64(PRTASN1INTEGER pThis, uint64_t uValue, PCRTASN1ALLOCATORVTABLE pAllocator)
{
    /*
     * Initialize the core and the native value.
     */
    RTAsn1Core_InitEx(&pThis->Asn1Core,
                      ASN1_TAG_INTEGER,
                      ASN1_TAGCLASS_UNIVERSAL | ASN1_TAGFLAG_PRIMITIVE,
                      &g_RTAsn1Integer_Vtable,
                      RTASN1CORE_F_PRESENT | RTASN1CORE_F_PRIMITE_TAG_STRUCT);
    pThis->uValue.u = uValue;

    /*
     * Use one of the constants if possible.
     */
    if (uValue < RT_ELEMENTS(g_abSmall))
    {
        pThis->Asn1Core.cb = 1;
        pThis->Asn1Core.uData.pv = (void *)&g_abSmall[0];
    }
    else
    {
        /*
         * Need to turn uValue into a big endian number without any
         * unnecessary leading zero bytes.
         */
        /* Figure the size. */
        uint32_t cb = 0;
        if (uValue <= UINT32_MAX)
        {
            if (uValue <= UINT16_MAX)
            {
                if (uValue <= UINT8_MAX)
                    cb = 1;
                else
                    cb = 2;
            }
            else
            {
                if (uValue <= UINT32_C(0xffffff))
                    cb = 3;
                else
                    cb = 4;
            }
        }
        else
        {
            if (uValue <= UINT64_C(0x0000FfffFfffFfff))
            {
                if (uValue <= UINT64_C(0x000000ffFfffFfff))
                    cb = 5;
                else
                    cb = 6;
            }
            else
            {
                if (uValue <= UINT64_C(0x00ffFfffFfffFfff))
                    cb = 7;
                else
                    cb = 8;
            }
        }

        /* Allocate space. */
        int rc = RTAsn1ContentAllocZ(&pThis->Asn1Core, cb, pAllocator);
        if (RT_FAILURE(rc))
        {
            RT_ZERO(*pThis);
            return rc;
        }

        /* Serialize the number in MSB order. */
        uint8_t *pb = (uint8_t *)pThis->Asn1Core.uData.pu8;
        while (cb-- > 0)
        {
            pb[cb] = (uint8_t)uValue;
            uValue >>= 8;
        }
        Assert(uValue == 0);
    }
    return VINF_SUCCESS;
}
예제 #6
0
RTDECL(int) RTAsn1Core_InitDefault(PRTASN1CORE pAsn1Core, uint32_t uTag, uint8_t fClass)
{
    return RTAsn1Core_InitEx(pAsn1Core, uTag, fClass, NULL, RTASN1CORE_F_DEFAULT);
}
예제 #7
0
RTDECL(int) RTAsn1Core_Init(PRTASN1CORE pThis, PCRTASN1ALLOCATORVTABLE pAllocator)
{
    return RTAsn1Core_InitEx(pThis, 0, ASN1_TAGCLASS_CONTEXT | ASN1_TAGFLAG_PRIMITIVE,
                             &g_RTAsn1Core_Vtable, RTASN1CORE_F_PRESENT);
}