Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /**
  2.  * \file base64.h
  3.  *
  4.  * \brief RFC 1521 base64 encoding/decoding
  5.  */
  6. /*
  7.  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  8.  *  SPDX-License-Identifier: GPL-2.0
  9.  *
  10.  *  This program is free software; you can redistribute it and/or modify
  11.  *  it under the terms of the GNU General Public License as published by
  12.  *  the Free Software Foundation; either version 2 of the License, or
  13.  *  (at your option) any later version.
  14.  *
  15.  *  This program is distributed in the hope that it will be useful,
  16.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  *  GNU General Public License for more details.
  19.  *
  20.  *  You should have received a copy of the GNU General Public License along
  21.  *  with this program; if not, write to the Free Software Foundation, Inc.,
  22.  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  23.  *
  24.  *  This file is part of mbed TLS (https://tls.mbed.org)
  25.  */
  26. #ifndef MBEDTLS_BASE64_H
  27. #define MBEDTLS_BASE64_H
  28.  
  29. #if !defined(MBEDTLS_CONFIG_FILE)
  30. #include "config.h"
  31. #else
  32. #include MBEDTLS_CONFIG_FILE
  33. #endif
  34.  
  35. #include <stddef.h>
  36.  
  37. #define MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL               -0x002A  /**< Output buffer too small. */
  38. #define MBEDTLS_ERR_BASE64_INVALID_CHARACTER              -0x002C  /**< Invalid character in input. */
  39.  
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43.  
  44. /**
  45.  * \brief          Encode a buffer into base64 format
  46.  *
  47.  * \param dst      destination buffer
  48.  * \param dlen     size of the destination buffer
  49.  * \param olen     number of bytes written
  50.  * \param src      source buffer
  51.  * \param slen     amount of data to be encoded
  52.  *
  53.  * \return         0 if successful, or MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL.
  54.  *                 *olen is always updated to reflect the amount
  55.  *                 of data that has (or would have) been written.
  56.  *                 If that length cannot be represented, then no data is
  57.  *                 written to the buffer and *olen is set to the maximum
  58.  *                 length representable as a size_t.
  59.  *
  60.  * \note           Call this function with dlen = 0 to obtain the
  61.  *                 required buffer size in *olen
  62.  */
  63. int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen,
  64.                    const unsigned char *src, size_t slen );
  65.  
  66. /**
  67.  * \brief          Decode a base64-formatted buffer
  68.  *
  69.  * \param dst      destination buffer (can be NULL for checking size)
  70.  * \param dlen     size of the destination buffer
  71.  * \param olen     number of bytes written
  72.  * \param src      source buffer
  73.  * \param slen     amount of data to be decoded
  74.  *
  75.  * \return         0 if successful, MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL, or
  76.  *                 MBEDTLS_ERR_BASE64_INVALID_CHARACTER if the input data is
  77.  *                 not correct. *olen is always updated to reflect the amount
  78.  *                 of data that has (or would have) been written.
  79.  *
  80.  * \note           Call this function with *dst = NULL or dlen = 0 to obtain
  81.  *                 the required buffer size in *olen
  82.  */
  83. int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
  84.                    const unsigned char *src, size_t slen );
  85.  
  86. #if defined(MBEDTLS_SELF_TEST)
  87. /**
  88.  * \brief          Checkup routine
  89.  *
  90.  * \return         0 if successful, or 1 if the test failed
  91.  */
  92. int mbedtls_base64_self_test( int verbose );
  93.  
  94. #endif /* MBEDTLS_SELF_TEST */
  95.  
  96. #ifdef __cplusplus
  97. }
  98. #endif
  99.  
  100. #endif /* base64.h */
  101.