libosmocore 1.13.1.1-afb4 Osmocom core library

Functions | Variables
base64.c File Reference
`#include "config.h"`
`#include <osmocom/core/base64.h>`
`#include <stdint.h>`
`#include <stdio.h>`
`#include <errno.h>`

## Functions
int | osmo_base64_encode (unsigned char *dst, size_t dlen, size_t *olen, const unsigned char *src, size_t slen)
| Encode a buffer into base64 format. More...
int | osmo_base64_decode (unsigned char *dst, size_t dlen, size_t *olen, const unsigned char *src, size_t slen)
| Decode a base64-formatted buffer. More...

## Variables
static const unsigned char | base64_enc_map [64]
static const unsigned char | base64_dec_map [128]

## Function Documentation

## ◆ osmo_base64_decode()

int osmo_base64_decode | ( | unsigned char * | dst,
|  | size_t | dlen,
|  | size_t * | olen,
|  | const unsigned char * | src,
|  | size_t | slen
| ) |  |

Decode a base64-formatted buffer.

Parameters

  dst | destination buffer (can be NULL for checking size)
  dlen | size of the destination buffer
  olen | number of bytes written
  src | source buffer
  slen | amount of data to be decoded

Returns
  0 if successful, MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL, or MBEDTLS_ERR_BASE64_INVALID_CHARACTER if the input data is not correct. *olen is always updated to reflect the amount of data that has (or would have) been written.

Note
  Call this function with *dst = NULL or dlen = 0 to obtain the required buffer size in *olen

References base64_dec_map, n, and x.

## ◆ osmo_base64_encode()

int osmo_base64_encode | ( | unsigned char * | dst,
|  | size_t | dlen,
|  | size_t * | olen,
|  | const unsigned char * | src,
|  | size_t | slen
| ) |  |

Encode a buffer into base64 format.

Parameters

  dst | destination buffer
  dlen | size of the destination buffer
  olen | number of bytes written
  src | source buffer
  slen | amount of data to be encoded

Returns
  0 if successful, or MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL. *olen is always updated to reflect the amount of data that has (or would have) been written.

Note
  Call this function with dlen = 0 to obtain the required buffer size in *olen

References base64_enc_map, and n.

## Variable Documentation

## ◆ base64_dec_map

const unsigned char base64_dec_map[128]
| static

Initial value:
= {
127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
127, 127, 127, 62, 127, 127, 127, 63, 52, 53,
54, 55, 56, 57, 58, 59, 60, 61, 127, 127,
127, 64, 127, 127, 127, 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, 127, 127, 127, 127, 127, 127, 26, 27, 28,
29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
49, 50, 51, 127, 127, 127, 127, 127
}

Referenced by osmo_base64_decode().

## ◆ base64_enc_map

const unsigned char base64_enc_map[64]
| static

Initial value:
= {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', '+', '/'
}

Referenced by osmo_base64_encode().