From: Sergey Matveev Date: Thu, 16 Jan 2025 12:55:24 +0000 (+0300) Subject: Move KEKSAtom definition to apropriate header X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=32e48c85f8b1c94d768da9911868666ecd52f050a0afc747a092e9762e649c17;p=keks.git Move KEKSAtom definition to apropriate header --- diff --git a/c/cmd/deatomiser/deatomiser.c b/c/cmd/deatomiser/deatomiser.c index 118ce4a..50c3966 100644 --- a/c/cmd/deatomiser/deatomiser.c +++ b/c/cmd/deatomiser/deatomiser.c @@ -17,6 +17,7 @@ #include #include +#include #include #include diff --git a/c/cmd/for-fuzz/for-fuzz.c b/c/cmd/for-fuzz/for-fuzz.c index 530cc26..6a79c56 100644 --- a/c/cmd/for-fuzz/for-fuzz.c +++ b/c/cmd/for-fuzz/for-fuzz.c @@ -18,7 +18,7 @@ main(int argc, char **argv) exit(EXIT_FAILURE); } struct KEKSItems items; - enum KEKSErr err = KEKSItemsInit(&items); + enum KEKSErr err = KEKSItemsInit(&items, 128); if (err != KEKSErrNo) { return EXIT_FAILURE; } diff --git a/c/cmd/pp/pp.c b/c/cmd/pp/pp.c index e27db41..25763e8 100644 --- a/c/cmd/pp/pp.c +++ b/c/cmd/pp/pp.c @@ -18,13 +18,14 @@ #include #include #include +#include #include #include #include #include #include -#include +#include #include #include diff --git a/c/cmd/test-vector/test-vector.c b/c/cmd/test-vector/test-vector.c index b436968..d8251ed 100644 --- a/c/cmd/test-vector/test-vector.c +++ b/c/cmd/test-vector/test-vector.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include diff --git a/c/lib/atom.h b/c/lib/atom.h new file mode 100644 index 0000000..f747b18 --- /dev/null +++ b/c/lib/atom.h @@ -0,0 +1,124 @@ +#ifndef KEKS_ATOM_H +#define KEKS_ATOM_H + +#include +#include + +enum KEKSAtomType { + KEKSAtomEOC = 0x00, + KEKSAtomNIL = 0x01, + KEKSAtomFalse = 0x02, + KEKSAtomTrue = 0x03, + KEKSAtomUUID = 0x04, + KEKSAtomList = 0x08, + KEKSAtomMap = 0x09, + KEKSAtomBlob = 0x0B, + KEKSAtomPint = 0x0C, + KEKSAtomNint = 0x0D, + KEKSAtomFloat16 = 0x10, + KEKSAtomFloat32 = 0x11, + KEKSAtomFloat64 = 0x12, + KEKSAtomFloat128 = 0x13, + KEKSAtomFloat256 = 0x14, + KEKSAtomTAI64 = 0x18, + KEKSAtomTAI64N = 0x19, + KEKSAtomTAI64NA = 0x1A, + + KEKSAtomStrings = 0x80, + KEKSAtomIsUTF8 = 0x40, +}; + +// TEXINFO: KEKSItemType +// @deftp {Data type} {enum KEKSItemType} +// High-level type of the atom. +// @itemize +// @item KEKSItemInvalid -- invalid item value, uninitialised +// @item KEKSItemEOC +// @item KEKSItemNIL +// @item KEKSItemFalse +// @item KEKSItemTrue +// @item KEKSItemUUID +// @item KEKSItemPint -- positive integer +// @item KEKSItemNint -- negative integer +// @item KEKSItemList +// @item KEKSItemMap +// @item KEKSItemBlob +// @item KEKSItemFloat +// @item KEKSItemTAI64 +// @item KEKSItemBin +// @item KEKSItemStr +// @item KEKSItemRaw -- raw value, non-decodable by the library +// @end itemize +// @end deftp +enum KEKSItemType { + KEKSItemInvalid = 0, + KEKSItemEOC = 1, + KEKSItemNIL, + KEKSItemFalse, + KEKSItemTrue, + KEKSItemUUID, + KEKSItemPint, + KEKSItemNint, + KEKSItemList, + KEKSItemMap, + KEKSItemBlob, + KEKSItemFloat, + KEKSItemTAI64, + KEKSItemBin, + KEKSItemStr, + KEKSItemRaw, +}; + +// TEXINFO: KEKSAtom +// @deftp {Data type} {struct KEKSAtom} +// Basic unit of the library, describing single TLV-like value. +// @table @code +// @item .typ +// High level @ref{KEKSItemType, type} of the atom's value. As a rule +// you should look solely on it. +// @item .v.uuid +// Pointer to 16-byte UUID value. +// @item .v.pint +// Value of the positive integer. +// @item .v.nint +// Value of the negative integer. +// @item .v.list +// That value is filled only when dealing with @ref{Items, items} +// for lists and maps. +// Its @code{.head} is the index in items list to the first element +// inside the container. If equals to 0, then it is empty. Its +// @code{.len} contains number of the items (key-values pairs in +// case of map) inside it. +// @item .v.blob +// That value is filled only when dealing with @ref{Items, items}. +// @code{.chunkLen} is the length of the chunk. @code{.chunks} is +// the number of chunks, including the terminating binary string. +// @item .v.str +// @code{.ptr} points to the start of the binary/UTF-8/TAI64* +// string. @code{.len} is its length in bytes. +// Raw values use it as a payload. +// @end table +// @end deftp +struct KEKSAtom { + union { + const unsigned char *uuid; + uint64_t pint; + int64_t nint; + struct { + size_t head; + size_t len; + } list; + struct { + size_t chunkLen; + size_t chunks; + } blob; + struct { + const unsigned char *ptr; + size_t len; + } str; + } v; + enum KEKSItemType typ; + char _pad[4]; +}; + +#endif // KEKS_ATOM_H diff --git a/c/lib/atoms.h b/c/lib/atoms.h deleted file mode 100644 index 4581ed0..0000000 --- a/c/lib/atoms.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef KEKS_ATOMS_H -#define KEKS_ATOMS_H - -enum KEKSAtomType { - KEKSAtomEOC = 0x00, - KEKSAtomNIL = 0x01, - KEKSAtomFalse = 0x02, - KEKSAtomTrue = 0x03, - KEKSAtomUUID = 0x04, - KEKSAtomList = 0x08, - KEKSAtomMap = 0x09, - KEKSAtomBlob = 0x0B, - KEKSAtomPint = 0x0C, - KEKSAtomNint = 0x0D, - KEKSAtomFloat16 = 0x10, - KEKSAtomFloat32 = 0x11, - KEKSAtomFloat64 = 0x12, - KEKSAtomFloat128 = 0x13, - KEKSAtomFloat256 = 0x14, - KEKSAtomTAI64 = 0x18, - KEKSAtomTAI64N = 0x19, - KEKSAtomTAI64NA = 0x1A, - - KEKSAtomStrings = 0x80, - KEKSAtomIsUTF8 = 0x40, -}; - -#endif // KEKS_ATOMS_H diff --git a/c/lib/dec.c b/c/lib/dec.c index 22d0ae9..b844af3 100644 --- a/c/lib/dec.c +++ b/c/lib/dec.c @@ -19,7 +19,7 @@ #include #include -#include "atoms.h" +#include "atom.h" #include "dec.h" #include "err.h" #include "frombe.h" diff --git a/c/lib/dec.h b/c/lib/dec.h index 507d48e..f006492 100644 --- a/c/lib/dec.h +++ b/c/lib/dec.h @@ -2,103 +2,10 @@ #define KEKS_DEC_H #include -#include +#include "atom.h" #include "err.h" -// TEXINFO: KEKSItemType -// @deftp {Data type} {enum KEKSItemType} -// High-level type of the atom. -// @itemize -// @item KEKSItemInvalid -- invalid item value, uninitialised -// @item KEKSItemEOC -// @item KEKSItemNIL -// @item KEKSItemFalse -// @item KEKSItemTrue -// @item KEKSItemUUID -// @item KEKSItemPint -- positive integer -// @item KEKSItemNint -- negative integer -// @item KEKSItemList -// @item KEKSItemMap -// @item KEKSItemBlob -// @item KEKSItemFloat -// @item KEKSItemTAI64 -// @item KEKSItemBin -// @item KEKSItemStr -// @item KEKSItemRaw -- raw value, non-decodable by the library -// @end itemize -// @end deftp -enum KEKSItemType { - KEKSItemInvalid = 0, - KEKSItemEOC = 1, - KEKSItemNIL, - KEKSItemFalse, - KEKSItemTrue, - KEKSItemUUID, - KEKSItemPint, - KEKSItemNint, - KEKSItemList, - KEKSItemMap, - KEKSItemBlob, - KEKSItemFloat, - KEKSItemTAI64, - KEKSItemBin, - KEKSItemStr, - KEKSItemRaw, -}; - -// TEXINFO: KEKSAtom -// @deftp {Data type} {struct KEKSAtom} -// Basic unit of the library, describing single TLV-like value. -// @table @code -// @item .typ -// High level @ref{KEKSItemType, type} of the atom's value. As a rule -// you should look solely on it. -// @item .v.uuid -// Pointer to 16-byte UUID value. -// @item .v.pint -// Value of the positive integer. -// @item .v.nint -// Value of the negative integer. -// @item .v.list -// That value is filled only when dealing with @ref{Items, items} -// for lists and maps. -// Its @code{.head} is the index in items list to the first element -// inside the container. If equals to 0, then it is empty. Its -// @code{.len} contains number of the items (key-values pairs in -// case of map) inside it. -// @item .v.blob -// That value is filled only when dealing with @ref{Items, items}. -// @code{.chunkLen} is the length of the chunk. @code{.chunks} is -// the number of chunks, including the terminating binary string. -// @item .v.str -// @code{.ptr} points to the start of the binary/UTF-8/TAI64* -// string. @code{.len} is its length in bytes. -// Raw values use it as a payload. -// @end table -// @end deftp -struct KEKSAtom { - union { - const unsigned char *uuid; - uint64_t pint; - int64_t nint; - struct { - size_t head; - size_t len; - } list; - struct { - size_t chunkLen; - size_t chunks; - } blob; - struct { - const unsigned char *ptr; - size_t len; - } str; - } v; - enum KEKSItemType typ; - char _pad[4]; -}; - // TEXINFO: KEKSAtomDecode // @deftypefun {enum KEKSErr} KEKSAtomDecode ( @ // size_t *got, @ diff --git a/c/lib/enc.c b/c/lib/enc.c index bf8e418..f18a92b 100644 --- a/c/lib/enc.c +++ b/c/lib/enc.c @@ -18,7 +18,7 @@ #include #include -#include "atoms.h" +#include "atom.h" #include "enc.h" #include "tobe.h" diff --git a/c/lib/items.h b/c/lib/items.h index c085484..6f9b1bb 100644 --- a/c/lib/items.h +++ b/c/lib/items.h @@ -4,7 +4,7 @@ #include #include -#include "dec.h" +#include "atom.h" #include "err.h" // TEXINFO: KEKSItem diff --git a/c/lib/pki/cer.c b/c/lib/pki/cer.c index 81eb105..81ce256 100644 --- a/c/lib/pki/cer.c +++ b/c/lib/pki/cer.c @@ -2,7 +2,7 @@ #include #include -#include "../dec.h" +#include "../atom.h" #include "../dectai.h" #include "../enc.h" #include "../err.h"