const unsigned char *buf,
const size_t len)
{
+ assert(cer != NULL);
+ assert(off != NULL);
+ assert(failReason != NULL);
(*failReason) = "unspecified";
struct KEKSItems schema;
enum KEKSErr err = KEKSItemsInit(&schema, 512);
const size_t poolLen,
const struct KEKSCMPubVerifyOpts opts)
{
+ assert(failReason != NULL);
+ assert(verifier != NULL);
+ assert(cer != NULL);
+ assert(pool != NULL);
(*failReason) = "unspecified";
if (opts.t.tv_sec <= cer->since.tv_sec) {
(*failReason) = "unsatisfied since";
const unsigned char *buf,
const size_t len)
{
+ assert(atom != NULL);
+ assert(got != NULL);
atom->v.str.ptr = NULL;
atom->v.str.len = 0;
(*got) = 1;
if (len < 1) {
return KEKSErrNotEnough;
}
+ assert(buf != NULL);
unsigned char tag = buf[0];
if ((tag & (uint8_t)KEKSAtomStrings) > 0) {
// You should have received a copy of the GNU Lesser General Public
// License along with this program. If not, see <http://www.gnu.org/licenses/>.
+#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <time.h>
// You should have received a copy of the GNU Lesser General Public
// License along with this program. If not, see <http://www.gnu.org/licenses/>.
+#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
bool
KEKSAtomEOCEncode(size_t *len, unsigned char *buf, const size_t cap)
{
+ assert(len != NULL);
(*len) = 1;
if (cap < 1) {
return false;
}
+ assert(buf != NULL);
buf[0] = KEKSAtomEOC;
return true;
}
bool
KEKSAtomNILEncode(size_t *len, unsigned char *buf, const size_t cap)
{
+ assert(len != NULL);
(*len) = 1;
if (cap < 1) {
return false;
}
+ assert(buf != NULL);
buf[0] = KEKSAtomNIL;
return true;
}
bool
KEKSAtomBoolEncode(size_t *len, unsigned char *buf, const size_t cap, const bool v)
{
+ assert(len != NULL);
(*len) = 1;
if (cap < 1) {
return false;
}
+ assert(buf != NULL);
buf[0] = v ? KEKSAtomTrue : KEKSAtomFalse;
return true;
}
const size_t cap,
const unsigned char v[16])
{
+ assert(len != NULL);
(*len) = 1 + 16;
if (cap < (1 + 16)) {
return false;
}
+ assert(buf != NULL);
buf[0] = KEKSAtomHexlet;
memcpy(buf + 1, v, 16);
return true;
if (vlen > 12) {
return false;
}
+ assert(len != NULL);
(*len) = 1 + 15;
if (cap < (1 + 15)) {
return false;
}
+ assert(buf != NULL);
buf[0] = 'K';
buf[1] = 'E';
buf[2] = 'K';
if (cap < 1) {
return false;
}
+ assert(len != NULL);
+ assert(buf != NULL);
if (v == 0) {
const bool ok =
KEKSAtomBinEncode(len, buf + 1, cap - 1, (const unsigned char *)"", 0);
bool
KEKSAtomListEncode(size_t *len, unsigned char *buf, const size_t cap)
{
+ assert(len != NULL);
(*len) = 1;
if (cap < 1) {
return false;
}
+ assert(buf != NULL);
buf[0] = KEKSAtomList;
return true;
}
bool
KEKSAtomMapEncode(size_t *len, unsigned char *buf, const size_t cap)
{
+ assert(len != NULL);
(*len) = 1;
if (cap < 1) {
return false;
}
+ assert(buf != NULL);
buf[0] = KEKSAtomMap;
return true;
}
const size_t cap,
const size_t chunkLen)
{
+ assert(len != NULL);
(*len) = 1 + 8;
if (cap < 1 + 8) {
return false;
}
+ assert(buf != NULL);
buf[0] = KEKSAtomBlob;
keksToBE(buf + 1, 8, (uint64_t)chunkLen - 1);
return true;
} else {
lVal = (unsigned char)srcLen;
}
+ assert(len != NULL);
(*len) = 1 + lLen + srcLen;
if ((*len) <= srcLen) {
(*len) = 0;
if (cap < (*len)) {
return false;
}
+ assert(buf != NULL);
buf[0] = (uint8_t)KEKSAtomStrings | lVal;
if (utf8) {
buf[0] |= (unsigned char)KEKSAtomIsUTF8;
default:
return false;
}
+ assert(len != NULL);
(*len) = 1 + srcLen;
if (cap < (*len)) {
return false;
}
+ assert(buf != NULL);
buf[0] = tag;
memcpy(buf + 1, src, srcLen);
return true;
// You should have received a copy of the GNU Lesser General Public
// License along with this program. If not, see <http://www.gnu.org/licenses/>.
+#include <assert.h>
#include <stdint.h>
#include <time.h>
bool
KEKSTimespecToTAI64(unsigned char *buf, const struct timespec *ts)
{
+ assert(ts != NULL);
int64_t v = (int64_t)(ts->tv_sec);
uint64_t val = (uint64_t)v + 0x4000000000000000;
if (val <= (uint64_t)v) {
return false;
}
+ assert(buf != NULL);
keksToBE(buf, 8, val);
if (ts->tv_nsec != 0) {
keksToBE(buf + 8, 4, (uint64_t)(ts->tv_nsec));
+// KEKS -- C99 KEKS encoder implementation
+// Copyright (C) 2024-2025 Sergey Matveev <stargrave@stargrave.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as
+// published by the Free Software Foundation, version 3 of the License.
+//
+// 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 Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include <assert.h>
#include <stddef.h>
#include <stdint.h>
uint64_t
keksFromBE(const unsigned char *buf, const size_t len)
{
+ assert(buf != NULL);
uint64_t v = 0;
switch (len) {
case 1:
enum KEKSErr
KEKSItemsInit(struct KEKSItems *items, const ptrdiff_t initialLen)
{
+ assert(items != NULL);
items->len = 0;
items->cap = initialLen;
items->reallocs = 0;
void
KEKSItemsNoOffsets(struct KEKSItems *items)
{
+ assert(items != NULL);
if (items->offsets == NULL) {
return;
}
void
KEKSItemsFree(struct KEKSItems *items)
{
+ assert(items != NULL);
items->len = 0;
items->cap = 0;
if (items->list != NULL) {
enum KEKSErr
KEKSItemsGrow(struct KEKSItems *items)
{
+ assert(items != NULL);
if (items->cap == -1) {
return KEKSErrNoMem;
}
const unsigned char *buf,
const size_t len)
{
+ assert(items != NULL);
+ assert(off != NULL);
+ assert(buf != NULL);
enum KEKSErr err = KEKSErrInvalid;
if (items->len == (size_t)(items->cap)) {
err = KEKSItemsGrow(items);
const bool allowContainers,
const size_t recursionDepth)
{
+ assert(items != NULL);
+ assert(off != NULL);
+ assert(buf != NULL);
if (recursionDepth >= parseMaxRecursionDepth) {
return KEKSErrDeepRecursion;
}
unsigned char *buf,
const size_t cap)
{
+ assert(items != NULL);
+ assert(off != NULL);
+ assert(buf != NULL);
const struct KEKSItem *item = &(items->list[idx]);
size_t got = 0;
bool ok = false;
const char *key,
const size_t keyLen)
{
+ assert(items != NULL);
const struct KEKSItem *item = &(items->list[itemIdx]);
if (item->atom.typ != KEKSItemMap) {
return 0;
bool
KEKSStrEqual(const struct KEKSAtom *atom, const char *s)
{
+ assert(atom != NULL);
return (atom->v.str.len == strlen(s)) &&
(memcmp(atom->v.str.ptr, s, atom->v.str.len) == 0);
}
// You should have received a copy of the GNU Lesser General Public
// License along with this program. If not, see <http://www.gnu.org/licenses/>.
+#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
size_t idxSchema,
size_t idxData)
{
+ assert(our != NULL);
+ assert(their != NULL);
+ assert(schema != NULL);
+ assert(data != NULL);
switch (schema->list[idxSchema].atom.typ) {
case KEKSItemPint:
(*our) = (int64_t)(schema->list[idxSchema].atom.v.pint);
size_t idxSchema,
size_t idxData)
{
+ assert(taken != NULL);
+ assert(eachInList != NULL);
+ assert(eachInMap != NULL);
+ assert(schema != NULL);
+ assert(data != NULL);
size_t origIdxSchema = idxSchema;
struct KEKSSchemaErr err;
size_t v = *taken;
size_t idxSchema,
size_t idxData)
{
+ assert(schema != NULL);
+ assert(data != NULL);
struct KEKSSchemaErr err = (struct KEKSSchemaErr){
.offSchema = schema->offsets[idxSchema],
.offData = data->offsets[idxData],
+// KEKS -- C99 KEKS encoder implementation
+// Copyright (C) 2024-2025 Sergey Matveev <stargrave@stargrave.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as
+// published by the Free Software Foundation, version 3 of the License.
+//
+// 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 Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include <assert.h>
#include <stddef.h>
#include <stdint.h>
void
keksToBE(unsigned char *buf, const size_t len, const uint64_t v)
{
+ assert(buf != NULL);
switch (len) {
case 1:
buf[0] = (v & (uint64_t)0x00000000000000FF);