VirtualBox

Ignore:
Timestamp:
Mar 15, 2016 10:39:16 AM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
106008
Message:

iprt: Added simple (and untested) RTAsn1Integer_ToString implemented. Added spacing flags to RTStrPrintHexBytes (also untested).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/asn1/asn1-ut-integer.cpp

    r57358 r60028  
    55
    66/*
    7  * Copyright (C) 2006-2015 Oracle Corporation
     7 * Copyright (C) 2006-2016 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    338338
    339339
     340RTDECL(int) RTAsn1Integer_ToString(PRTASN1INTEGER pThis, char *pszBuf, size_t cbBuf, uint32_t fFlags, size_t *pcbActual)
     341{
     342    AssertReturn(RTAsn1Integer_IsPresent(pThis), VERR_INVALID_PARAMETER);
     343    AssertReturn(fFlags == 0, VERR_INVALID_FLAGS);
     344
     345    /*
     346     * We only do hex conversions via this API.
     347     * Currently we consider all numbers to be unsigned.
     348     */
     349    /** @todo Signed ASN.1 INTEGER. */
     350    int rc;
     351    size_t cbActual;
     352    if (pThis->Asn1Core.cb <= 8)
     353    {
     354        cbActual = 2 + pThis->Asn1Core.cb*2 + 1;
     355        if (cbActual <= cbBuf)
     356        {
     357            ssize_t cchFormat = RTStrFormatU64(pszBuf, cbBuf, pThis->uValue.u, 16, cbActual - 1 /*cchWidth*/, 0,
     358                                               RTSTR_F_SPECIAL | RTSTR_F_ZEROPAD);
     359            AssertStmt(cchFormat == (ssize_t)cbActual - 1, rc = VERR_INTERNAL_ERROR_3);
     360        }
     361        else
     362            rc = VERR_BUFFER_OVERFLOW;
     363    }
     364    else
     365    {
     366        cbActual = pThis->Asn1Core.cb * 3 - 1 /* save one separator */ + 1 /* terminator */;
     367        if (cbActual <= cbBuf)
     368        {
     369            rc = RTStrPrintHexBytes(pszBuf, cbBuf, pThis->Asn1Core.uData.pv, pThis->Asn1Core.cb, RTSTRPRINTHEXBYTES_F_SEP_SPACE);
     370            Assert(rc == VINF_SUCCESS);
     371        }
     372        else
     373            rc = VERR_BUFFER_OVERFLOW;
     374    }
     375    if (pcbActual)
     376        *pcbActual = cbActual;
     377    return rc;
     378}
     379
    340380
    341381/*
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette