/*
webid-oidc, implementation of the Solid specification
Copyright (C) 2020, 2021 Vivien Kraus
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
#include
#define _(s) dgettext (PACKAGE, s)
void init_webidoidc_base64 (void);
SCM_DEFINE (webidoidc_base64_encode_g, "base64-encode", 1, 0, 0, (SCM data),
"Encode @var{data} as base64. If @var{data} is a string, first encode it to UTF-8.")
{
size_t c_size;
uint8_t *c_data;
if (scm_is_string (data))
{
return webidoidc_base64_encode_g (scm_string_to_utf8 (data));
}
c_size = scm_c_bytevector_length (data);
c_data = scm_gc_malloc_pointerless (c_size, "data");
memcpy (c_data, SCM_BYTEVECTOR_CONTENTS (data), c_size);
return wrap_bytevector (c_size, c_data);
}
SCM_DEFINE (webidoidc_base64_decode_g, "base64-decode", 1, 0, 0, (SCM data),
"Decode @var{data} from base64.")
{
size_t c_size;
uint8_t *c_data = get_as_bytevector (data, &c_size, 1);
SCM ret = scm_c_make_bytevector (c_size);
memcpy (SCM_BYTEVECTOR_CONTENTS (ret), c_data, c_size);
return ret;
}
void
init_webidoidc_base64 (void)
{
#ifndef SCM_MAGIC_SNARFER
#include "libwebidoidc-base64.x"
#endif /* not SCM_MAGIC_SNARFER */
}