Mercurial > libavutil.hg
comparison base64.c @ 320:ca1f5d65e653 libavutil
expose av_base64_decode and av_base64_encode
author | lu_zero |
---|---|
date | Mon, 19 Mar 2007 00:48:47 +0000 |
parents | 9a977b2c7069 |
children | 62575220eb1a |
comparison
equal
deleted
inserted
replaced
319:aac7ff53ef86 | 320:ca1f5d65e653 |
---|---|
68 * b64_encode: stolen from VLC's http.c | 68 * b64_encode: stolen from VLC's http.c |
69 * simplified by michael | 69 * simplified by michael |
70 * fixed edge cases and made it work from data (vs. strings) by ryan. | 70 * fixed edge cases and made it work from data (vs. strings) by ryan. |
71 *****************************************************************************/ | 71 *****************************************************************************/ |
72 | 72 |
73 char *av_base64_encode(uint8_t * src, int len) | 73 char *av_base64_encode(char * buf, int buf_len, uint8_t * src, int len) |
74 { | 74 { |
75 static const char b64[] = | 75 static const char b64[] = |
76 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | 76 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
77 char *ret, *dst; | 77 char *ret, *dst; |
78 unsigned i_bits = 0; | 78 unsigned i_bits = 0; |
79 int i_shift = 0; | 79 int i_shift = 0; |
80 int bytes_remaining = len; | 80 int bytes_remaining = len; |
81 | 81 |
82 if (len < UINT_MAX / 4) { | 82 if (len >= UINT_MAX / 4 || |
83 ret = dst = av_malloc(len * 4 / 3 + 12); | 83 buf_len < len * 4 / 3 + 12) |
84 } else | |
85 return NULL; | 84 return NULL; |
86 | 85 ret = dst = buf; |
87 if (len) { // special edge case, what should we really do here? | 86 if (len) { // special edge case, what should we really do here? |
88 while (bytes_remaining) { | 87 while (bytes_remaining) { |
89 i_bits = (i_bits << 8) + *src++; | 88 i_bits = (i_bits << 8) + *src++; |
90 bytes_remaining--; | 89 bytes_remaining--; |
91 i_shift += 8; | 90 i_shift += 8; |