VirtualBox

Changeset 23507 in vbox for trunk/include/iprt


Ignore:
Timestamp:
Oct 2, 2009 12:02:02 PM (15 years ago)
Author:
vboxsync
Message:

IPRT: Added APIs for convering digests to/from strings.

Location:
trunk/include/iprt
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/md5.h

    r22092 r23507  
    3939
    4040/** Size of a MD5 hash. */
    41 #define RTMD5HASHSIZE 16
     41#define RTMD5_HASH_SIZE     16
     42/** @deprecated Use RTMD5_HASH_SIZE. */
     43#define RTMD5HASHSIZE       RTMD5_HASH_SIZE
     44/** Size of a MD5 hash. */
     45#define RTMD5_STRING_LEN    32
    4246
    4347/**
     
    9195RTDECL(void) RTMd5Final(uint8_t pabDigest[RTMD5HASHSIZE], PRTMD5CONTEXT pCtx);
    9296
     97/**
     98 * Converts a MD5 hash to a digest string.
     99 *
     100 * @returns IPRT status code.
     101 *
     102 * @param   pabDigest   The binary digest returned by RTMd5Final or RTMd5.
     103 * @param   pszDigest   Where to return the stringified digest.
     104 * @param   cchDigest   The size of the output buffer. Should be at least
     105 *                      RTMD5_STRING_LEN + 1 bytes.
     106 */
     107RTDECL(int) RTMd5ToString(uint8_t const pabDigest[RTMD5_HASH_SIZE], char *pszDigest, size_t cchDigest);
     108
     109/**
     110 * Converts a MD5 hash to a digest string.
     111 *
     112 * @returns IPRT status code.
     113 *
     114 * @param   pszDigest   The strigified digest. Leading and trailing spaces are
     115 *                      ignored.
     116 * @param   pabDigest   Where to store the hash. (What is passed is a pointer to
     117 *                      the caller's buffer.)
     118 */
     119RTDECL(int) RTMd5FromString(char const *pszDigest, uint8_t pabDigest[RTMD5_HASH_SIZE]);
     120
     121
    93122RT_C_DECLS_END
    94123
  • trunk/include/iprt/sha.h

    r23501 r23507  
    4141
    4242/** The size of a SHA-1 hash. */
    43 #define RTSHA1_HASH_SIZE  20
     43#define RTSHA1_HASH_SIZE    20
     44/** The length of a SHA-1 digest string. The terminator is not included. */
     45#define RTSHA1_DIGEST_LEN  (40+1)
    4446
    4547/**
     
    9193RTDECL(void) RTSha1Final(PRTSHA1CONTEXT pCtx, uint8_t pabDigest[RTSHA1_HASH_SIZE]);
    9294
     95/**
     96 * Converts a SHA-512 hash to a digest string.
     97 *
     98 * @returns IPRT status code.
     99 *
     100 * @param   pabDigest   The binary digest returned by RTSha1Final or RTSha1.
     101 * @param   pszDigest   Where to return the stringified digest.
     102 * @param   cchDigest   The size of the output buffer. Should be at least
     103 *                      RTSHA1_STRING_LEN + 1 bytes.
     104 */
     105RTDECL(int) RTSha1ToString(uint8_t const pabDigest[RTSHA1_HASH_SIZE], char *pszDigest, size_t cchDigest);
     106
     107/**
     108 * Converts a SHA-1 hash to a digest string.
     109 *
     110 * @returns IPRT status code.
     111 *
     112 * @param   pszDigest   The strigified digest. Leading and trailing spaces are
     113 *                      ignored.
     114 * @param   pabDigest   Where to store the hash. (What is passed is a pointer to
     115 *                      the caller's buffer.)
     116 */
     117RTDECL(int) RTSha1FromString(char const *pszDigest, uint8_t pabDigest[RTSHA1_HASH_SIZE]);
    93118
    94119/**
     
    103128
    104129
     130
    105131/** The size of a SHA-256 hash. */
    106 #define RTSHA256_HASH_SIZE  32
     132#define RTSHA256_HASH_SIZE      32
     133/** The length of a SHA-256 digest string. The terminator is not included. */
     134#define RTSHA256_DIGEST_LEN     64
    107135
    108136/**
     
    154182RTDECL(void) RTSha256Final(PRTSHA256CONTEXT pCtx, uint8_t pabDigest[RTSHA256_HASH_SIZE]);
    155183
     184/**
     185 * Converts a SHA-256 hash to a digest string.
     186 *
     187 * @returns IPRT status code.
     188 *
     189 * @param   pabDigest   The binary digest returned by RTSha256Final or RTSha256.
     190 * @param   pszDigest   Where to return the stringified digest.
     191 * @param   cchDigest   The size of the output buffer. Should be at least
     192 *                      RTSHA256_STRING_LEN + 1 bytes.
     193 */
     194RTDECL(int) RTSha256ToString(uint8_t const pabDigest[RTSHA256_HASH_SIZE], char *pszDigest, size_t cchDigest);
     195
     196/**
     197 * Converts a SHA-256 hash to a digest string.
     198 *
     199 * @returns IPRT status code.
     200 *
     201 * @param   pszDigest   The strigified digest. Leading and trailing spaces are
     202 *                      ignored.
     203 * @param   pabDigest   Where to store the hash. (What is passed is a pointer to
     204 *                      the caller's buffer.)
     205 */
     206RTDECL(int) RTSha256FromString(char const *pszDigest, uint8_t pabDigest[RTSHA256_HASH_SIZE]);
     207
     208
    156209
    157210/** The size of a SHA-512 hash. */
    158 #define RTSHA512_HASH_SIZE  64
     211#define RTSHA512_HASH_SIZE      64
     212/** The length of a SHA-512 digest string. The terminator is not included. */
     213#define RTSHA512_STRING_LEN     128
    159214
    160215/**
     
    206261RTDECL(void) RTSha512Final(PRTSHA512CONTEXT pCtx, uint8_t pabDigest[RTSHA512_HASH_SIZE]);
    207262
     263/**
     264 * Converts a SHA-512 hash to a digest string.
     265 *
     266 * @returns IPRT status code.
     267 *
     268 * @param   pabDigest   The binary digest returned by RTSha512Final or RTSha512.
     269 * @param   pszDigest   Where to return the stringified digest.
     270 * @param   cchDigest   The size of the output buffer. Should be at least
     271 *                      RTSHA512_STRING_LEN + 1 bytes.
     272 */
     273RTDECL(int) RTSha512ToString(uint8_t const pabDigest[RTSHA512_HASH_SIZE], char *pszDigest, size_t cchDigest);
     274
     275/**
     276 * Converts a SHA-512 hash to a digest string.
     277 *
     278 * @returns IPRT status code.
     279 *
     280 * @param   pszDigest   The strigified digest. Leading and trailing spaces are
     281 *                      ignored.
     282 * @param   pabDigest   Where to store the hash. (What is passed is a pointer to
     283 *                      the caller's buffer.)
     284 */
     285RTDECL(int) RTSha512FromString(char const *pszDigest, uint8_t pabDigest[RTSHA512_HASH_SIZE]);
     286
    208287/** @} */
    209288
  • trunk/include/iprt/string.h

    r22736 r23507  
    14321432RTDECL(int8_t) RTStrToInt8(const char *pszValue);
    14331433
     1434/**
     1435 * Formats a buffer stream as hex bytes.
     1436 *
     1437 * The default is no separating spaces or line breaks or anything.
     1438 *
     1439 * @returns IPRT status code.
     1440 * @retval  VERR_INVALID_POINTER if any of the pointers are wrong.
     1441 * @retval  VERR_BUFFER_OVERFLOW if the buffer is insufficent to hold the bytes.
     1442 *
     1443 * @param   pszBuf      Output string buffer.
     1444 * @param   cchBuf      The size of the output buffer.
     1445 * @param   pv          Pointer to the bytes to stringify.
     1446 * @param   cb          The number of bytes to stringify.
     1447 * @param   fFlags      Must be zero, reserved for future use.
     1448 */
     1449RTDECL(int) RTStrPrintHexBytes(char *pszBuf, size_t cchBuf, void const *pv, size_t cb, uint32_t fFlags);
     1450
     1451/**
     1452 * Converts a string of hex bytes back into binary data.
     1453 *
     1454 * @returns IPRT status code.
     1455 * @retval  VERR_INVALID_POINTER if any of the pointers are wrong.
     1456 * @retval  VERR_BUFFER_OVERFLOW if the string contains too many hex bytes.
     1457 * @retval  VERR_BUFFER_UNDERFLOW if there aren't enough hex bytes to fill up
     1458 *          the output buffer.
     1459 * @retval  VERR_UNEVEN_INPUT if the input contains a half byte.
     1460 * @retval  VERR_NO_DIGITS
     1461 * @retval  VWRN_TRAILING_CHARS
     1462 * @retval  VWRN_TRAILING_SPACES
     1463 *
     1464 * @param   pszHex      The string containing the hex bytes.
     1465 * @param   pv          Output buffer.
     1466 * @param   cb          The size of the output buffer.
     1467 * @param   fFlags      Must be zero, reserved for future use.
     1468 */
     1469RTDECL(int) RTStrConvertHexBytes(char const *pszHex, void *pv, size_t cb, uint32_t fFlags);
     1470
    14341471/** @} */
    14351472
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