[OpenWrt-Devel] [PATCH] [libubox] b64: add base64 support

Felix Fietkau nbd at openwrt.org
Tue Mar 17 02:27:51 EDT 2015


On 2015-03-16 18:48, Luka Perkov wrote:
> The code has been taken from zstream project which
> was written by Steven Barth.
> 
> Signed-off-by: Luka Perkov <luka at openwrt.org>
> CC: Steven Barth <steven at midlink.org>
> CC: John Crispin <blogic at openwrt.org>
> ---
> --- /dev/null
> +++ b/b64.h
> @@ -0,0 +1,25 @@
> +/*
> + * Copyright (C) 2011 Steven Barth <steven at midlink.org>
> + *
> + * Permission to use, copy, modify, and/or distribute this software for any
> + * purpose with or without fee is hereby granted, provided that the above
> + * copyright notice and this permission notice appear in all copies.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> + */
> +
> +#ifndef __LIBUBOX_B64_H
> +#define __LIBUBOX_B64_H
> +
> +#include <stddef.h>
> +
> +char *b64encode(const void *in, size_t *len);
> +void *b64decode(const char *in, size_t *len);
I think output buffers should be passed in by the caller, and the
functions should return size_t.
You could then add an inline function that returns the maximum output
buffer size for encode/decode.

Example:

size_t b64decode(void *out, const void *in, size_t len);
size_t b64encode(void *out, const void *in, size_t len);

static inline int b64_decode_size(size_t in);
static inline int b64_encode_size(size_t in);

b64decode() should also be able to handle in == out.

- Felix
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list