/* This file is part of limb https://lila.oss/limb
* Copyright (C) 2023 Olivier Brunel jjk@jjacky.com */
/* SPDX-License-Identifier: GPL-2.0-only */
#include <limb/buffer-shldata.h>
#include <limb/shldata.h>
#include <limb/siovec.h>
ssize_t
buffer_shldata_get(buffer *b, char *dst, size_t dlen, buffer_shldata_ctx *ctx)
{
if (ctx->sd.done + dlen > ctx->sd.len)
dlen = ctx->sd.len - ctx->sd.done;
if (dlen) {
if (buffer_get(b, dst, dlen) < 0)
return -1;
shldata_decrypt(dst, dst, dlen, &ctx->sd);
}
return dlen;
}