From 29e2952bb1762db37418ef6aace46ecb3e1abdbbdbfebbcfa504a222643fad9b Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sun, 15 Dec 2024 20:57:09 +0300 Subject: [PATCH] Great renaming --- README | 7 +- {cyac => c}/.clang-tidy | 0 {cyac => c}/.gitignore | 0 {cyac => c}/COPYING | 0 {cyac => c}/COPYING.LESSER | 0 c/README | 2 + {cyac => c}/clean | 0 {cyac => c}/cmd/cer-verify/.gitignore | 0 {cyac => c}/cmd/cer-verify/all.do | 0 {cyac => c}/cmd/cer-verify/cer-verify.c | 28 +- {cyac => c}/cmd/cer-verify/cer-verify.do | 2 +- {cyac => c}/cmd/cer-verify/clean | 0 .../cmd/cer-verify/compile_flags.txt.do | 0 {cyac => c}/cmd/cer-verify/conf/.gitignore | 0 {cyac => c}/cmd/cer-verify/conf/gcl3.rc.do | 0 .../cmd/cer-verify/conf/monocypher.rc.do | 0 {cyac => c}/cmd/cer-verify/curves.c.in | 0 .../cmd/cer-verify/verifier-ed25519-blake2b.c | 0 .../cmd/cer-verify/verifier-ed25519-blake2b.h | 6 +- .../cer-verify/verifier-ed25519-blake2b.o.do | 0 .../cmd/cer-verify/verifier-gost3410.c | 0 .../cmd/cer-verify/verifier-gost3410.h | 6 +- .../cmd/cer-verify/verifier-gost3410.o.do | 0 {cyac => c}/cmd/clean | 0 {cyac => c}/cmd/for-fuzz/.gitignore | 0 {cyac => c}/cmd/for-fuzz/all.do | 0 {cyac => c}/cmd/for-fuzz/clean | 0 {cyac => c}/cmd/for-fuzz/for-fuzz.c | 16 +- {cyac => c}/cmd/for-fuzz/for-fuzz.do | 2 +- {cyac => c}/cmd/lib/clean | 0 {cyac => c}/cmd/lib/default.o.do | 0 {cyac => c}/cmd/lib/hex.c | 0 {cyac => c}/cmd/lib/hex.h | 6 +- {cyac => c}/cmd/lib/mmap.c | 0 {cyac => c}/cmd/lib/mmap.h | 6 +- {cyac => c}/cmd/lib/printai.c | 28 +- c/cmd/lib/printai.h | 11 + {cyac => c}/cmd/lib/printai.o.do | 0 {cyac => c}/cmd/lib/uuid.c | 0 c/cmd/lib/uuid.h | 7 + {cyac => c}/cmd/print-items/.gitignore | 0 {cyac => c}/cmd/print-items/all.do | 0 {cyac => c}/cmd/print-items/clean | 0 {cyac => c}/cmd/print-items/print-items.c | 80 +++--- {cyac => c}/cmd/print-items/print-items.do | 2 +- {cyac => c}/cmd/print-itered/.gitignore | 0 {cyac => c}/cmd/print-itered/all.do | 0 {cyac => c}/cmd/print-itered/clean | 0 {cyac => c}/cmd/print-itered/print-itered.c | 78 ++--- {cyac => c}/cmd/print-itered/print-itered.do | 2 +- {cyac => c}/cmd/test-vector/.gitignore | 0 {cyac => c}/cmd/test-vector/all.do | 0 {cyac => c}/cmd/test-vector/clean | 0 c/cmd/test-vector/test-vector.c | 252 +++++++++++++++++ {cyac => c}/cmd/test-vector/test-vector.do | 2 +- {cyac => c}/compile_flags.txt.do | 0 {cyac => c}/conf/ar | 0 {cyac => c}/conf/cc | 0 {cyac => c}/conf/cflags | 0 {cyac => c}/conf/ldflags | 0 {cyac => c}/conf/prefix | 0 {cyac => c}/doc/.gitignore | 2 +- c/doc/atom.texi | 29 ++ cyac/doc/cyac.info.do => c/doc/ckeks.info.do | 0 {cyac => c}/doc/clean | 2 +- {cyac => c}/doc/cmd.texi | 2 +- {cyac => c}/doc/docstringer.log.do | 0 {cyac => c}/doc/docstringer.pl | 0 {cyac => c}/doc/err.texi | 4 +- {cyac => c}/doc/index.texi | 8 +- {cyac => c}/doc/install.texi | 0 c/doc/items.texi | 24 ++ c/doc/pki.texi | 19 ++ c/doc/tai64.texi | 13 + {cyac => c}/lib/.gitignore | 2 +- c/lib/atoms.h | 28 ++ {cyac => c}/lib/clean | 0 {cyac => c}/lib/dec.c | 180 ++++++------ {cyac => c}/lib/dec.h | 102 +++---- {cyac => c}/lib/dectai.c | 34 +-- c/lib/dectai.h | 31 ++ {cyac => c}/lib/default.o.do | 0 {cyac => c}/lib/enc.c | 86 +++--- {cyac => c}/lib/enc.h | 96 +++---- {cyac => c}/lib/enctai.c | 14 +- {cyac => c}/lib/enctai.h | 18 +- {cyac => c}/lib/err.c | 46 +-- c/lib/err.h | 78 +++++ {cyac => c}/lib/frombe.c | 2 +- c/lib/frombe.h | 11 + {cyac => c}/lib/h-extract.pl | 0 c/lib/install.do | 6 + {cyac => c}/lib/items.c | 266 +++++++++--------- {cyac => c}/lib/items.h | 136 ++++----- {cyac => c}/lib/iter.c | 102 +++---- {cyac => c}/lib/iter.h | 34 +-- {cyac => c}/lib/leapsecs.c | 4 +- c/lib/leapsecs.h | 15 + cyac/lib/libyac.a.do => c/lib/libkeks.a.do | 0 {cyac => c}/lib/o.list | 0 c/lib/pki/.gitignore | 1 + {cyac => c}/lib/pki/cer.c | 198 ++++++------- {cyac => c}/lib/pki/cer.h | 78 ++--- {cyac => c}/lib/pki/clean | 0 c/lib/pki/install.do | 6 + .../lib/pki/libkekspki.a.do | 0 {cyac => c}/lib/pki/o.list | 0 {cyac => c}/lib/tobe.c | 2 +- c/lib/tobe.h | 11 + {cyac => c}/lib/utf8.c | 16 +- c/lib/utf8.h | 12 + {cyac => c}/lint/.clang-format | 0 {cyac => c}/lint/iwyu-maps.imp | 0 cyac/README | 2 - cyac/cmd/lib/printai.h | 11 - cyac/cmd/lib/uuid.h | 7 - cyac/cmd/test-vector/test-vector.c | 252 ----------------- cyac/doc/atom.texi | 29 -- cyac/doc/items.texi | 24 -- cyac/doc/pki.texi | 19 -- cyac/doc/tai64.texi | 13 - cyac/lib/atoms.h | 28 -- cyac/lib/dectai.h | 31 -- cyac/lib/err.h | 78 ----- cyac/lib/frombe.h | 11 - cyac/lib/install.do | 6 - cyac/lib/leapsecs.h | 15 - cyac/lib/pki/.gitignore | 1 - cyac/lib/pki/install.do | 6 - cyac/lib/tobe.h | 11 - cyac/lib/utf8.h | 12 - {gyac => go}/COPYING | 0 {gyac => go}/COPYING.LESSER | 0 {gyac => go}/README | 4 +- {gyac => go}/atom/be/be.go | 2 +- {gyac => go}/atom/dec.go | 8 +- {gyac => go}/atom/enc.go | 4 +- {gyac => go}/atom/raw.go | 2 +- {gyac => go}/atom/type_string.go | 0 {gyac => go}/blob.go | 4 +- {gyac => go}/cmd/print/main.go | 4 +- {gyac => go}/cmd/test-vector-anys/main.go | 16 +- {gyac => go}/cmd/test-vector-manual/main.go | 2 +- {gyac => go}/dec.go | 10 +- go/doc.go | 6 + {gyac => go}/enc.go | 8 +- {gyac => go}/fromgo.go | 10 +- {gyac => go}/fuzz_test.go | 2 +- {gyac => go}/go.mod | 2 +- {gyac => go}/go.sum | 0 {gyac => go}/mapstruct/dec.go | 12 +- {gyac => go}/mapstruct/map.go | 4 +- {gyac => go}/mk-fuzz-testdata | 2 +- {gyac => go}/pki/algo.go | 4 +- {gyac => go}/pki/av.go | 10 +- {gyac => go}/pki/cer.go | 28 +- .../pki/cmd/kekscertool}/basic.t | 14 +- .../pki/cmd/kekscertool}/main.go | 16 +- .../pki/cmd/kekssdtool}/main.go | 12 +- go/pki/doc.go | 2 + {gyac => go}/pki/ed25519-blake2b/.gitignore | 0 {gyac => go}/pki/ed25519-blake2b/algo.go | 0 {gyac => go}/pki/ed25519-blake2b/clean | 0 .../ed25519-blake2b/ed25519-to-blake2b.patch | 2 +- {gyac => go}/pki/ed25519-blake2b/kp.go | 2 +- {gyac => go}/pki/ed25519-blake2b/mk-from-go | 2 +- {gyac => go}/pki/ed25519-blake2b/prv.go | 2 +- {gyac => go}/pki/ed25519-blake2b/verify.go | 2 +- {gyac => go}/pki/go.mod | 2 +- {gyac => go}/pki/go.sum | 0 {gyac => go}/pki/gost/gost.go | 0 {gyac => go}/pki/gost/kp.go | 0 {gyac => go}/pki/gost/signer.go | 0 {gyac => go}/pki/gost/verify.go | 2 +- {gyac => go}/pki/hash/algo.go | 0 {gyac => go}/pki/prv.go | 8 +- {gyac => go}/pki/signed-data.go | 52 ++-- {gyac => go}/pki/utils/utils.go | 0 {gyac => go}/sort.go | 2 +- {gyac => go}/togo.go | 8 +- {gyac => go}/types/type.go | 0 {gyac => go}/types/type_string.go | 0 gyac/doc.go | 6 - gyac/pki/doc.go | 2 - {pyac => py3}/.gitignore | 0 {pyac => py3}/COPYING | 0 {pyac => py3}/COPYING.LESSER | 0 py3/README | 6 + pyac/pyac.py => py3/keks.py | 26 +- {pyac => py3}/test-vector.py | 26 +- {pyac => py3}/tests/.gitignore | 0 {pyac => py3}/tests/__init__.py | 0 {pyac => py3}/tests/fuzz.py | 4 +- {pyac => py3}/tests/requirements.txt | 0 {pyac => py3}/tests/strategies.py | 4 +- {pyac => py3}/tests/test_blob.py | 12 +- {pyac => py3}/tests/test_bool.py | 6 +- {pyac => py3}/tests/test_everything.py | 6 +- {pyac => py3}/tests/test_float.py | 10 +- {pyac => py3}/tests/test_fuzz_inputs.py | 18 +- {pyac => py3}/tests/test_generic.py | 12 +- {pyac => py3}/tests/test_int.py | 10 +- {pyac => py3}/tests/test_list.py | 8 +- {pyac => py3}/tests/test_map.py | 8 +- {pyac => py3}/tests/test_not_enough_data.py | 4 +- {pyac => py3}/tests/test_recursion.py | 14 +- {pyac => py3}/tests/test_str.py | 10 +- {pyac => py3}/tests/test_tai.py | 20 +- {pyac => py3}/tests/test_uuid.py | 8 +- pyac/README | 6 - spec/design.texi | 2 +- spec/encoding/index.texi | 2 +- spec/index.texi | 20 +- spec/install.texi | 12 +- spec/schema.texi | 2 +- {tyac => tcl}/COPYING | 0 {tyac => tcl}/COPYING.LESSER | 0 tcl/README | 5 + tcl/args | 6 + tyac/tyac.tcl => tcl/keks.tcl | 4 +- {tyac => tcl}/mk-fuzz-inputs | 0 {tyac => tcl}/test-vector.tcl | 6 +- tyac/README | 5 - tyac/args | 6 - 224 files changed, 1699 insertions(+), 1686 deletions(-) rename {cyac => c}/.clang-tidy (100%) rename {cyac => c}/.gitignore (100%) rename {cyac => c}/COPYING (100%) rename {cyac => c}/COPYING.LESSER (100%) create mode 100644 c/README rename {cyac => c}/clean (100%) rename {cyac => c}/cmd/cer-verify/.gitignore (100%) rename {cyac => c}/cmd/cer-verify/all.do (100%) rename {cyac => c}/cmd/cer-verify/cer-verify.c (78%) rename {cyac => c}/cmd/cer-verify/cer-verify.do (89%) rename {cyac => c}/cmd/cer-verify/clean (100%) rename {cyac => c}/cmd/cer-verify/compile_flags.txt.do (100%) rename {cyac => c}/cmd/cer-verify/conf/.gitignore (100%) rename {cyac => c}/cmd/cer-verify/conf/gcl3.rc.do (100%) rename {cyac => c}/cmd/cer-verify/conf/monocypher.rc.do (100%) rename {cyac => c}/cmd/cer-verify/curves.c.in (100%) rename {cyac => c}/cmd/cer-verify/verifier-ed25519-blake2b.c (100%) rename {cyac => c}/cmd/cer-verify/verifier-ed25519-blake2b.h (72%) rename {cyac => c}/cmd/cer-verify/verifier-ed25519-blake2b.o.do (100%) rename {cyac => c}/cmd/cer-verify/verifier-gost3410.c (100%) rename {cyac => c}/cmd/cer-verify/verifier-gost3410.h (76%) rename {cyac => c}/cmd/cer-verify/verifier-gost3410.o.do (100%) rename {cyac => c}/cmd/clean (100%) rename {cyac => c}/cmd/for-fuzz/.gitignore (100%) rename {cyac => c}/cmd/for-fuzz/all.do (100%) rename {cyac => c}/cmd/for-fuzz/clean (100%) rename {cyac => c}/cmd/for-fuzz/for-fuzz.c (69%) rename {cyac => c}/cmd/for-fuzz/for-fuzz.do (92%) rename {cyac => c}/cmd/lib/clean (100%) rename {cyac => c}/cmd/lib/default.o.do (100%) rename {cyac => c}/cmd/lib/hex.c (100%) rename {cyac => c}/cmd/lib/hex.h (59%) rename {cyac => c}/cmd/lib/mmap.c (100%) rename {cyac => c}/cmd/lib/mmap.h (63%) rename {cyac => c}/cmd/lib/printai.c (80%) create mode 100644 c/cmd/lib/printai.h rename {cyac => c}/cmd/lib/printai.o.do (100%) rename {cyac => c}/cmd/lib/uuid.c (100%) create mode 100644 c/cmd/lib/uuid.h rename {cyac => c}/cmd/print-items/.gitignore (100%) rename {cyac => c}/cmd/print-items/all.do (100%) rename {cyac => c}/cmd/print-items/clean (100%) rename {cyac => c}/cmd/print-items/print-items.c (87%) rename {cyac => c}/cmd/print-items/print-items.do (95%) rename {cyac => c}/cmd/print-itered/.gitignore (100%) rename {cyac => c}/cmd/print-itered/all.do (100%) rename {cyac => c}/cmd/print-itered/clean (100%) rename {cyac => c}/cmd/print-itered/print-itered.c (76%) rename {cyac => c}/cmd/print-itered/print-itered.do (96%) rename {cyac => c}/cmd/test-vector/.gitignore (100%) rename {cyac => c}/cmd/test-vector/all.do (100%) rename {cyac => c}/cmd/test-vector/clean (100%) create mode 100644 c/cmd/test-vector/test-vector.c rename {cyac => c}/cmd/test-vector/test-vector.do (97%) rename {cyac => c}/compile_flags.txt.do (100%) rename {cyac => c}/conf/ar (100%) rename {cyac => c}/conf/cc (100%) rename {cyac => c}/conf/cflags (100%) rename {cyac => c}/conf/ldflags (100%) rename {cyac => c}/conf/prefix (100%) rename {cyac => c}/doc/.gitignore (67%) create mode 100644 c/doc/atom.texi rename cyac/doc/cyac.info.do => c/doc/ckeks.info.do (100%) rename {cyac => c}/doc/clean (56%) rename {cyac => c}/doc/cmd.texi (94%) rename {cyac => c}/doc/docstringer.log.do (100%) rename {cyac => c}/doc/docstringer.pl (100%) rename {cyac => c}/doc/err.texi (52%) rename {cyac => c}/doc/index.texi (90%) rename {cyac => c}/doc/install.texi (100%) create mode 100644 c/doc/items.texi create mode 100644 c/doc/pki.texi create mode 100644 c/doc/tai64.texi rename {cyac => c}/lib/.gitignore (68%) create mode 100644 c/lib/atoms.h rename {cyac => c}/lib/clean (100%) rename {cyac => c}/lib/dec.c (55%) rename {cyac => c}/lib/dec.h (59%) rename {cyac => c}/lib/dectai.c (66%) create mode 100644 c/lib/dectai.h rename {cyac => c}/lib/default.o.do (100%) rename {cyac => c}/lib/enc.c (69%) rename {cyac => c}/lib/enc.h (73%) rename {cyac => c}/lib/enctai.c (79%) rename {cyac => c}/lib/enctai.h (60%) rename {cyac => c}/lib/err.c (53%) create mode 100644 c/lib/err.h rename {cyac => c}/lib/frombe.c (97%) create mode 100644 c/lib/frombe.h rename {cyac => c}/lib/h-extract.pl (100%) create mode 100644 c/lib/install.do rename {cyac => c}/lib/items.c (64%) rename {cyac => c}/lib/items.h (58%) rename {cyac => c}/lib/iter.c (66%) rename {cyac => c}/lib/iter.h (60%) rename {cyac => c}/lib/leapsecs.c (92%) create mode 100644 c/lib/leapsecs.h rename cyac/lib/libyac.a.do => c/lib/libkeks.a.do (100%) rename {cyac => c}/lib/o.list (100%) create mode 100644 c/lib/pki/.gitignore rename {cyac => c}/lib/pki/cer.c (59%) rename {cyac => c}/lib/pki/cer.h (67%) rename {cyac => c}/lib/pki/clean (100%) create mode 100644 c/lib/pki/install.do rename cyac/lib/pki/libyacpki.a.do => c/lib/pki/libkekspki.a.do (100%) rename {cyac => c}/lib/pki/o.list (100%) rename {cyac => c}/lib/tobe.c (97%) create mode 100644 c/lib/tobe.h rename {cyac => c}/lib/utf8.c (88%) create mode 100644 c/lib/utf8.h rename {cyac => c}/lint/.clang-format (100%) rename {cyac => c}/lint/iwyu-maps.imp (100%) delete mode 100644 cyac/README delete mode 100644 cyac/cmd/lib/printai.h delete mode 100644 cyac/cmd/lib/uuid.h delete mode 100644 cyac/cmd/test-vector/test-vector.c delete mode 100644 cyac/doc/atom.texi delete mode 100644 cyac/doc/items.texi delete mode 100644 cyac/doc/pki.texi delete mode 100644 cyac/doc/tai64.texi delete mode 100644 cyac/lib/atoms.h delete mode 100644 cyac/lib/dectai.h delete mode 100644 cyac/lib/err.h delete mode 100644 cyac/lib/frombe.h delete mode 100644 cyac/lib/install.do delete mode 100644 cyac/lib/leapsecs.h delete mode 100644 cyac/lib/pki/.gitignore delete mode 100644 cyac/lib/pki/install.do delete mode 100644 cyac/lib/tobe.h delete mode 100644 cyac/lib/utf8.h rename {gyac => go}/COPYING (100%) rename {gyac => go}/COPYING.LESSER (100%) rename {gyac => go}/README (54%) rename {gyac => go}/atom/be/be.go (98%) rename {gyac => go}/atom/dec.go (96%) rename {gyac => go}/atom/enc.go (98%) rename {gyac => go}/atom/raw.go (96%) rename {gyac => go}/atom/type_string.go (100%) rename {gyac => go}/blob.go (94%) rename {gyac => go}/cmd/print/main.go (70%) rename {gyac => go}/cmd/test-vector-anys/main.go (89%) rename {gyac => go}/cmd/test-vector-manual/main.go (99%) rename {gyac => go}/dec.go (96%) create mode 100644 go/doc.go rename {gyac => go}/enc.go (96%) rename {gyac => go}/fromgo.go (97%) rename {gyac => go}/fuzz_test.go (97%) rename {gyac => go}/go.mod (80%) rename {gyac => go}/go.sum (100%) rename {gyac => go}/mapstruct/dec.go (83%) rename {gyac => go}/mapstruct/map.go (93%) rename {gyac => go}/mk-fuzz-testdata (91%) rename {gyac => go}/pki/algo.go (63%) rename {gyac => go}/pki/av.go (83%) rename {gyac => go}/pki/cer.go (90%) rename {gyac/pki/cmd/yacertool => go/pki/cmd/kekscertool}/basic.t (72%) rename {gyac/pki/cmd/yacertool => go/pki/cmd/kekscertool}/main.go (92%) rename {gyac/pki/cmd/yacsdtool => go/pki/cmd/kekssdtool}/main.go (92%) create mode 100644 go/pki/doc.go rename {gyac => go}/pki/ed25519-blake2b/.gitignore (100%) rename {gyac => go}/pki/ed25519-blake2b/algo.go (100%) rename {gyac => go}/pki/ed25519-blake2b/clean (100%) rename {gyac => go}/pki/ed25519-blake2b/ed25519-to-blake2b.patch (98%) rename {gyac => go}/pki/ed25519-blake2b/kp.go (85%) rename {gyac => go}/pki/ed25519-blake2b/mk-from-go (92%) rename {gyac => go}/pki/ed25519-blake2b/prv.go (83%) rename {gyac => go}/pki/ed25519-blake2b/verify.go (83%) rename {gyac => go}/pki/go.mod (78%) rename {gyac => go}/pki/go.sum (100%) rename {gyac => go}/pki/gost/gost.go (100%) rename {gyac => go}/pki/gost/kp.go (100%) rename {gyac => go}/pki/gost/signer.go (100%) rename {gyac => go}/pki/gost/verify.go (94%) rename {gyac => go}/pki/hash/algo.go (100%) rename {gyac => go}/pki/prv.go (73%) rename {gyac => go}/pki/signed-data.go (72%) rename {gyac => go}/pki/utils/utils.go (100%) rename {gyac => go}/sort.go (96%) rename {gyac => go}/togo.go (95%) rename {gyac => go}/types/type.go (100%) rename {gyac => go}/types/type_string.go (100%) delete mode 100644 gyac/doc.go delete mode 100644 gyac/pki/doc.go rename {pyac => py3}/.gitignore (100%) rename {pyac => py3}/COPYING (100%) rename {pyac => py3}/COPYING.LESSER (100%) create mode 100644 py3/README rename pyac/pyac.py => py3/keks.py (94%) rename {pyac => py3}/test-vector.py (81%) rename {pyac => py3}/tests/.gitignore (100%) rename {pyac => py3}/tests/__init__.py (100%) rename {pyac => py3}/tests/fuzz.py (77%) rename {pyac => py3}/tests/requirements.txt (100%) rename {pyac => py3}/tests/strategies.py (96%) rename {pyac => py3}/tests/test_blob.py (96%) rename {pyac => py3}/tests/test_bool.py (94%) rename {pyac => py3}/tests/test_everything.py (93%) rename {pyac => py3}/tests/test_float.py (95%) rename {pyac => py3}/tests/test_fuzz_inputs.py (91%) rename {pyac => py3}/tests/test_generic.py (92%) rename {pyac => py3}/tests/test_int.py (97%) rename {pyac => py3}/tests/test_list.py (94%) rename {pyac => py3}/tests/test_map.py (97%) rename {pyac => py3}/tests/test_not_enough_data.py (95%) rename {pyac => py3}/tests/test_recursion.py (88%) rename {pyac => py3}/tests/test_str.py (98%) rename {pyac => py3}/tests/test_tai.py (96%) rename {pyac => py3}/tests/test_uuid.py (94%) delete mode 100644 pyac/README rename {tyac => tcl}/COPYING (100%) rename {tyac => tcl}/COPYING.LESSER (100%) create mode 100644 tcl/README create mode 100755 tcl/args rename tyac/tyac.tcl => tcl/keks.tcl (98%) rename {tyac => tcl}/mk-fuzz-inputs (100%) rename {tyac => tcl}/test-vector.tcl (97%) delete mode 100644 tyac/README delete mode 100755 tyac/args diff --git a/README b/README index fbaf228..db1e42f 100644 --- a/README +++ b/README @@ -1,3 +1,4 @@ -Yet Another Codec. -Yet another format for binary reprensentation of structured data. -Its implementations are not heavily tested, project was just created. +KEKS is compact, deterministic, concise and streaming binary +serialisation format. It is aimed to be lightweight in terms of CPU, +memory, storage and codec implementation size usage. It supports wide +range of data types, making it able to transparently replace JSON. diff --git a/cyac/.clang-tidy b/c/.clang-tidy similarity index 100% rename from cyac/.clang-tidy rename to c/.clang-tidy diff --git a/cyac/.gitignore b/c/.gitignore similarity index 100% rename from cyac/.gitignore rename to c/.gitignore diff --git a/cyac/COPYING b/c/COPYING similarity index 100% rename from cyac/COPYING rename to c/COPYING diff --git a/cyac/COPYING.LESSER b/c/COPYING.LESSER similarity index 100% rename from cyac/COPYING.LESSER rename to c/COPYING.LESSER diff --git a/c/README b/c/README new file mode 100644 index 0000000..78f8a0a --- /dev/null +++ b/c/README @@ -0,0 +1,2 @@ +ckeks is C99 implementation of the KEKS codec. +Look at doc/ for more information. diff --git a/cyac/clean b/c/clean similarity index 100% rename from cyac/clean rename to c/clean diff --git a/cyac/cmd/cer-verify/.gitignore b/c/cmd/cer-verify/.gitignore similarity index 100% rename from cyac/cmd/cer-verify/.gitignore rename to c/cmd/cer-verify/.gitignore diff --git a/cyac/cmd/cer-verify/all.do b/c/cmd/cer-verify/all.do similarity index 100% rename from cyac/cmd/cer-verify/all.do rename to c/cmd/cer-verify/all.do diff --git a/cyac/cmd/cer-verify/cer-verify.c b/c/cmd/cer-verify/cer-verify.c similarity index 78% rename from cyac/cmd/cer-verify/cer-verify.c rename to c/cmd/cer-verify/cer-verify.c index 22bf26e..bb3f6ce 100644 --- a/cyac/cmd/cer-verify/cer-verify.c +++ b/c/cmd/cer-verify/cer-verify.c @@ -1,4 +1,4 @@ -// cyac -- C YAC encoder implementation +// ckeks -- C KEKS encoder implementation // Copyright (C) 2024-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify @@ -20,9 +20,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include "../lib/mmap.h" #include "../lib/uuid.h" @@ -38,7 +38,7 @@ main(int argc, char **argv) return EXIT_FAILURE; } const size_t cersLen = (size_t)argc - 1; - struct YACCer *cers = calloc(cersLen, sizeof(struct YACCer)); + struct KEKSCer *cers = calloc(cersLen, sizeof(struct KEKSCer)); assert(cers != NULL); char *failReason = NULL; for (int i = 1; i < argc; i++) { @@ -51,8 +51,8 @@ main(int argc, char **argv) fputs(argv[i], stdout); fputs(":\t", stdout); size_t off = 0; - enum YACErr err = YACCerParse(&(cers[i - 1]), &off, &failReason, buf, len); - if (err != YACErrNo) { + enum KEKSErr err = KEKSCerParse(&(cers[i - 1]), &off, &failReason, buf, len); + if (err != KEKSErrNo) { fprintf(stderr, "%s: %s\n", argv[i], failReason); return EXIT_FAILURE; } @@ -72,21 +72,21 @@ main(int argc, char **argv) return EXIT_FAILURE; } - struct YACCerSigVerifier sigVerifiers[] = { + struct KEKSCerSigVerifier sigVerifiers[] = { {.algo = "ed25519-blake2b", .func = ed25519blake2bSignatureVerifier}, {.algo = "gost3410-256A", .func = gost3410SignatureVerifier}, {.algo = "gost3410-512C", .func = gost3410SignatureVerifier}, {.algo = NULL}, }; - struct YACCerVerifyOpts opts = {.t = now, .sigVerifiers = sigVerifiers}; + struct KEKSCerVerifyOpts opts = {.t = now, .sigVerifiers = sigVerifiers}; - struct YACCer *toVerify = &(cers[0]); - struct YACCer *verifier = NULL; + struct KEKSCer *toVerify = &(cers[0]); + struct KEKSCer *verifier = NULL; for (;;) { fputs("verifying ", stdout); UUIDPrint(toVerify->cid); fputs(": ", stdout); - if (!YACCerVerify(&failReason, &verifier, toVerify, cers, cersLen, opts)) { + if (!KEKSCerVerify(&failReason, &verifier, toVerify, cers, cersLen, opts)) { fputs(failReason, stdout); fputs("\n", stdout); return EXIT_FAILURE; @@ -96,8 +96,8 @@ main(int argc, char **argv) break; } { - size_t ku = YACItemsGetByKey(&(verifier->items), verifier->load, "ku"); - if ((ku == 0) || YACItemsGetByKey(&(verifier->items), ku, "ca") == 0) { + size_t ku = KEKSItemsGetByKey(&(verifier->items), verifier->load, "ku"); + if ((ku == 0) || KEKSItemsGetByKey(&(verifier->items), ku, "ca") == 0) { fputs("no ca ku\n", stdout); return EXIT_FAILURE; } diff --git a/cyac/cmd/cer-verify/cer-verify.do b/c/cmd/cer-verify/cer-verify.do similarity index 89% rename from cyac/cmd/cer-verify/cer-verify.do rename to c/cmd/cer-verify/cer-verify.do index 8f431f1..e42594d 100644 --- a/cyac/cmd/cer-verify/cer-verify.do +++ b/c/cmd/cer-verify/cer-verify.do @@ -11,4 +11,4 @@ $CC \ $CFLAGS -I$PREFIX/include \ -o $3 $2.c $deps \ $LDFLAGS $GCL3_LDFLAGS $MONOCYPHER_LDFLAGS -L$PREFIX/lib \ - -lyac -lyacpki $GCL3_LDLIBS $MONOCYPHER_LDLIBS -static + -lkeks -lkekspki $GCL3_LDLIBS $MONOCYPHER_LDLIBS -static diff --git a/cyac/cmd/cer-verify/clean b/c/cmd/cer-verify/clean similarity index 100% rename from cyac/cmd/cer-verify/clean rename to c/cmd/cer-verify/clean diff --git a/cyac/cmd/cer-verify/compile_flags.txt.do b/c/cmd/cer-verify/compile_flags.txt.do similarity index 100% rename from cyac/cmd/cer-verify/compile_flags.txt.do rename to c/cmd/cer-verify/compile_flags.txt.do diff --git a/cyac/cmd/cer-verify/conf/.gitignore b/c/cmd/cer-verify/conf/.gitignore similarity index 100% rename from cyac/cmd/cer-verify/conf/.gitignore rename to c/cmd/cer-verify/conf/.gitignore diff --git a/cyac/cmd/cer-verify/conf/gcl3.rc.do b/c/cmd/cer-verify/conf/gcl3.rc.do similarity index 100% rename from cyac/cmd/cer-verify/conf/gcl3.rc.do rename to c/cmd/cer-verify/conf/gcl3.rc.do diff --git a/cyac/cmd/cer-verify/conf/monocypher.rc.do b/c/cmd/cer-verify/conf/monocypher.rc.do similarity index 100% rename from cyac/cmd/cer-verify/conf/monocypher.rc.do rename to c/cmd/cer-verify/conf/monocypher.rc.do diff --git a/cyac/cmd/cer-verify/curves.c.in b/c/cmd/cer-verify/curves.c.in similarity index 100% rename from cyac/cmd/cer-verify/curves.c.in rename to c/cmd/cer-verify/curves.c.in diff --git a/cyac/cmd/cer-verify/verifier-ed25519-blake2b.c b/c/cmd/cer-verify/verifier-ed25519-blake2b.c similarity index 100% rename from cyac/cmd/cer-verify/verifier-ed25519-blake2b.c rename to c/cmd/cer-verify/verifier-ed25519-blake2b.c diff --git a/cyac/cmd/cer-verify/verifier-ed25519-blake2b.h b/c/cmd/cer-verify/verifier-ed25519-blake2b.h similarity index 72% rename from cyac/cmd/cer-verify/verifier-ed25519-blake2b.h rename to c/cmd/cer-verify/verifier-ed25519-blake2b.h index 4050260..eeaa6da 100644 --- a/cyac/cmd/cer-verify/verifier-ed25519-blake2b.h +++ b/c/cmd/cer-verify/verifier-ed25519-blake2b.h @@ -1,5 +1,5 @@ -#ifndef YAC_VERIFIER_ED25519_BLAKE2B_H -#define YAC_VERIFIER_ED25519_BLAKE2B_H +#ifndef KEKS_VERIFIER_ED25519_BLAKE2B_H +#define KEKS_VERIFIER_ED25519_BLAKE2B_H #include #include @@ -16,4 +16,4 @@ ed25519blake2bSignatureVerifier( const unsigned char *data, const size_t dataLen); -#endif // YAC_VERIFIER_ED25519_BLAKE2B_H +#endif // KEKS_VERIFIER_ED25519_BLAKE2B_H diff --git a/cyac/cmd/cer-verify/verifier-ed25519-blake2b.o.do b/c/cmd/cer-verify/verifier-ed25519-blake2b.o.do similarity index 100% rename from cyac/cmd/cer-verify/verifier-ed25519-blake2b.o.do rename to c/cmd/cer-verify/verifier-ed25519-blake2b.o.do diff --git a/cyac/cmd/cer-verify/verifier-gost3410.c b/c/cmd/cer-verify/verifier-gost3410.c similarity index 100% rename from cyac/cmd/cer-verify/verifier-gost3410.c rename to c/cmd/cer-verify/verifier-gost3410.c diff --git a/cyac/cmd/cer-verify/verifier-gost3410.h b/c/cmd/cer-verify/verifier-gost3410.h similarity index 76% rename from cyac/cmd/cer-verify/verifier-gost3410.h rename to c/cmd/cer-verify/verifier-gost3410.h index af6ddd6..17be3d5 100644 --- a/cyac/cmd/cer-verify/verifier-gost3410.h +++ b/c/cmd/cer-verify/verifier-gost3410.h @@ -1,5 +1,5 @@ -#ifndef YAC_VERIFIER_GOST3410_H -#define YAC_VERIFIER_GOST3410_H +#ifndef KEKS_VERIFIER_GOST3410_H +#define KEKS_VERIFIER_GOST3410_H #include #include @@ -16,4 +16,4 @@ gost3410SignatureVerifier( const unsigned char *data, const size_t dataLen); -#endif // YAC_VERIFIER_GOST3410_H +#endif // KEKS_VERIFIER_GOST3410_H diff --git a/cyac/cmd/cer-verify/verifier-gost3410.o.do b/c/cmd/cer-verify/verifier-gost3410.o.do similarity index 100% rename from cyac/cmd/cer-verify/verifier-gost3410.o.do rename to c/cmd/cer-verify/verifier-gost3410.o.do diff --git a/cyac/cmd/clean b/c/cmd/clean similarity index 100% rename from cyac/cmd/clean rename to c/cmd/clean diff --git a/cyac/cmd/for-fuzz/.gitignore b/c/cmd/for-fuzz/.gitignore similarity index 100% rename from cyac/cmd/for-fuzz/.gitignore rename to c/cmd/for-fuzz/.gitignore diff --git a/cyac/cmd/for-fuzz/all.do b/c/cmd/for-fuzz/all.do similarity index 100% rename from cyac/cmd/for-fuzz/all.do rename to c/cmd/for-fuzz/all.do diff --git a/cyac/cmd/for-fuzz/clean b/c/cmd/for-fuzz/clean similarity index 100% rename from cyac/cmd/for-fuzz/clean rename to c/cmd/for-fuzz/clean diff --git a/cyac/cmd/for-fuzz/for-fuzz.c b/c/cmd/for-fuzz/for-fuzz.c similarity index 69% rename from cyac/cmd/for-fuzz/for-fuzz.c rename to c/cmd/for-fuzz/for-fuzz.c index bf366c0..530cc26 100644 --- a/cyac/cmd/for-fuzz/for-fuzz.c +++ b/c/cmd/for-fuzz/for-fuzz.c @@ -3,8 +3,8 @@ #include #include -#include -#include +#include +#include #include "../lib/mmap.h" @@ -17,14 +17,14 @@ main(int argc, char **argv) if (!Mmap(&buf, &len, argv[1])) { exit(EXIT_FAILURE); } - struct YACItems items; - enum YACErr err = YACItemsInit(&items); - if (err != YACErrNo) { + struct KEKSItems items; + enum KEKSErr err = KEKSItemsInit(&items); + if (err != KEKSErrNo) { return EXIT_FAILURE; } size_t off = 0; - err = YACItemsParse(&items, &off, buf, len); - if (err != YACErrNo) { + err = KEKSItemsParse(&items, &off, buf, len); + if (err != KEKSErrNo) { return EXIT_SUCCESS; } { @@ -32,7 +32,7 @@ main(int argc, char **argv) unsigned char *dst = malloc(len); assert(dst != NULL); off = 0; - assert(YACItemsEncode(&items, 0, &off, dst, len)); + assert(KEKSItemsEncode(&items, 0, &off, dst, len)); assert(off == len - tailLen); assert(memcmp(dst, buf, len - tailLen) == 0); } diff --git a/cyac/cmd/for-fuzz/for-fuzz.do b/c/cmd/for-fuzz/for-fuzz.do similarity index 92% rename from cyac/cmd/for-fuzz/for-fuzz.do rename to c/cmd/for-fuzz/for-fuzz.do index ce78095..fc038d4 100644 --- a/cyac/cmd/for-fuzz/for-fuzz.do +++ b/c/cmd/for-fuzz/for-fuzz.do @@ -5,4 +5,4 @@ read CC <../../conf/cc CFLAGS=$(cat ../../conf/cflags) LDFLAGS=$(cat ../../conf/ldflags) read PREFIX <../../conf/prefix -$CC $CFLAGS -I$PREFIX/include -o $3 $2.c $deps $LDFLAGS -L$PREFIX/lib -lyac -lm -static +$CC $CFLAGS -I$PREFIX/include -o $3 $2.c $deps $LDFLAGS -L$PREFIX/lib -lkeks -lm -static diff --git a/cyac/cmd/lib/clean b/c/cmd/lib/clean similarity index 100% rename from cyac/cmd/lib/clean rename to c/cmd/lib/clean diff --git a/cyac/cmd/lib/default.o.do b/c/cmd/lib/default.o.do similarity index 100% rename from cyac/cmd/lib/default.o.do rename to c/cmd/lib/default.o.do diff --git a/cyac/cmd/lib/hex.c b/c/cmd/lib/hex.c similarity index 100% rename from cyac/cmd/lib/hex.c rename to c/cmd/lib/hex.c diff --git a/cyac/cmd/lib/hex.h b/c/cmd/lib/hex.h similarity index 59% rename from cyac/cmd/lib/hex.h rename to c/cmd/lib/hex.h index a5f956a..9d7729f 100644 --- a/cyac/cmd/lib/hex.h +++ b/c/cmd/lib/hex.h @@ -1,9 +1,9 @@ -#ifndef YAC_HEX_H -#define YAC_HEX_H +#ifndef KEKS_HEX_H +#define KEKS_HEX_H #include char * HexEnc(const unsigned char *src, const size_t srcLen); -#endif // YAC_HEX_H +#endif // KEKS_HEX_H diff --git a/cyac/cmd/lib/mmap.c b/c/cmd/lib/mmap.c similarity index 100% rename from cyac/cmd/lib/mmap.c rename to c/cmd/lib/mmap.c diff --git a/cyac/cmd/lib/mmap.h b/c/cmd/lib/mmap.h similarity index 63% rename from cyac/cmd/lib/mmap.h rename to c/cmd/lib/mmap.h index e5416b8..456b604 100644 --- a/cyac/cmd/lib/mmap.h +++ b/c/cmd/lib/mmap.h @@ -1,5 +1,5 @@ -#ifndef YAC_MMAP_H -#define YAC_MMAP_H +#ifndef KEKS_MMAP_H +#define KEKS_MMAP_H #include #include @@ -7,4 +7,4 @@ bool Mmap(unsigned char **buf, size_t *len, const char *path); -#endif // YAC_MMAP_H +#endif // KEKS_MMAP_H diff --git a/cyac/cmd/lib/printai.c b/c/cmd/lib/printai.c similarity index 80% rename from cyac/cmd/lib/printai.c rename to c/cmd/lib/printai.c index f8ae884..7d6ef8a 100644 --- a/cyac/cmd/lib/printai.c +++ b/c/cmd/lib/printai.c @@ -3,13 +3,13 @@ #include #include -#include -#include +#include +#include #include "hex.h" #include "printai.h" -enum YACErr +enum KEKSErr PrintTAI64(const unsigned char *buf, const size_t len) { char *hex = NULL; @@ -17,7 +17,7 @@ PrintTAI64(const unsigned char *buf, const size_t len) hex = HexEnc(buf, len); fprintf(stdout, "TAI64NA(%s)\n", hex); free(hex); - return YACErrNo; + return KEKSErrNo; } switch (len) { case 8: @@ -30,33 +30,33 @@ PrintTAI64(const unsigned char *buf, const size_t len) break; } struct timespec tv; - enum YACErr err = YACTAI64ToTimespec(&tv, buf, len); + enum KEKSErr err = KEKSTAI64ToTimespec(&tv, buf, len); #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wswitch-enum" switch (err) { #pragma clang diagnostic pop - case YACErrNo: + case KEKSErrNo: break; - case YACErrTAI64InPast: + case KEKSErrTAI64InPast: hex = HexEnc(buf, len); fprintf(stdout, "in past: %s)\n", hex); free(hex); - return YACErrNo; + return KEKSErrNo; default: return err; } - err = YACTimespecToUTC(&tv); + err = KEKSTimespecToUTC(&tv); #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wswitch-enum" switch (err) { #pragma clang diagnostic pop - case YACErrNo: + case KEKSErrNo: break; - case YACErrTAI64InPast: + case KEKSErrTAI64InPast: hex = HexEnc(buf, len); fprintf(stdout, "in past: %s)\n", hex); free(hex); - return YACErrNo; + return KEKSErrNo; default: return err; } @@ -66,7 +66,7 @@ PrintTAI64(const unsigned char *buf, const size_t len) hex = HexEnc(buf, len); fprintf(stdout, "unrepresentable: %s)\n", hex); free(hex); - return YACErrNo; + return KEKSErrNo; } { char human[20] = {0}; @@ -77,5 +77,5 @@ PrintTAI64(const unsigned char *buf, const size_t len) fprintf(stdout, ".%09zu", tv.tv_nsec); } fputs(")\n", stdout); - return YACErrNo; + return KEKSErrNo; } diff --git a/c/cmd/lib/printai.h b/c/cmd/lib/printai.h new file mode 100644 index 0000000..f6da8e9 --- /dev/null +++ b/c/cmd/lib/printai.h @@ -0,0 +1,11 @@ +#ifndef KEKS_PRINTAI_H +#define KEKS_PRINTAI_H + +#include + +#include + +enum KEKSErr +PrintTAI64(const unsigned char *buf, const size_t len); + +#endif // KEKS_PRINTAI_H diff --git a/cyac/cmd/lib/printai.o.do b/c/cmd/lib/printai.o.do similarity index 100% rename from cyac/cmd/lib/printai.o.do rename to c/cmd/lib/printai.o.do diff --git a/cyac/cmd/lib/uuid.c b/c/cmd/lib/uuid.c similarity index 100% rename from cyac/cmd/lib/uuid.c rename to c/cmd/lib/uuid.c diff --git a/c/cmd/lib/uuid.h b/c/cmd/lib/uuid.h new file mode 100644 index 0000000..c64693a --- /dev/null +++ b/c/cmd/lib/uuid.h @@ -0,0 +1,7 @@ +#ifndef KEKS_UUID_H +#define KEKS_UUID_H + +void +UUIDPrint(const unsigned char *buf); + +#endif // KEKS_UUID_H diff --git a/cyac/cmd/print-items/.gitignore b/c/cmd/print-items/.gitignore similarity index 100% rename from cyac/cmd/print-items/.gitignore rename to c/cmd/print-items/.gitignore diff --git a/cyac/cmd/print-items/all.do b/c/cmd/print-items/all.do similarity index 100% rename from cyac/cmd/print-items/all.do rename to c/cmd/print-items/all.do diff --git a/cyac/cmd/print-items/clean b/c/cmd/print-items/clean similarity index 100% rename from cyac/cmd/print-items/clean rename to c/cmd/print-items/clean diff --git a/cyac/cmd/print-items/print-items.c b/c/cmd/print-items/print-items.c similarity index 87% rename from cyac/cmd/print-items/print-items.c rename to c/cmd/print-items/print-items.c index 3b5546c..9d6eaa6 100644 --- a/cyac/cmd/print-items/print-items.c +++ b/c/cmd/print-items/print-items.c @@ -1,4 +1,4 @@ -// cyac -- C YAC encoder implementation +// ckeks -- C KEKS encoder implementation // Copyright (C) 2024-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify @@ -23,9 +23,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include "../lib/hex.h" #include "../lib/mmap.h" @@ -69,9 +69,9 @@ usage(void) exit(EXIT_FAILURE); } -static enum YACErr +static enum KEKSErr printer( // NOLINT(misc-no-recursion) - const struct YACItems *items, + const struct KEKSItems *items, size_t idx, size_t indent, const bool inList, @@ -94,7 +94,7 @@ printer( // NOLINT(misc-no-recursion) items->offsets[idx], NoColour ? "" : ColourReset); } - struct YACItem *item = &(items->list[idx]); + struct KEKSItem *item = &(items->list[idx]); printIndent(indent); if (inList) { fprintf( @@ -113,31 +113,31 @@ printer( // NOLINT(misc-no-recursion) NoColour ? "" : ColourReset); } char *str = NULL; - enum YACErr err = YACErrInvalid; + enum KEKSErr err = KEKSErrInvalid; switch (item->atom.typ) { - case YACItemInvalid: + case KEKSItemInvalid: fputs("INVALID\n", stdout); break; - case YACItemNIL: + case KEKSItemNIL: fputs("NIL\n", stdout); break; - case YACItemFalse: + case KEKSItemFalse: fputs("FALSE\n", stdout); break; - case YACItemTrue: + case KEKSItemTrue: fputs("TRUE\n", stdout); break; - case YACItemUUID: + case KEKSItemUUID: UUIDPrint(item->atom.v.uuid); fputs("\n", stdout); break; - case YACItemPint: + case KEKSItemPint: fprintf(stdout, "%zu\n", item->atom.v.pint); break; - case YACItemNint: + case KEKSItemNint: fprintf(stdout, "%zd\n", item->atom.v.nint); break; - case YACItemList: { + case KEKSItemList: { fprintf( stdout, "[ %s%zd%s\n", @@ -149,7 +149,7 @@ printer( // NOLINT(misc-no-recursion) listIdx = 0; while (idx != 0) { err = printer(items, idx, indent, true, listIdx, NULL); - if (err != YACErrNo) { + if (err != KEKSErrNo) { return err; } idx = items->list[idx].next; @@ -163,7 +163,7 @@ printer( // NOLINT(misc-no-recursion) fputs("]\n", stdout); break; } - case YACItemMap: { + case KEKSItemMap: { fprintf( stdout, "{ %s%zd%s\n", @@ -179,7 +179,7 @@ printer( // NOLINT(misc-no-recursion) idx = items->list[idx].next; err = printer(items, idx, indent, false, 0, str); free(str); - if (err != YACErrNo) { + if (err != KEKSErrNo) { return err; } idx = items->list[idx].next; @@ -192,7 +192,7 @@ printer( // NOLINT(misc-no-recursion) fputs("}\n", stdout); break; } - case YACItemBlob: + case KEKSItemBlob: fprintf( stdout, "BLOB[ %s%zu l=%zu%s\n", @@ -205,7 +205,7 @@ printer( // NOLINT(misc-no-recursion) listIdx = 0; while (idx != 0) { err = printer(items, idx, indent, true, listIdx, NULL); - if (err != YACErrNo) { + if (err != KEKSErrNo) { return err; } idx = items->list[idx].next; @@ -218,17 +218,17 @@ printer( // NOLINT(misc-no-recursion) printIndent(indent); fputs("]\n", stdout); break; - case YACItemFloat: + case KEKSItemFloat: fputs("FLOAT: TODO\n", stdout); break; - case YACItemTAI64: { + case KEKSItemTAI64: { err = PrintTAI64(item->atom.v.str.ptr, item->atom.v.str.len); - if (err != YACErrNo) { + if (err != KEKSErrNo) { return err; } break; } - case YACItemBin: { + case KEKSItemBin: { const size_t l = (item->atom.v.str.len > MaxStrLen) ? MaxStrLen : item->atom.v.str.len; str = HexEnc(item->atom.v.str.ptr, l); @@ -243,7 +243,7 @@ printer( // NOLINT(misc-no-recursion) free(str); break; } - case YACItemStr: { + case KEKSItemStr: { const size_t l = (item->atom.v.str.len > MaxStrLen) ? MaxStrLen : item->atom.v.str.len; str = strndup((const char *)item->atom.v.str.ptr, l); @@ -252,18 +252,18 @@ printer( // NOLINT(misc-no-recursion) free(str); break; } - case YACItemRaw: + case KEKSItemRaw: str = HexEnc(item->atom.v.str.ptr, item->atom.v.str.len); fprintf( stdout, "(t=0x%X l=%zu v=%s)\n", item->atom.tag, item->atom.v.str.len, str); free(str); break; - case YACItemEOC: + case KEKSItemEOC: default: fprintf(stderr, "unknown atom\n"); return EXIT_FAILURE; } - return YACErrNo; + return KEKSErrNo; } int @@ -327,10 +327,10 @@ main(int argc, char **argv) OffDigits = NoOffsets ? -1 : (int)(1 + floor(log10((double)len))); snprintf(OffFmt, sizeof OffFmt, "%%s%%0%dzd%%s ", OffDigits); - struct YACItems items; - enum YACErr err = YACItemsInit(&items); - if (err != YACErrNo) { - fprintf(stderr, "err: %s\n", YACErr2Str(err)); + struct KEKSItems items; + enum KEKSErr err = KEKSItemsInit(&items); + if (err != KEKSErrNo) { + fprintf(stderr, "err: %s\n", KEKSErr2Str(err)); return EXIT_FAILURE; } if (NoOffsets) { @@ -338,21 +338,21 @@ main(int argc, char **argv) items.offsets = NULL; } size_t off = 0; - err = YACItemsParse(&items, &off, buf, len); - if (err != YACErrNo) { - fprintf(stderr, "err: %s\n", YACErr2Str(err)); + err = KEKSItemsParse(&items, &off, buf, len); + if (err != KEKSErrNo) { + fprintf(stderr, "err: %s\n", KEKSErr2Str(err)); return EXIT_FAILURE; } err = printer(&items, 0, 0, false, 0, NULL); - if (err != YACErrNo) { - fprintf(stderr, "err: %s\n", YACErr2Str(err)); + if (err != KEKSErrNo) { + fprintf(stderr, "err: %s\n", KEKSErr2Str(err)); return EXIT_FAILURE; } if (!noTotals) { printf( "items: %zu size: %zu\n", items.len, - items.len * (sizeof(struct YACItem) + (NoOffsets ? 0 : sizeof(size_t)))); + items.len * (sizeof(struct KEKSItem) + (NoOffsets ? 0 : sizeof(size_t)))); } if (off < len) { char *hex = HexEnc(buf + off, len - off); @@ -364,7 +364,7 @@ main(int argc, char **argv) assert(dst != NULL); size_t lenExpected = off; off = 0; - assert(YACItemsEncode(&items, 0, &off, dst, len)); + assert(KEKSItemsEncode(&items, 0, &off, dst, len)); assert(off == lenExpected); assert(memcmp(dst, buf, lenExpected) == 0); } diff --git a/cyac/cmd/print-items/print-items.do b/c/cmd/print-items/print-items.do similarity index 95% rename from cyac/cmd/print-items/print-items.do rename to c/cmd/print-items/print-items.do index 7a01e52..41150c2 100644 --- a/cyac/cmd/print-items/print-items.do +++ b/c/cmd/print-items/print-items.do @@ -5,4 +5,4 @@ read CC <../../conf/cc CFLAGS=$(cat ../../conf/cflags) LDFLAGS=$(cat ../../conf/ldflags) read PREFIX <../../conf/prefix -$CC $CFLAGS -I$PREFIX/include -o $3 $2.c $deps $LDFLAGS -L$PREFIX/lib -lyac -lm +$CC $CFLAGS -I$PREFIX/include -o $3 $2.c $deps $LDFLAGS -L$PREFIX/lib -lkeks -lm diff --git a/cyac/cmd/print-itered/.gitignore b/c/cmd/print-itered/.gitignore similarity index 100% rename from cyac/cmd/print-itered/.gitignore rename to c/cmd/print-itered/.gitignore diff --git a/cyac/cmd/print-itered/all.do b/c/cmd/print-itered/all.do similarity index 100% rename from cyac/cmd/print-itered/all.do rename to c/cmd/print-itered/all.do diff --git a/cyac/cmd/print-itered/clean b/c/cmd/print-itered/clean similarity index 100% rename from cyac/cmd/print-itered/clean rename to c/cmd/print-itered/clean diff --git a/cyac/cmd/print-itered/print-itered.c b/c/cmd/print-itered/print-itered.c similarity index 76% rename from cyac/cmd/print-itered/print-itered.c rename to c/cmd/print-itered/print-itered.c index 13ac0fa..1cc13ac 100644 --- a/cyac/cmd/print-itered/print-itered.c +++ b/c/cmd/print-itered/print-itered.c @@ -1,4 +1,4 @@ -// cyac -- C YAC encoder implementation +// ckeks -- C KEKS encoder implementation // Copyright (C) 2024-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify @@ -19,9 +19,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include "../lib/hex.h" #include "../lib/mmap.h" @@ -34,20 +34,20 @@ struct CbState { int indent; }; -static enum YACErr +static enum KEKSErr myCb( const unsigned char *key, const size_t keyLen, const bool inList, const size_t idx, void *cbState, - struct YACAtom *atom, + struct KEKSAtom *atom, size_t *off, const unsigned char *buf, const size_t len) { struct CbState *state = (struct CbState *)(cbState); - if ((atom->typ) == YACItemEOC) { + if ((atom->typ) == KEKSItemEOC) { state->indent--; assert(state->indent >= 0); } @@ -63,69 +63,69 @@ myCb( } char *hex = NULL; - enum YACErr err = YACErrInvalid; + enum KEKSErr err = KEKSErrInvalid; switch (atom->typ) { - case YACItemInvalid: + case KEKSItemInvalid: fputs("INVALID\n", stdout); break; - case YACItemEOC: + case KEKSItemEOC: break; - case YACItemNIL: + case KEKSItemNIL: fputs("NIL\n", stdout); break; - case YACItemFalse: + case KEKSItemFalse: fputs("FALSE\n", stdout); break; - case YACItemTrue: + case KEKSItemTrue: fputs("TRUE\n", stdout); break; - case YACItemUUID: + case KEKSItemUUID: UUIDPrint(atom->v.uuid); fputs("\n", stdout); break; - case YACItemPint: + case KEKSItemPint: fprintf(stdout, "%zu\n", atom->v.pint); break; - case YACItemNint: + case KEKSItemNint: fprintf(stdout, "%zd\n", atom->v.nint); break; - case YACItemList: + case KEKSItemList: fputs("[\n", stdout); state->indent++; - err = YACIterList(cbState, atom, off, buf, len, myCb); - if (err != YACErrNo) { + err = KEKSIterList(cbState, atom, off, buf, len, myCb); + if (err != KEKSErrNo) { return err; } fputs("]\n", stdout); break; - case YACItemMap: + case KEKSItemMap: fputs("{\n", stdout); state->indent++; - err = YACIterMap(cbState, atom, off, buf, len, myCb); - if (err != YACErrNo) { + err = KEKSIterMap(cbState, atom, off, buf, len, myCb); + if (err != KEKSErrNo) { return err; } fputs("}\n", stdout); break; - case YACItemBlob: + case KEKSItemBlob: printf("BLOB(l=%zu\n", atom->v.blob.chunkLen); state->indent++; - err = YACIterBlob(cbState, atom, off, buf, len, myCb); - if (err != YACErrNo) { + err = KEKSIterBlob(cbState, atom, off, buf, len, myCb); + if (err != KEKSErrNo) { return err; } fputs(")\n", stdout); break; - case YACItemFloat: + case KEKSItemFloat: fputs("FLOAT: TODO\n", stdout); break; - case YACItemTAI64: + case KEKSItemTAI64: err = PrintTAI64(atom->v.str.ptr, atom->v.str.len); - if (err != YACErrNo) { + if (err != KEKSErrNo) { return err; } break; - case YACItemBin: { + case KEKSItemBin: { const size_t l = (atom->v.str.len > maxStrLen) ? maxStrLen : atom->v.str.len; hex = HexEnc(atom->v.str.ptr, l); fprintf( @@ -137,14 +137,14 @@ myCb( free(hex); break; } - case YACItemStr: { + case KEKSItemStr: { const size_t l = (atom->v.str.len > maxStrLen) ? maxStrLen : atom->v.str.len; hex = strndup((const char *)(atom->v.str.ptr), l); fprintf(stdout, "\"%s%s\"\n", hex, (atom->v.str.len > maxStrLen) ? "..." : ""); free(hex); break; } - case YACItemRaw: + case KEKSItemRaw: hex = HexEnc(atom->v.str.ptr, atom->v.str.len); fprintf(stdout, "(t=0x%X l=%zu v=%s)\n", atom->tag, atom->v.str.len, hex); free(hex); @@ -153,7 +153,7 @@ myCb( fprintf(stderr, "unknown atom\n"); return EXIT_FAILURE; } - return YACErrNo; + return KEKSErrNo; } int @@ -168,20 +168,20 @@ main(int argc, char **argv) if (!Mmap(&buf, &len, argv[1])) { exit(EXIT_FAILURE); } - struct YACAtom atom; - memset(&atom, 0, sizeof(struct YACAtom)); + struct KEKSAtom atom; + memset(&atom, 0, sizeof(struct KEKSAtom)); size_t off = 0; size_t got = 0; - enum YACErr err = YACAtomDecode(&got, &atom, buf, len); - if (err != YACErrNo) { - fprintf(stderr, "err: %s\n", YACErr2Str(err)); + enum KEKSErr err = KEKSAtomDecode(&got, &atom, buf, len); + if (err != KEKSErrNo) { + fprintf(stderr, "err: %s\n", KEKSErr2Str(err)); return EXIT_FAILURE; } off += got; struct CbState cbState = {.indent = 0}; err = myCb(NULL, 0, false, 0, &cbState, &atom, &off, buf, len); - if (err != YACErrNo) { - fprintf(stderr, "err: %s\n", YACErr2Str(err)); + if (err != KEKSErrNo) { + fprintf(stderr, "err: %s\n", KEKSErr2Str(err)); return EXIT_FAILURE; } assert(cbState.indent == 0); diff --git a/cyac/cmd/print-itered/print-itered.do b/c/cmd/print-itered/print-itered.do similarity index 96% rename from cyac/cmd/print-itered/print-itered.do rename to c/cmd/print-itered/print-itered.do index 9f9b1e3..cb6ed26 100644 --- a/cyac/cmd/print-itered/print-itered.do +++ b/c/cmd/print-itered/print-itered.do @@ -5,4 +5,4 @@ read CC <../../conf/cc CFLAGS=$(cat ../../conf/cflags) LDFLAGS=$(cat ../../conf/ldflags) read PREFIX <../../conf/prefix -$CC $CFLAGS -I$PREFIX/include -o $3 $2.c $deps $LDFLAGS -L$PREFIX/lib -lyac +$CC $CFLAGS -I$PREFIX/include -o $3 $2.c $deps $LDFLAGS -L$PREFIX/lib -lkeks diff --git a/cyac/cmd/test-vector/.gitignore b/c/cmd/test-vector/.gitignore similarity index 100% rename from cyac/cmd/test-vector/.gitignore rename to c/cmd/test-vector/.gitignore diff --git a/cyac/cmd/test-vector/all.do b/c/cmd/test-vector/all.do similarity index 100% rename from cyac/cmd/test-vector/all.do rename to c/cmd/test-vector/all.do diff --git a/cyac/cmd/test-vector/clean b/c/cmd/test-vector/clean similarity index 100% rename from cyac/cmd/test-vector/clean rename to c/cmd/test-vector/clean diff --git a/c/cmd/test-vector/test-vector.c b/c/cmd/test-vector/test-vector.c new file mode 100644 index 0000000..3eebe6e --- /dev/null +++ b/c/cmd/test-vector/test-vector.c @@ -0,0 +1,252 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +static size_t Off = 0; +static size_t Got = 0; + +static void +adder(const bool ok) +{ + assert(ok); + Off += Got; +} + +int +main(void) +{ + const size_t len = (size_t)68 * (uint16_t)1024; + unsigned char *buf = malloc(len); + assert(buf != NULL); + unsigned char *bin = malloc((uint32_t)1 << (uint8_t)17); + assert(bin != NULL); + + adder(KEKSAtomMapEncode(&Got, buf + Off, len - Off)); // . + + adder( + KEKSAtomStrEncode(&Got, buf + Off, len - Off, (const unsigned char *)"nil", 3)); + adder(KEKSAtomNILEncode(&Got, buf + Off, len - Off)); + + adder( + KEKSAtomStrEncode(&Got, buf + Off, len - Off, (const unsigned char *)"str", 3)); + adder(KEKSAtomMapEncode(&Got, buf + Off, len - Off)); // .str + + adder( + KEKSAtomStrEncode(&Got, buf + Off, len - Off, (const unsigned char *)"bin", 3)); + adder(KEKSAtomListEncode(&Got, buf + Off, len - Off)); // .str.bin + adder(KEKSAtomBinEncode(&Got, buf + Off, len - Off, (const unsigned char *)"", 0)); + memset(bin, '0', 60); + adder(KEKSAtomBinEncode(&Got, buf + Off, len - Off, bin, 60)); + memset(bin, '1', 61); + adder(KEKSAtomBinEncode(&Got, buf + Off, len - Off, bin, 61)); + memset(bin, '2', 255); + adder(KEKSAtomBinEncode(&Got, buf + Off, len - Off, bin, 255)); + memset(bin, 'A', 61 + 255); + adder(KEKSAtomBinEncode(&Got, buf + Off, len - Off, bin, 61 + 255)); + memset(bin, 'B', 62 + 255); + adder(KEKSAtomBinEncode(&Got, buf + Off, len - Off, bin, 62 + 255)); + memset(bin, '3', 1024); + adder(KEKSAtomBinEncode(&Got, buf + Off, len - Off, bin, 1024)); + memset(bin, '4', 63 + 255 + 65535 + 1); + adder(KEKSAtomBinEncode(&Got, buf + Off, len - Off, bin, 63 + 255 + 65535 + 1)); + adder(KEKSAtomEOCEncode(&Got, buf + Off, len - Off)); // .str.bin + + adder( + KEKSAtomStrEncode(&Got, buf + Off, len - Off, (const unsigned char *)"utf8", 4)); + adder(KEKSAtomStrEncode( + &Got, buf + Off, len - Off, (const unsigned char *)"привет мир", 19)); + adder(KEKSAtomEOCEncode(&Got, buf + Off, len - Off)); // .str + + adder( + KEKSAtomStrEncode(&Got, buf + Off, len - Off, (const unsigned char *)"blob", 4)); + adder(KEKSAtomListEncode(&Got, buf + Off, len - Off)); // .blob + + adder(KEKSAtomBlobEncode(&Got, buf + Off, len - Off, 12)); // .blob.0 + memset(bin, '5', 1); + adder(KEKSAtomBinEncode(&Got, buf + Off, len - Off, bin, 1)); + + adder(KEKSAtomBlobEncode(&Got, buf + Off, len - Off, 12)); // .blob.1 + memset(bin, '6', 12); + adder(KEKSAtomChunkEncode(&Got, buf + Off, len - Off, bin, 12)); + adder(KEKSAtomBinEncode(&Got, buf + Off, len - Off, NULL, 0)); + + adder(KEKSAtomBlobEncode(&Got, buf + Off, len - Off, 12)); // .blob.2 + memset(bin, '7', 12); + adder(KEKSAtomChunkEncode(&Got, buf + Off, len - Off, bin, 12)); + adder(KEKSAtomBinEncode(&Got, buf + Off, len - Off, bin, 1)); + + adder(KEKSAtomBlobEncode(&Got, buf + Off, len - Off, 5)); // .blob.3 + adder(KEKSAtomChunkEncode( + &Got, buf + Off, len - Off, (const unsigned char *)"12345", 5)); + adder(KEKSAtomChunkEncode( + &Got, buf + Off, len - Off, (const unsigned char *)"67890", 5)); + adder(KEKSAtomBinEncode(&Got, buf + Off, len - Off, (const unsigned char *)"-", 1)); + + adder(KEKSAtomEOCEncode(&Got, buf + Off, len - Off)); // .blob + + adder( + KEKSAtomStrEncode(&Got, buf + Off, len - Off, (const unsigned char *)"bool", 4)); + adder(KEKSAtomListEncode(&Got, buf + Off, len - Off)); // .bool + adder(KEKSAtomBoolEncode(&Got, buf + Off, len - Off, true)); + adder(KEKSAtomBoolEncode(&Got, buf + Off, len - Off, false)); + adder(KEKSAtomEOCEncode(&Got, buf + Off, len - Off)); // .bool + + adder( + KEKSAtomStrEncode(&Got, buf + Off, len - Off, (const unsigned char *)"ints", 4)); + adder(KEKSAtomMapEncode(&Got, buf + Off, len - Off)); // .ints + + adder( + KEKSAtomStrEncode(&Got, buf + Off, len - Off, (const unsigned char *)"neg", 3)); + adder(KEKSAtomListEncode(&Got, buf + Off, len - Off)); // .ints.neg + adder(KEKSAtomSintEncode(&Got, buf + Off, len - Off, -1)); + adder(KEKSAtomSintEncode(&Got, buf + Off, len - Off, -2)); + adder(KEKSAtomSintEncode(&Got, buf + Off, len - Off, -32)); + adder(KEKSAtomSintEncode(&Got, buf + Off, len - Off, -33)); + adder(KEKSAtomSintEncode(&Got, buf + Off, len - Off, -123)); + adder(KEKSAtomSintEncode(&Got, buf + Off, len - Off, -1234)); + adder(KEKSAtomSintEncode(&Got, buf + Off, len - Off, -12345678)); + adder(KEKSAtomRawEncode( + &Got, + buf + Off, + len - Off, + KEKSAtomNint, + (const unsigned char *)"\x8A\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", + 11)); + adder(KEKSAtomRawEncode( + &Got, + buf + Off, + len - Off, + KEKSAtomNint, + (const unsigned char + *)"\x91\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + 18)); + adder(KEKSAtomRawEncode( + &Got, + buf + Off, + len - Off, + KEKSAtomNint, + (const unsigned char + *)"\xBE\x00\xA1\xE5\xA4\x61\x28\x03\x41\x85\x6D\x4A\xD9\x08\xA6\x9E\xA5\xF3\xCC\xC1\x0C\x78\x82\x14\x2B\xB7\xD8\x01\xCC\x38\x0F\x26\xB6\xB4\xD6\x96\x32\x02\x4E\xE5\x21\xF8\xCF\xAF\xB4\x43\xD4\x9A\x2A\x3D\x0C\xC7\x3B\xB4\x75\x7E\x88\x2F\x53\x96\xED\x30\x2B\x41\x82\x10\xD0\xD4\x9D\x71\xBE\x86\xCA\x69\x9C\xF5\xEE\x3B\xD6\xD5\x7E\xD6\x58\xE6\x93\x16\x22\x96\x44\xBA\x65\x0C\x92\xD7\xF0\xD4\xDB\x29\xC3\xAD\x1D\xFA\x99\x79\x16\x6F\x4C\x6E\x79\x56\x1A\x58\xF8\xE2\xC6\x3D\x08\xDF\x4E\x22\x46\xED\x1F\x64\xD2\xD6\x13\xA1\x9D\x8C\x9A\x68\x70\xE6\x18\x8E\x2F\x3A\xD4\x0C\x03\x8F\xDA\x30\x45\x2F\x8D\xDF\xCD\x21\x2A\x6A\x97\x4B\xC2\x5E\xC6\xA0\x56\x4C\x66\xA7\xD2\x87\x50\xFF\x9D\xB4\x58\xB7\x44\x41\xE4\x9E\xE5\xE8\x2D\xBF\x49\x74\xD6\x45\x67\x8E\x0A\xD0\x31\xF9\x7A\xAB\xA8\x55\x45\x1E\xEF\x17\xA8\x9B\x42\x82\x1E\x53\x08\x16\xDD\x57\x93\xA8\x3B\x7A\x82\xE8\xED\xE8\x1E\x7F\x33\x95\x69\x1F\x76\x17\x84\xF8\xBC\x62\x79\x61\xCD\x40\x84\x5E\xE9\x08\xA4\x0B\x9D\x1F\x01\x92\x7B\x38\xEB\x1A\x7D\x4E\xFD\x60\xDB\x09\x44\xF7\xEC\x1B\x83\x2B\x7E\x6E\xB1\x83\x3F\x9A\x35\x15\x76\xAD\x5D\xE5\x71\xFA\xE8\x86\x5D\xA7\x51\x4F\x06\xB0\xFB\xF3\x8C\x1F\x2A\x85\x38\xF5\xD3\x8B\x4E\x18\x00\x1C\xCB\xB9\xDD\xCB\x48\x85\x30\xF6\x08\x6D\x14\x74\x4D\x8B\x56\x72\x16\x6E\x48\xE9\xEF\x93\x77\x25\x75\xDB\x66\xB6\xF2\x57\xC6\xFF\xAD\x6E\x2C\x29\x15\x10\xC5\xED\x02\xE1\xA8\xB2\x4B\x44\xEC\x1E\x2A\x91\x68\x62\x38\xE8\xDE\xFD\x18\xC0\x19\x98\x63\x4A\x50\x76\xA6\xB7\xF8\x5F\xC8\x1A\x1D\x61\xA1\x5B\x2C\x52\x8D\xFA\x08\x2C\xE3\xE3\xE2\xCA\x64\x9A\xC0\x48\x17\xEC\x5C\x12\x3E\x0B\x76\x1A\xB1\x03\xF7\x80\xC0\x14\xF0\x21\xBB\xEB\x7E\xA3\xB8\x6E\x0C\xA1\xC8\x33\xE3\x8E\xF5\xC8\x97\xA6\xD7\xE1\xF4\xA2\x39\x8C\x49\x0B\x3D\x65\xE2\xF4\x5C\x7F\xAE\x40\x2D\x1D\xF1\x69\x8B\x6F\xDD\xB1\x85\x48\x16\x64\x87\x1C\x26\x64\xBF\xD1\x68\x6B\x2B\x33\x72\x78\x3F\x18\x56\xF6\x24\x7A\x3F\x84\x37\xA2\x81\x8F\x68\xB7\xC4\xEA\x13\xA5\xF5\x7B\x73\xC7\x28\x70\xB6\x84\x04\x5F\x14", + 481)); + adder(KEKSAtomEOCEncode(&Got, buf + Off, len - Off)); // .ints.neg + + adder( + KEKSAtomStrEncode(&Got, buf + Off, len - Off, (const unsigned char *)"pos", 3)); + adder(KEKSAtomListEncode(&Got, buf + Off, len - Off)); // .ints.pos + adder(KEKSAtomUintEncode(&Got, buf + Off, len - Off, 0)); + adder(KEKSAtomUintEncode(&Got, buf + Off, len - Off, 1)); + adder(KEKSAtomUintEncode(&Got, buf + Off, len - Off, 31)); + adder(KEKSAtomUintEncode(&Got, buf + Off, len - Off, 32)); + adder(KEKSAtomUintEncode(&Got, buf + Off, len - Off, 123)); + adder(KEKSAtomUintEncode(&Got, buf + Off, len - Off, 1234)); + adder(KEKSAtomUintEncode(&Got, buf + Off, len - Off, 12345678)); + adder(KEKSAtomRawEncode( + &Got, + buf + Off, + len - Off, + KEKSAtomPint, + (const unsigned char *)"\x8B\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + 12)); + adder(KEKSAtomRawEncode( + &Got, + buf + Off, + len - Off, + KEKSAtomPint, + (const unsigned char + *)"\x91\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", + 18)); + adder(KEKSAtomEOCEncode(&Got, buf + Off, len - Off)); // .ints.pos + + adder(KEKSAtomEOCEncode(&Got, buf + Off, len - Off)); // .ints + + adder( + KEKSAtomStrEncode(&Got, buf + Off, len - Off, (const unsigned char *)"uuid", 4)); + adder(KEKSAtomUUIDEncode( + &Got, + buf + Off, + len - Off, + (const unsigned char + *)"\x0e\x87\x5e\x3f\xd3\x85\x49\xeb\x87\xb4\xbe\x42\xd6\x41\xc3\x67")); + + adder(KEKSAtomStrEncode( + &Got, buf + Off, len - Off, (const unsigned char *)"dates", 5)); + adder(KEKSAtomListEncode(&Got, buf + Off, len - Off)); // .dates + { + struct timespec ts; + ts.tv_sec = 1234567890; + assert(KEKSTimespecToTAI(&ts)); + unsigned char tai[12] = {0}; + assert(KEKSTimespecToTAI64(tai, &ts)); + adder(KEKSAtomTAI64Encode(&Got, buf + Off, len - Off, tai, 8)); + + ts.tv_nsec = 456000; + assert(KEKSTimespecToTAI64(tai, &ts)); + adder(KEKSAtomTAI64Encode(&Got, buf + Off, len - Off, tai, 12)); + + adder(KEKSAtomRawEncode( + &Got, + buf + Off, + len - Off, + KEKSAtomTAI64N, + (const unsigned char *)"\x40\x00\x00\x00\x49\x96\x02\xF4\x00\x06\xF8\x55", + 12)); + + adder(KEKSAtomRawEncode( + &Got, + buf + Off, + len - Off, + KEKSAtomTAI64NA, + (const unsigned char + *)"\x40\x00\x00\x00\x49\x96\x02\xF4\x00\x06\xF8\x55\x07\x5B\xCD\x15", + 16)); + } + adder(KEKSAtomEOCEncode(&Got, buf + Off, len - Off)); // .dates + + adder(KEKSAtomStrEncode( + &Got, buf + Off, len - Off, (const unsigned char *)"floats", 6)); + adder(KEKSAtomListEncode(&Got, buf + Off, len - Off)); // .floats + adder(KEKSAtomRawEncode( + &Got, + buf + Off, + len - Off, + KEKSAtomFloat32, + (const unsigned char *)"\x01\x02\x03\x04", + 4)); + adder(KEKSAtomEOCEncode(&Got, buf + Off, len - Off)); // .floats + + adder(KEKSAtomStrEncode( + &Got, buf + Off, len - Off, (const unsigned char *)"empties", 7)); + adder(KEKSAtomListEncode(&Got, buf + Off, len - Off)); // .empties + adder(KEKSAtomListEncode(&Got, buf + Off, len - Off)); + adder(KEKSAtomEOCEncode(&Got, buf + Off, len - Off)); + adder(KEKSAtomMapEncode(&Got, buf + Off, len - Off)); + adder(KEKSAtomEOCEncode(&Got, buf + Off, len - Off)); + adder(KEKSAtomBlobEncode(&Got, buf + Off, len - Off, 123)); + adder(KEKSAtomBinEncode(&Got, buf + Off, len - Off, NULL, 0)); + memset(bin, '\x00', 16); + adder(KEKSAtomUUIDEncode(&Got, buf + Off, len - Off, bin)); + adder(KEKSAtomRawEncode( + &Got, + buf + Off, + len - Off, + KEKSAtomTAI64, + (const unsigned char *)"\x00\x00\x00\x00\x00\x00\x00\x00", + 8)); + adder(KEKSAtomEOCEncode(&Got, buf + Off, len - Off)); // .empties + + adder(KEKSAtomEOCEncode(&Got, buf + Off, len - Off)); // . + + free(bin); + assert(write(STDOUT_FILENO, buf, Off) == (ssize_t)Off); + free(buf); + + return EXIT_SUCCESS; +} diff --git a/cyac/cmd/test-vector/test-vector.do b/c/cmd/test-vector/test-vector.do similarity index 97% rename from cyac/cmd/test-vector/test-vector.do rename to c/cmd/test-vector/test-vector.do index 28cdd53..6b15a27 100644 --- a/cyac/cmd/test-vector/test-vector.do +++ b/c/cmd/test-vector/test-vector.do @@ -3,4 +3,4 @@ read CC <../../conf/cc CFLAGS=$(cat ../../conf/cflags) LDFLAGS=$(cat ../../conf/ldflags) read PREFIX <../../conf/prefix -$CC $CFLAGS -I$PREFIX/include -o $3 $2.c $LDFLAGS -L$PREFIX/lib -lyac +$CC $CFLAGS -I$PREFIX/include -o $3 $2.c $LDFLAGS -L$PREFIX/lib -lkeks diff --git a/cyac/compile_flags.txt.do b/c/compile_flags.txt.do similarity index 100% rename from cyac/compile_flags.txt.do rename to c/compile_flags.txt.do diff --git a/cyac/conf/ar b/c/conf/ar similarity index 100% rename from cyac/conf/ar rename to c/conf/ar diff --git a/cyac/conf/cc b/c/conf/cc similarity index 100% rename from cyac/conf/cc rename to c/conf/cc diff --git a/cyac/conf/cflags b/c/conf/cflags similarity index 100% rename from cyac/conf/cflags rename to c/conf/cflags diff --git a/cyac/conf/ldflags b/c/conf/ldflags similarity index 100% rename from cyac/conf/ldflags rename to c/conf/ldflags diff --git a/cyac/conf/prefix b/c/conf/prefix similarity index 100% rename from cyac/conf/prefix rename to c/conf/prefix diff --git a/cyac/doc/.gitignore b/c/doc/.gitignore similarity index 67% rename from cyac/doc/.gitignore rename to c/doc/.gitignore index 68365ba..71c97b1 100644 --- a/cyac/doc/.gitignore +++ b/c/doc/.gitignore @@ -1,3 +1,3 @@ /build/ -/cyac.info +/ckeks.info /docstringer.log diff --git a/c/doc/atom.texi b/c/doc/atom.texi new file mode 100644 index 0000000..8ae2d42 --- /dev/null +++ b/c/doc/atom.texi @@ -0,0 +1,29 @@ +@node Atom +@cindex atom +@unnumbered Atom + +@anchor{KEKSAtom} +@DOCSTRING KEKSAtom@ + +@anchor{KEKSItemType} +@DOCSTRING KEKSItemType@ + +@DOCSTRING KEKSAtomDecode@ + +@DOCSTRING KEKSAtomEOCEncode@ +@anchor{KEKSAtomNILEncode} +@DOCSTRING KEKSAtomNILEncode@ +@DOCSTRING KEKSAtomBoolEncode@ +@DOCSTRING KEKSAtomUUIDEncode@ +@DOCSTRING KEKSAtomUintEncode@ +@DOCSTRING KEKSAtomSintEncode@ +@DOCSTRING KEKSAtomListEncode@ +@DOCSTRING KEKSAtomMapEncode@ +@DOCSTRING KEKSAtomBlobEncode@ +@DOCSTRING KEKSAtomStrEncode@ +@anchor{KEKSAtomBinEncode} +@DOCSTRING KEKSAtomBinEncode@ +@anchor{KEKSAtomChunkEncode} +@DOCSTRING KEKSAtomChunkEncode@ +@DOCSTRING KEKSAtomTAI64Encode@ +@DOCSTRING KEKSAtomRawEncode@ diff --git a/cyac/doc/cyac.info.do b/c/doc/ckeks.info.do similarity index 100% rename from cyac/doc/cyac.info.do rename to c/doc/ckeks.info.do diff --git a/cyac/doc/clean b/c/doc/clean similarity index 56% rename from cyac/doc/clean rename to c/doc/clean index 1d3c999..4757f3c 100755 --- a/cyac/doc/clean +++ b/c/doc/clean @@ -1,4 +1,4 @@ #!/bin/sh -e cd "$(dirname "$(realpath -- "$0")")" -rm -fr build cyac.info docstringer.log +rm -fr build ckeks.info docstringer.log diff --git a/cyac/doc/cmd.texi b/c/doc/cmd.texi similarity index 94% rename from cyac/doc/cmd.texi rename to c/doc/cmd.texi index e86a9c2..7882521 100644 --- a/cyac/doc/cmd.texi +++ b/c/doc/cmd.texi @@ -6,7 +6,7 @@ @pindex cmd/test-vector @item cmd/test-vector Example program that forms the same test vector as -@file{tyac/test-vector.tcl} in a streaming way. +@file{tkeks/test-vector.tcl} in a streaming way. @pindex cmd/print-itered @item cmd/test-itered diff --git a/cyac/doc/docstringer.log.do b/c/doc/docstringer.log.do similarity index 100% rename from cyac/doc/docstringer.log.do rename to c/doc/docstringer.log.do diff --git a/cyac/doc/docstringer.pl b/c/doc/docstringer.pl similarity index 100% rename from cyac/doc/docstringer.pl rename to c/doc/docstringer.pl diff --git a/cyac/doc/err.texi b/c/doc/err.texi similarity index 52% rename from cyac/doc/err.texi rename to c/doc/err.texi index c610cf8..8744727 100644 --- a/cyac/doc/err.texi +++ b/c/doc/err.texi @@ -2,6 +2,6 @@ @cindex errors @unnumbered Errors -@DOCSTRING YACErr@ +@DOCSTRING KEKSErr@ -@DOCSTRING YACErr2Str@ +@DOCSTRING KEKSErr2Str@ diff --git a/cyac/doc/index.texi b/c/doc/index.texi similarity index 90% rename from cyac/doc/index.texi rename to c/doc/index.texi index d979c12..bfd22a6 100644 --- a/cyac/doc/index.texi +++ b/c/doc/index.texi @@ -1,14 +1,14 @@ \input texinfo -@settitle cyac +@settitle ckeks @copying Copyright @copyright{} 2024-2025 @email{stargrave@@stargrave.org, Sergey Matveev} @end copying @node Top -@top cyac +@top ckeks -C99 implementation of the @url{http://www.yac.cypherpunks.su, YAC} +C99 implementation of the @url{http://www.keks.cypherpunks.su, KEKS} codec. @itemize @@ -18,7 +18,7 @@ codec. @item No TAI64NA support. @end itemize -cyac is +ckeks is @url{https://www.gnu.org/philosophy/pragmatic.html, copylefted} @url{https://www.gnu.org/philosophy/free-sw.html, free software} licenced under @url{https://www.gnu.org/licenses/lgpl-3.0.html, GNU LGPLv3}. diff --git a/cyac/doc/install.texi b/c/doc/install.texi similarity index 100% rename from cyac/doc/install.texi rename to c/doc/install.texi diff --git a/c/doc/items.texi b/c/doc/items.texi new file mode 100644 index 0000000..93fce40 --- /dev/null +++ b/c/doc/items.texi @@ -0,0 +1,24 @@ +@node Items +@cindex items +@unnumbered Items + +Streamable decoding by one atom is not very convenient in many cases. +There is ability to recursively decode the whole structures. + +@anchor{KEKSItems} +@DOCSTRING KEKSItems@ +@anchor{KEKSItem} +@DOCSTRING KEKSItem@ +@DOCSTRING KEKSItemsInit@ +@anchor{KEKSItemsGrow} +@DOCSTRING KEKSItemsGrow@ +@anchor{KEKSItemsParse} +@DOCSTRING KEKSItemsParse@ +@DOCSTRING KEKSItemsEncode@ +@DOCSTRING KEKSItemsGetByKeyLen@ +@anchor{KEKSItemsGetByKey} +@DOCSTRING KEKSItemsGetByKey@ +@DOCSTRING KEKSItemsGetByKeyAndType@ +@DOCSTRING KEKSStrEqual@ +@DOCSTRING KEKSListHasOnlyType@ +@DOCSTRING KEKSMapHasOnlyType@ diff --git a/c/doc/pki.texi b/c/doc/pki.texi new file mode 100644 index 0000000..db36e6a --- /dev/null +++ b/c/doc/pki.texi @@ -0,0 +1,19 @@ +@node PKI +@cindex PKI +@unnumbered PKI + +@file{lib/pki} contains PKI-related code. It is not directly related to +the KEKS codec, so it is placed isolated nearby. Currently there are +functions to deal with certificate verification: + +@anchor{KEKSCer} +@DOCSTRING KEKSCer@ + +@DOCSTRING KEKSCerParse@ + +@DOCSTRING KEKSCerVerify@ + +@DOCSTRING KEKSCerVerifyOpts@ + +@anchor{KEKSCerSigVerifier} +@DOCSTRING KEKSCerSigVerifier@ diff --git a/c/doc/tai64.texi b/c/doc/tai64.texi new file mode 100644 index 0000000..a590946 --- /dev/null +++ b/c/doc/tai64.texi @@ -0,0 +1,13 @@ +@node Datetime +@cindex TAI64 +@cindex datetime +@unnumbered Datetime + +KEKS uses @url{http://cr.yp.to/libtai/tai64.html, TAI64} for datetime +objects. There are helpers to convert it to UTC and vice versa. + +@DOCSTRING KEKSTAI64ToTimespec@ +@DOCSTRING KEKSTimespecToUTC@ +@DOCSTRING KEKSTimespecToTAI64@ +@DOCSTRING KEKSTimespecToTAI@ +@DOCSTRING KEKSLeapsecs@ diff --git a/cyac/lib/.gitignore b/c/lib/.gitignore similarity index 68% rename from cyac/lib/.gitignore rename to c/lib/.gitignore index a0169a4..c081203 100644 --- a/cyac/lib/.gitignore +++ b/c/lib/.gitignore @@ -1,3 +1,3 @@ /*.o /compile_flags.txt -/libyac.a +/libkeks.a diff --git a/c/lib/atoms.h b/c/lib/atoms.h new file mode 100644 index 0000000..4581ed0 --- /dev/null +++ b/c/lib/atoms.h @@ -0,0 +1,28 @@ +#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/cyac/lib/clean b/c/lib/clean similarity index 100% rename from cyac/lib/clean rename to c/lib/clean diff --git a/cyac/lib/dec.c b/c/lib/dec.c similarity index 55% rename from cyac/lib/dec.c rename to c/lib/dec.c index f7f3438..802d437 100644 --- a/cyac/lib/dec.c +++ b/c/lib/dec.c @@ -1,4 +1,4 @@ -// cyac -- C YAC encoder implementation +// ckeks -- C KEKS encoder implementation // Copyright (C) 2024-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify @@ -23,10 +23,10 @@ #include "frombe.h" #include "utf8.h" -enum YACErr -YACAtomDecode( // NOLINT(misc-no-recursion) +enum KEKSErr +KEKSAtomDecode( // NOLINT(misc-no-recursion) size_t *got, - struct YACAtom *atom, + struct KEKSAtom *atom, const unsigned char *buf, const size_t len) { @@ -34,13 +34,13 @@ YACAtomDecode( // NOLINT(misc-no-recursion) atom->v.str.len = 0; (*got) = 1; if (len < 1) { - return YACErrNotEnough; + return KEKSErrNotEnough; } atom->tag = buf[0]; - if ((atom->tag & (uint8_t)YACAtomStrings) > 0) { + if ((atom->tag & (uint8_t)KEKSAtomStrings) > 0) { atom->typ = - ((atom->tag & (uint8_t)YACAtomIsUTF8) == 0) ? YACItemBin : YACItemStr; + ((atom->tag & (uint8_t)KEKSAtomIsUTF8) == 0) ? KEKSItemBin : KEKSItemStr; uint64_t l = atom->tag & (uint8_t)63; size_t ll = 0; switch (l) { @@ -61,212 +61,212 @@ YACAtomDecode( // NOLINT(misc-no-recursion) if (ll != 0) { (*got) += ll; if (len < (*got)) { - return YACErrNotEnough; + return KEKSErrNotEnough; } - uint64_t ul = yacFromBE(buf + 1, ll); + uint64_t ul = keksFromBE(buf + 1, ll); if (ul > (SIZE_MAX - (63 + 255 + 65535))) { - return YACErrLenTooBig; + return KEKSErrLenTooBig; } l += ul; } const size_t ls = (size_t)l; (*got) += ls; if ((*got) <= ls) { - return YACErrLenTooBig; + return KEKSErrLenTooBig; } if (len < (*got)) { - return YACErrNotEnough; + return KEKSErrNotEnough; } atom->v.str.len = ls; atom->v.str.ptr = buf + 1 + ll; - if (atom->typ == YACItemStr) { + if (atom->typ == KEKSItemStr) { if (l > PTRDIFF_MAX) { - return YACErrLenTooBig; + return KEKSErrLenTooBig; } size_t cpl = 0; - uint32_t cp = YACUTF8InvalidCp; + uint32_t cp = KEKSUTF8InvalidCp; for (size_t n = 0; n < l; n += cpl) { - cpl = YACUTF8CpDecode(&cp, atom->v.str.ptr + (ptrdiff_t)n, l - n); - if (cp == YACUTF8InvalidCp) { - return YACErrBadUTF8; + cpl = KEKSUTF8CpDecode(&cp, atom->v.str.ptr + (ptrdiff_t)n, l - n); + if (cp == KEKSUTF8InvalidCp) { + return KEKSErrBadUTF8; } } } - return YACErrNo; + return KEKSErrNo; } switch (atom->tag) { - case YACAtomEOC: - atom->typ = YACItemEOC; + case KEKSAtomEOC: + atom->typ = KEKSItemEOC; break; - case YACAtomNIL: - atom->typ = YACItemNIL; + case KEKSAtomNIL: + atom->typ = KEKSItemNIL; break; - case YACAtomFalse: - atom->typ = YACItemFalse; + case KEKSAtomFalse: + atom->typ = KEKSItemFalse; break; - case YACAtomTrue: - atom->typ = YACItemTrue; + case KEKSAtomTrue: + atom->typ = KEKSItemTrue; break; - case YACAtomUUID: - atom->typ = YACItemUUID; + case KEKSAtomUUID: + atom->typ = KEKSItemUUID; (*got) += 16; if (len < (*got)) { - return YACErrNotEnough; + return KEKSErrNotEnough; } atom->v.uuid = buf + 1; break; - case YACAtomList: - atom->typ = YACItemList; + case KEKSAtomList: + atom->typ = KEKSItemList; break; - case YACAtomMap: - atom->typ = YACItemMap; + case KEKSAtomMap: + atom->typ = KEKSItemMap; break; - case YACAtomBlob: { - atom->typ = YACItemBlob; + case KEKSAtomBlob: { + atom->typ = KEKSItemBlob; (*got) += 8; if (len < (*got)) { - return YACErrNotEnough; + return KEKSErrNotEnough; } - const uint64_t chunkLen = yacFromBE(buf + 1, 8); + const uint64_t chunkLen = keksFromBE(buf + 1, 8); if (chunkLen > (SIZE_MAX - 1)) { - return YACErrLenTooBig; + return KEKSErrLenTooBig; } atom->v.blob.chunkLen = (size_t)chunkLen + 1; break; } - case YACAtomPint: - case YACAtomNint: { - atom->typ = (atom->tag == YACAtomPint) ? YACItemPint : YACItemNint; + case KEKSAtomPint: + case KEKSAtomNint: { + atom->typ = (atom->tag == KEKSAtomPint) ? KEKSItemPint : KEKSItemNint; size_t binGot = 0; - struct YACAtom bin; - memset(&bin, 0, sizeof(struct YACAtom)); - if ((buf[1] & (unsigned char)YACAtomStrings) == 0) { - return YACErrIntNonBin; + struct KEKSAtom bin; + memset(&bin, 0, sizeof(struct KEKSAtom)); + if ((buf[1] & (unsigned char)KEKSAtomStrings) == 0) { + return KEKSErrIntNonBin; } - enum YACErr err = YACAtomDecode(&binGot, &bin, buf + 1, len - 1); - if (err != YACErrNo) { + enum KEKSErr err = KEKSAtomDecode(&binGot, &bin, buf + 1, len - 1); + if (err != KEKSErrNo) { return err; } (*got) += binGot; - if (bin.typ != YACItemBin) { - return YACErrIntNonBin; + if (bin.typ != KEKSItemBin) { + return KEKSErrIntNonBin; } if (bin.v.str.len == 0) { - if (atom->typ == YACItemPint) { + if (atom->typ == KEKSItemPint) { atom->v.pint = 0; } else { atom->v.nint = -1; } - return YACErrNo; + return KEKSErrNo; } if (bin.v.str.ptr[0] == 0) { - return YACErrIntNonMinimal; + return KEKSErrIntNonMinimal; } if (bin.v.str.len > 8) { - atom->typ = YACItemRaw; + atom->typ = KEKSItemRaw; atom->v.str.len = binGot; atom->v.str.ptr = buf + 1; - return YACErrNo; + return KEKSErrNo; } - atom->v.pint = yacFromBE(bin.v.str.ptr, bin.v.str.len); - if (atom->typ == YACItemNint) { + atom->v.pint = keksFromBE(bin.v.str.ptr, bin.v.str.len); + if (atom->typ == KEKSItemNint) { if (atom->v.pint >= ((uint64_t)1 << (uint8_t)63)) { - atom->typ = YACItemRaw; + atom->typ = KEKSItemRaw; atom->v.str.len = binGot; atom->v.str.ptr = buf + 1; } else { atom->v.nint = -1 - (int64_t)(atom->v.pint); } } - return YACErrNo; + return KEKSErrNo; } - case YACAtomFloat16: - case YACAtomFloat32: - case YACAtomFloat64: - case YACAtomFloat128: - case YACAtomFloat256: { + case KEKSAtomFloat16: + case KEKSAtomFloat32: + case KEKSAtomFloat64: + case KEKSAtomFloat128: + case KEKSAtomFloat256: { size_t l = 0; switch (atom->tag) { - case YACAtomFloat16: + case KEKSAtomFloat16: l = 2; break; - case YACAtomFloat32: + case KEKSAtomFloat32: l = 4; break; - case YACAtomFloat64: + case KEKSAtomFloat64: l = 8; break; - case YACAtomFloat128: + case KEKSAtomFloat128: l = 16; break; - case YACAtomFloat256: + case KEKSAtomFloat256: l = 32; break; } - atom->typ = YACItemFloat; + atom->typ = KEKSItemFloat; (*got) += l; if (len < (*got)) { - return YACErrNotEnough; + return KEKSErrNotEnough; } - atom->typ = YACItemRaw; + atom->typ = KEKSItemRaw; atom->v.str.len = l; atom->v.str.ptr = buf + 1; break; } - case YACAtomTAI64: - case YACAtomTAI64N: - case YACAtomTAI64NA: { + case KEKSAtomTAI64: + case KEKSAtomTAI64N: + case KEKSAtomTAI64NA: { size_t l = 0; switch (atom->tag) { - case YACAtomTAI64: + case KEKSAtomTAI64: l = 8; break; - case YACAtomTAI64N: + case KEKSAtomTAI64N: l = 12; break; - case YACAtomTAI64NA: + case KEKSAtomTAI64NA: l = 16; break; } - atom->typ = YACItemTAI64; + atom->typ = KEKSItemTAI64; (*got) += l; if (len < (*got)) { - return YACErrNotEnough; + return KEKSErrNotEnough; } atom->v.str.len = l; atom->v.str.ptr = buf + 1; - uint64_t v = yacFromBE(buf + 1, 8); + uint64_t v = keksFromBE(buf + 1, 8); if (v > ((uint64_t)1 << (uint8_t)63)) { - return YACErrTAI64TooBig; + return KEKSErrTAI64TooBig; } if (l > 8) { - v = yacFromBE(buf + 1 + 8, 4); + v = keksFromBE(buf + 1 + 8, 4); if ((l == 12) && (v == 0)) { - return YACErrTAI64NonMinimal; + return KEKSErrTAI64NonMinimal; } if (v > 999999999) { - return YACErrTAI64BadNsec; + return KEKSErrTAI64BadNsec; } } if (l > 12) { - v = yacFromBE(buf + 1 + 8 + 4, 4); + v = keksFromBE(buf + 1 + 8 + 4, 4); if (v == 0) { - return YACErrTAI64NonMinimal; + return KEKSErrTAI64NonMinimal; } if (v > 999999999) { - return YACErrTAI64BadAsec; + return KEKSErrTAI64BadAsec; } } break; } default: - return YACErrUnknownType; + return KEKSErrUnknownType; } - return YACErrNo; + return KEKSErrNo; } diff --git a/cyac/lib/dec.h b/c/lib/dec.h similarity index 59% rename from cyac/lib/dec.h rename to c/lib/dec.h index 190459a..64d3cb4 100644 --- a/cyac/lib/dec.h +++ b/c/lib/dec.h @@ -1,61 +1,61 @@ -#ifndef YAC_DEC_H -#define YAC_DEC_H +#ifndef KEKS_DEC_H +#define KEKS_DEC_H #include #include #include "err.h" -// TEXINFO: YACItemType -// @deftp {Data type} {enum YACItemType} +// TEXINFO: KEKSItemType +// @deftp {Data type} {enum KEKSItemType} // High-level type of the atom. // @itemize -// @item YACItemInvalid -- invalid item value, uninitialised -// @item YACItemEOC -// @item YACItemNIL -// @item YACItemFalse -// @item YACItemTrue -// @item YACItemUUID -// @item YACItemPint -- positive integer -// @item YACItemNint -- negative integer -// @item YACItemList -// @item YACItemMap -// @item YACItemBlob -// @item YACItemFloat -// @item YACItemTAI64 -// @item YACItemBin -// @item YACItemStr -// @item YACItemRaw -- raw value, non-decodable by the library +// @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 YACItemType { - YACItemInvalid = 0, - YACItemEOC = 1, - YACItemNIL, - YACItemFalse, - YACItemTrue, - YACItemUUID, - YACItemPint, - YACItemNint, - YACItemList, - YACItemMap, - YACItemBlob, - YACItemFloat, - YACItemTAI64, - YACItemBin, - YACItemStr, - YACItemRaw, +enum KEKSItemType { + KEKSItemInvalid = 0, + KEKSItemEOC = 1, + KEKSItemNIL, + KEKSItemFalse, + KEKSItemTrue, + KEKSItemUUID, + KEKSItemPint, + KEKSItemNint, + KEKSItemList, + KEKSItemMap, + KEKSItemBlob, + KEKSItemFloat, + KEKSItemTAI64, + KEKSItemBin, + KEKSItemStr, + KEKSItemRaw, }; -// TEXINFO: YACAtom -// @deftp {Data type} {struct YACAtom} +// TEXINFO: KEKSAtom +// @deftp {Data type} {struct KEKSAtom} // Basic unit of the library, describing single TLV-like value. // @table @code // @item .tag // Real value of the atom's tag. May be used during debugging or // when constructing raw value. // @item .typ -// High level @ref{YACItemType, type} of the atom's value. As a rule +// 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. @@ -80,7 +80,7 @@ enum YACItemType { // Raw values use it as a payload. // @end table // @end deftp -struct YACAtom { +struct KEKSAtom { union { const unsigned char *uuid; uint64_t pint; @@ -98,27 +98,27 @@ struct YACAtom { size_t len; } str; } v; - enum YACItemType typ; + enum KEKSItemType typ; unsigned char tag; char _pad[3]; }; -// TEXINFO: YACAtomDecode -// @deftypefun {enum YACErr} YACAtomDecode ( @ +// TEXINFO: KEKSAtomDecode +// @deftypefun {enum KEKSErr} KEKSAtomDecode ( @ // size_t *got, @ -// struct YACAtom *atom, @ +// struct KEKSAtom *atom, @ // const unsigned char *buf, @ // const size_t len) -// Decode the @ref{YACAtom, @var{atom}} from provided @var{buf} of -// length @var{len}. If error is @code{YACErrNotEnough}, then @var{got} +// Decode the @ref{KEKSAtom, @var{atom}} from provided @var{buf} of +// length @var{len}. If error is @code{KEKSErrNotEnough}, then @var{got} // will contain how many bytes is missing in the buffer for full atom // decoding. Otherwise it will contain the full atom's size. // @end deftypefun -enum YACErr -YACAtomDecode( +enum KEKSErr +KEKSAtomDecode( size_t *got, - struct YACAtom *, + struct KEKSAtom *, const unsigned char *buf, const size_t len); -#endif // YAC_DEC_H +#endif // KEKS_DEC_H diff --git a/cyac/lib/dectai.c b/c/lib/dectai.c similarity index 66% rename from cyac/lib/dectai.c rename to c/lib/dectai.c index e477679..ace0cab 100644 --- a/cyac/lib/dectai.c +++ b/c/lib/dectai.c @@ -1,4 +1,4 @@ -// cyac -- C YAC encoder implementation +// ckeks -- C KEKS encoder implementation // Copyright (C) 2024-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify @@ -22,49 +22,49 @@ #include "frombe.h" #include "leapsecs.h" -enum YACErr -YACTAI64ToTimespec(struct timespec *ts, const unsigned char *buf, const size_t len) +enum KEKSErr +KEKSTAI64ToTimespec(struct timespec *ts, const unsigned char *buf, const size_t len) { if (len > 12) { - return YACErrTAI64BadAsec; + return KEKSErrTAI64BadAsec; } - int64_t v = (int64_t)yacFromBE(buf, 8); + int64_t v = (int64_t)keksFromBE(buf, 8); v -= 0x4000000000000000; if (v <= 0) { - return YACErrTAI64InPast; + return KEKSErrTAI64InPast; } if (((uint64_t)1 << ((sizeof(time_t) * 8) - 1)) < (uint64_t)v) { - return YACErrTAI64TooBig; + return KEKSErrTAI64TooBig; } ts->tv_sec = (time_t)v; if (len > 8) { - uint32_t n = (uint32_t)yacFromBE(buf + 8, 4); + uint32_t n = (uint32_t)keksFromBE(buf + 8, 4); ts->tv_nsec = n; } - return YACErrNo; + return KEKSErrNo; } -enum YACErr -YACTimespecToUTC(struct timespec *ts) +enum KEKSErr +KEKSTimespecToUTC(struct timespec *ts) { int64_t v = (int64_t)(ts->tv_sec); - enum YACErr err = YACErrNo; + enum KEKSErr err = KEKSErrNo; { int64_t diff = 10; - for (int64_t i = 0; i < YACLeapsecsN; i++) { - if (v < YACLeapsecs[i]) { + for (int64_t i = 0; i < KEKSLeapsecsN; i++) { + if (v < KEKSLeapsecs[i]) { break; } diff++; - if (v == YACLeapsecs[i]) { - err = YACErrTAI64IsLeap; + if (v == KEKSLeapsecs[i]) { + err = KEKSErrTAI64IsLeap; break; } } v -= diff; } if (v <= 0) { - return YACErrTAI64InPast; + return KEKSErrTAI64InPast; } ts->tv_sec = (time_t)v; return err; diff --git a/c/lib/dectai.h b/c/lib/dectai.h new file mode 100644 index 0000000..49a69d9 --- /dev/null +++ b/c/lib/dectai.h @@ -0,0 +1,31 @@ +#ifndef KEKS_DECTAI_H +#define KEKS_DECTAI_H + +#include +#include + +#include "err.h" + +// TEXINFO: KEKSTAI64ToTimespec +// @deftypefun {enum KEKSErr} KEKSTAI64ToTimespec @ +// (struct timespec *tv, const unsigned char *buf, const size_t len) +// Convert TAI64* value from @var{buf} to @var{ts} structure. +// @code{KEKSErrTAI64InPast} error is returned if value represents time +// before 1970. Some systems support those dates, but not guaranteed to. +// @code{KEKSErrTAI64TooBig} error is returned when time is out of bounds +// of @code{time_t} representation. @code{KEKSErrTAI64BadAsec} is +// returned if TAI64NA is provided, because currently no systems support +// attoseconds. +// @end deftypefun +enum KEKSErr +KEKSTAI64ToTimespec(struct timespec *ts, const unsigned char *buf, const size_t len); + +// TEXINFO: KEKSTimespecToUTC +// @deftypefun {enum KEKSErr} KEKSTimespecToUTC (struct timespec *ts) +// Convert TAI stored in @var{ts} structure to UTC. @code{KEKSErrTAI64InPast} +// error is returned if value represents time before 1970. +// @end deftypefun +enum KEKSErr +KEKSTimespecToUTC(struct timespec *ts); + +#endif // KEKS_DECTAI_H diff --git a/cyac/lib/default.o.do b/c/lib/default.o.do similarity index 100% rename from cyac/lib/default.o.do rename to c/lib/default.o.do diff --git a/cyac/lib/enc.c b/c/lib/enc.c similarity index 69% rename from cyac/lib/enc.c rename to c/lib/enc.c index 55c01f8..a1a2456 100644 --- a/cyac/lib/enc.c +++ b/c/lib/enc.c @@ -1,4 +1,4 @@ -// cyac -- C YAC encoder implementation +// ckeks -- C KEKS encoder implementation // Copyright (C) 2024-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify @@ -23,40 +23,40 @@ #include "tobe.h" bool -YACAtomEOCEncode(size_t *len, unsigned char *buf, const size_t cap) +KEKSAtomEOCEncode(size_t *len, unsigned char *buf, const size_t cap) { (*len) = 1; if (cap < 1) { return false; } - buf[0] = YACAtomEOC; + buf[0] = KEKSAtomEOC; return true; } bool -YACAtomNILEncode(size_t *len, unsigned char *buf, const size_t cap) +KEKSAtomNILEncode(size_t *len, unsigned char *buf, const size_t cap) { (*len) = 1; if (cap < 1) { return false; } - buf[0] = YACAtomNIL; + buf[0] = KEKSAtomNIL; return true; } bool -YACAtomBoolEncode(size_t *len, unsigned char *buf, const size_t cap, const bool v) +KEKSAtomBoolEncode(size_t *len, unsigned char *buf, const size_t cap, const bool v) { (*len) = 1; if (cap < 1) { return false; } - buf[0] = v ? YACAtomTrue : YACAtomFalse; + buf[0] = v ? KEKSAtomTrue : KEKSAtomFalse; return true; } bool -YACAtomUUIDEncode( +KEKSAtomUUIDEncode( size_t *len, unsigned char *buf, const size_t cap, @@ -66,20 +66,20 @@ YACAtomUUIDEncode( if (cap < (1 + 16)) { return false; } - buf[0] = YACAtomUUID; + buf[0] = KEKSAtomUUID; memcpy(buf + 1, v, 16); return true; } static bool -yacAtomIntEncode(size_t *len, unsigned char *buf, const size_t cap, const uint64_t v) +keksAtomIntEncode(size_t *len, unsigned char *buf, const size_t cap, const uint64_t v) { if (cap < 1) { return false; } if (v == 0) { const bool ok = - YACAtomBinEncode(len, buf + 1, cap - 1, (const unsigned char *)"", 0); + KEKSAtomBinEncode(len, buf + 1, cap - 1, (const unsigned char *)"", 0); (*len)++; return ok; } @@ -91,60 +91,60 @@ yacAtomIntEncode(size_t *len, unsigned char *buf, const size_t cap, const uint64 } l++; unsigned char be[8] = {0}; - yacToBE(be, l, v); - const bool ok = YACAtomBinEncode(len, buf + 1, cap - 1, be, l); + keksToBE(be, l, v); + const bool ok = KEKSAtomBinEncode(len, buf + 1, cap - 1, be, l); (*len)++; return ok; } bool -YACAtomUintEncode(size_t *len, unsigned char *buf, const size_t cap, const uint64_t v) +KEKSAtomUintEncode(size_t *len, unsigned char *buf, const size_t cap, const uint64_t v) { - bool ok = yacAtomIntEncode(len, buf, cap, v); + bool ok = keksAtomIntEncode(len, buf, cap, v); if (ok) { - buf[0] = YACAtomPint; + buf[0] = KEKSAtomPint; } return ok; } bool -YACAtomSintEncode(size_t *len, unsigned char *buf, const size_t cap, const int64_t v) +KEKSAtomSintEncode(size_t *len, unsigned char *buf, const size_t cap, const int64_t v) { if (v >= 0) { - return YACAtomUintEncode(len, buf, cap, (uint64_t)v); + return KEKSAtomUintEncode(len, buf, cap, (uint64_t)v); } const uint64_t vp = (uint64_t)(-(v + 1)); - bool ok = yacAtomIntEncode(len, buf, cap, vp); + bool ok = keksAtomIntEncode(len, buf, cap, vp); if (ok) { - buf[0] = YACAtomNint; + buf[0] = KEKSAtomNint; } return ok; } bool -YACAtomListEncode(size_t *len, unsigned char *buf, const size_t cap) +KEKSAtomListEncode(size_t *len, unsigned char *buf, const size_t cap) { (*len) = 1; if (cap < 1) { return false; } - buf[0] = YACAtomList; + buf[0] = KEKSAtomList; return true; } bool -YACAtomMapEncode(size_t *len, unsigned char *buf, const size_t cap) +KEKSAtomMapEncode(size_t *len, unsigned char *buf, const size_t cap) { (*len) = 1; if (cap < 1) { return false; } - buf[0] = YACAtomMap; + buf[0] = KEKSAtomMap; return true; } bool -YACAtomBlobEncode( +KEKSAtomBlobEncode( size_t *len, unsigned char *buf, const size_t cap, @@ -154,13 +154,13 @@ YACAtomBlobEncode( if (cap < 1 + 8) { return false; } - buf[0] = YACAtomBlob; - yacToBE(buf + 1, 8, (uint64_t)chunkLen - 1); + buf[0] = KEKSAtomBlob; + keksToBE(buf + 1, 8, (uint64_t)chunkLen - 1); return true; } static bool -yacAtomStrEncode( +keksAtomStrEncode( size_t *len, unsigned char *buf, const size_t cap, @@ -174,11 +174,11 @@ yacAtomStrEncode( if (srcLen >= (63 + 255 + 65535)) { lVal = 63; lLen = 8; - yacToBE(lBuf, 8, (uint64_t)srcLen - (63 + 255 + 65535)); + keksToBE(lBuf, 8, (uint64_t)srcLen - (63 + 255 + 65535)); } else if (srcLen >= (62 + 255)) { lVal = 62; lLen = 2; - yacToBE(lBuf, 2, (uint64_t)srcLen - (62 + 255)); + keksToBE(lBuf, 2, (uint64_t)srcLen - (62 + 255)); } else if (srcLen >= 61) { lVal = 61; lLen = 1; @@ -194,9 +194,9 @@ yacAtomStrEncode( if (cap < (*len)) { return false; } - buf[0] = (uint8_t)YACAtomStrings | lVal; + buf[0] = (uint8_t)KEKSAtomStrings | lVal; if (utf8) { - buf[0] |= (unsigned char)YACAtomIsUTF8; + buf[0] |= (unsigned char)KEKSAtomIsUTF8; } memcpy(buf + 1, lBuf, lLen); memcpy(buf + 1 + lLen, src, srcLen); @@ -204,29 +204,29 @@ yacAtomStrEncode( } bool -YACAtomStrEncode( +KEKSAtomStrEncode( size_t *len, unsigned char *buf, const size_t cap, const unsigned char *src, const size_t srcLen) { - return yacAtomStrEncode(len, buf, cap, src, srcLen, true); + return keksAtomStrEncode(len, buf, cap, src, srcLen, true); } bool -YACAtomBinEncode( +KEKSAtomBinEncode( size_t *len, unsigned char *buf, const size_t cap, const unsigned char *src, const size_t srcLen) { - return yacAtomStrEncode(len, buf, cap, src, srcLen, false); + return keksAtomStrEncode(len, buf, cap, src, srcLen, false); } bool -YACAtomChunkEncode( +KEKSAtomChunkEncode( size_t *len, unsigned char *buf, const size_t cap, @@ -241,13 +241,13 @@ YACAtomChunkEncode( if (cap < (*len)) { return false; } - buf[0] = YACAtomNIL; + buf[0] = KEKSAtomNIL; memcpy(buf + 1, src, srcLen); return true; } bool -YACAtomTAI64Encode( +KEKSAtomTAI64Encode( size_t *len, unsigned char *buf, const size_t cap, @@ -260,13 +260,13 @@ YACAtomTAI64Encode( } switch (srcLen) { case 8: - buf[0] = YACAtomTAI64; + buf[0] = KEKSAtomTAI64; break; case 12: - buf[0] = YACAtomTAI64N; + buf[0] = KEKSAtomTAI64N; break; case 16: - buf[0] = YACAtomTAI64NA; + buf[0] = KEKSAtomTAI64NA; break; default: return 0; @@ -276,7 +276,7 @@ YACAtomTAI64Encode( } bool -YACAtomRawEncode( +KEKSAtomRawEncode( size_t *len, unsigned char *buf, const size_t cap, diff --git a/cyac/lib/enc.h b/c/lib/enc.h similarity index 73% rename from cyac/lib/enc.h rename to c/lib/enc.h index 1055c72..bb44240 100644 --- a/cyac/lib/enc.h +++ b/c/lib/enc.h @@ -1,56 +1,56 @@ -#ifndef YAC_ENC_H -#define YAC_ENC_H +#ifndef KEKS_ENC_H +#define KEKS_ENC_H #include #include #include -// TEXINFO: YACAtomEOCEncode -// @deftypefun bool YACAtomEOCEncode @ +// TEXINFO: KEKSAtomEOCEncode +// @deftypefun bool KEKSAtomEOCEncode @ // (size_t *len, unsigned char *buf, const size_t cap) // Encode EOC atom in provided @var{buf} with capacity of @var{cap}. // In case of success, true is returned and @var{len} will hold how many // bytes were written to buffer. // @end deftypefun bool -YACAtomEOCEncode(size_t *len, unsigned char *buf, const size_t cap); +KEKSAtomEOCEncode(size_t *len, unsigned char *buf, const size_t cap); -// TEXINFO: YACAtomNILEncode -// @deftypefun bool YACAtomNILEncode @ +// TEXINFO: KEKSAtomNILEncode +// @deftypefun bool KEKSAtomNILEncode @ // (size_t *len, unsigned char *buf, const size_t cap) // Encode NUL atom in provided @var{buf} with capacity of @var{cap}. // In case of success, true is returned and @var{len} will hold how many // bytes were written to buffer. // @end deftypefun bool -YACAtomNILEncode(size_t *len, unsigned char *buf, const size_t cap); +KEKSAtomNILEncode(size_t *len, unsigned char *buf, const size_t cap); -// TEXINFO: YACAtomBoolEncode -// @deftypefun bool YACAtomBoolEncode @ +// TEXINFO: KEKSAtomBoolEncode +// @deftypefun bool KEKSAtomBoolEncode @ // (size_t *len, unsigned char *buf, const size_t cap, const bool v) // Encode boolean atom in provided @var{buf} with capacity of @var{cap}. // In case of success, true is returned and @var{len} will hold how many // bytes were written to buffer. // @end deftypefun bool -YACAtomBoolEncode(size_t *len, unsigned char *buf, const size_t cap, const bool v); +KEKSAtomBoolEncode(size_t *len, unsigned char *buf, const size_t cap, const bool v); -// TEXINFO: YACAtomUUIDEncode -// @deftypefun bool YACAtomUUIDEncode @ +// TEXINFO: KEKSAtomUUIDEncode +// @deftypefun bool KEKSAtomUUIDEncode @ // (size_t *len, unsigned char *buf, const size_t cap, const unsigned char v[16]) // Encode UUID atom in provided @var{buf} with capacity of @var{cap}. // In case of success, true is returned and @var{len} will hold how many // bytes were written to buffer. // @end deftypefun bool -YACAtomUUIDEncode( +KEKSAtomUUIDEncode( size_t *len, unsigned char *buf, const size_t cap, const unsigned char v[16]); -// TEXINFO: YACAtomUintEncode -// @deftypefun bool YACAtomUintEncode @ +// TEXINFO: KEKSAtomUintEncode +// @deftypefun bool KEKSAtomUintEncode @ // (size_t *len, unsigned char *buf, const size_t cap, const uint64_t v) // Encode positive integer atom in provided @var{buf} with capacity of // @var{cap}. @@ -58,10 +58,10 @@ YACAtomUUIDEncode( // bytes were written to buffer. // @end deftypefun bool -YACAtomUintEncode(size_t *len, unsigned char *buf, const size_t cap, const uint64_t v); +KEKSAtomUintEncode(size_t *len, unsigned char *buf, const size_t cap, const uint64_t v); -// TEXINFO: YACAtomSintEncode -// @deftypefun bool YACAtomSintEncode @ +// TEXINFO: KEKSAtomSintEncode +// @deftypefun bool KEKSAtomSintEncode @ // (size_t *len, unsigned char *buf, const size_t cap, const int64_t v) // Encode signed integer atom in provided @var{buf} with capacity of // @var{cap}. If it is zero or positive, then it encodes unsigned one. @@ -70,46 +70,46 @@ YACAtomUintEncode(size_t *len, unsigned char *buf, const size_t cap, const uint6 // bytes were written to buffer. // @end deftypefun bool -YACAtomSintEncode(size_t *len, unsigned char *buf, const size_t cap, const int64_t v); +KEKSAtomSintEncode(size_t *len, unsigned char *buf, const size_t cap, const int64_t v); -// TEXINFO: YACAtomListEncode -// @deftypefun bool YACAtomListEncode @ +// TEXINFO: KEKSAtomListEncode +// @deftypefun bool KEKSAtomListEncode @ // (size_t *len, unsigned char *buf, const size_t cap) // Encode LIST atom in provided @var{buf} with capacity of @var{cap}. // In case of success, true is returned and @var{len} will hold how many // bytes were written to buffer. Do not forget to add EOC atom at the end. // @end deftypefun bool -YACAtomListEncode(size_t *len, unsigned char *buf, const size_t cap); +KEKSAtomListEncode(size_t *len, unsigned char *buf, const size_t cap); -// TEXINFO: YACAtomMapEncode -// @deftypefun bool YACAtomMapEncode @ +// TEXINFO: KEKSAtomMapEncode +// @deftypefun bool KEKSAtomMapEncode @ // (size_t *len, unsigned char *buf, const size_t cap) // Encode MAP atom in provided @var{buf} with capacity of @var{cap}. // In case of success, true is returned and @var{len} will hold how many // bytes were written to buffer. Do not forget to add EOC atom at the end. // @end deftypefun bool -YACAtomMapEncode(size_t *len, unsigned char *buf, const size_t cap); +KEKSAtomMapEncode(size_t *len, unsigned char *buf, const size_t cap); -// TEXINFO: YACAtomBlobEncode -// @deftypefun bool YACAtomBlobEncode @ +// TEXINFO: KEKSAtomBlobEncode +// @deftypefun bool KEKSAtomBlobEncode @ // (size_t *len, unsigned char *buf, const size_t cap, const size_t chunkLen) // Encode BLOB atom in provided @var{buf} with capacity of @var{cap}. // In case of success, true is returned and @var{len} will hold how many -// bytes were written to buffer. You must call @ref{YACAtomChunkEncode} +// bytes were written to buffer. You must call @ref{KEKSAtomChunkEncode} // functions for subsequent chunks, and terminate the blob with -// @ref{YACAtomBinEncode}. +// @ref{KEKSAtomBinEncode}. // @end deftypefun bool -YACAtomBlobEncode( +KEKSAtomBlobEncode( size_t *len, unsigned char *buf, const size_t cap, const size_t chunkLen); -// TEXINFO: YACAtomStrEncode -// @deftypefun bool YACAtomStrEncode @ +// TEXINFO: KEKSAtomStrEncode +// @deftypefun bool KEKSAtomStrEncode @ // (size_t *len, unsigned char *buf, const size_t cap, @ // const unsigned char *src, const size_t srcLen) // Encode STR atom in provided @var{buf} with capacity of @var{cap}. @@ -117,15 +117,15 @@ YACAtomBlobEncode( // bytes were written to buffer. // @end deftypefun bool -YACAtomStrEncode( +KEKSAtomStrEncode( size_t *len, unsigned char *buf, const size_t cap, const unsigned char *src, const size_t srcLen); -// TEXINFO: YACAtomBinEncode -// @deftypefun bool YACAtomBinEncode @ +// TEXINFO: KEKSAtomBinEncode +// @deftypefun bool KEKSAtomBinEncode @ // (size_t *len, unsigned char *buf, const size_t cap, @ // const unsigned char *src, const size_t srcLen) // Encode BIN atom in provided @var{buf} with capacity of @var{cap}. @@ -133,32 +133,32 @@ YACAtomStrEncode( // bytes were written to buffer. // @end deftypefun bool -YACAtomBinEncode( +KEKSAtomBinEncode( size_t *len, unsigned char *buf, const size_t cap, const unsigned char *src, const size_t srcLen); -// TEXINFO: YACAtomChunkEncode -// @deftypefun bool YACAtomChunkEncode @ +// TEXINFO: KEKSAtomChunkEncode +// @deftypefun bool KEKSAtomChunkEncode @ // (size_t *len, unsigned char *buf, const size_t cap, @ // const unsigned char *src, const size_t srcLen) // Encode the chunk in provided @var{buf} with capacity of @var{cap}. // In case of success, true is returned and @var{len} will hold how many // bytes were written to buffer. It is just a convenient wrapper instead -// of using @ref{YACAtomNILEncode} followed by @var{srcLen} bytes. +// of using @ref{KEKSAtomNILEncode} followed by @var{srcLen} bytes. // @end deftypefun bool -YACAtomChunkEncode( +KEKSAtomChunkEncode( size_t *len, unsigned char *buf, const size_t cap, const unsigned char *src, const size_t srcLen); -// TEXINFO: YACAtomTAI64Encode -// @deftypefun bool YACAtomTAI64Encode @ +// TEXINFO: KEKSAtomTAI64Encode +// @deftypefun bool KEKSAtomTAI64Encode @ // (size_t *len, unsigned char *buf, const size_t cap, @ // const unsigned char *src, const size_t srcLen) // Encode the TAI64* atom in provided @var{buf} with capacity of @var{cap}. @@ -167,15 +167,15 @@ YACAtomChunkEncode( // 16 byte string. // @end deftypefun bool -YACAtomTAI64Encode( +KEKSAtomTAI64Encode( size_t *len, unsigned char *buf, const size_t cap, const unsigned char *src, const size_t srcLen); -// TEXINFO: YACAtomRawEncode -// @deftypefun bool YACAtomRawEncode @ +// TEXINFO: KEKSAtomRawEncode +// @deftypefun bool KEKSAtomRawEncode @ // (size_t *len, unsigned char *buf, const size_t cap, @ // const unsigned char typ, const unsigned char *src, const size_t srcLen) // Encode raw atom in provided @var{buf} with capacity of @var{cap}. @@ -184,7 +184,7 @@ YACAtomTAI64Encode( // of manual writing of the @code{typ} byte followed by @var{srcLen} bytes. // @end deftypefun bool -YACAtomRawEncode( +KEKSAtomRawEncode( size_t *len, unsigned char *buf, const size_t cap, @@ -192,4 +192,4 @@ YACAtomRawEncode( const unsigned char *src, const size_t srcLen); -#endif // YAC_ENC_H +#endif // KEKS_ENC_H diff --git a/cyac/lib/enctai.c b/c/lib/enctai.c similarity index 79% rename from cyac/lib/enctai.c rename to c/lib/enctai.c index eab6f7f..414c976 100644 --- a/cyac/lib/enctai.c +++ b/c/lib/enctai.c @@ -1,4 +1,4 @@ -// cyac -- C YAC encoder implementation +// ckeks -- C KEKS encoder implementation // Copyright (C) 2024-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify @@ -21,26 +21,26 @@ #include "tobe.h" bool -YACTimespecToTAI64(unsigned char *buf, const struct timespec *ts) +KEKSTimespecToTAI64(unsigned char *buf, const struct timespec *ts) { int64_t v = (int64_t)(ts->tv_sec); uint64_t val = (uint64_t)v + 0x4000000000000000; if (val <= (uint64_t)v) { return false; } - yacToBE(buf, 8, val); + keksToBE(buf, 8, val); if (ts->tv_nsec != 0) { - yacToBE(buf + 8, 4, (uint64_t)(ts->tv_nsec)); + keksToBE(buf + 8, 4, (uint64_t)(ts->tv_nsec)); } return true; } bool -YACTimespecToTAI(struct timespec *ts) +KEKSTimespecToTAI(struct timespec *ts) { int64_t v = 10 + (int64_t)(ts->tv_sec); - for (int64_t i = 0; i < YACLeapsecsN; i++) { - if (v >= YACLeapsecs[i]) { + for (int64_t i = 0; i < KEKSLeapsecsN; i++) { + if (v >= KEKSLeapsecs[i]) { v++; } } diff --git a/cyac/lib/enctai.h b/c/lib/enctai.h similarity index 60% rename from cyac/lib/enctai.h rename to c/lib/enctai.h index a790bb9..6bd612d 100644 --- a/cyac/lib/enctai.h +++ b/c/lib/enctai.h @@ -1,11 +1,11 @@ -#ifndef YAC_ENCTAI_H -#define YAC_ENCTAI_H +#ifndef KEKS_ENCTAI_H +#define KEKS_ENCTAI_H #include #include -// TEXINFO: YACTimespecToTAI64 -// @deftypefun bool YACTimespecToTAI64 @ +// TEXINFO: KEKSTimespecToTAI64 +// @deftypefun bool KEKSTimespecToTAI64 @ // (unsigned char *buf, const struct timespec *ts) // Convert @var{ts} structure to TAI64/TAI64N in the @var{buf}. // If @var{ts} contains non zero nanoseconds count, then be sure that @@ -13,14 +13,14 @@ // False is returned if represented time is out of allowable bounds. // @end deftypefun bool -YACTimespecToTAI64(unsigned char *buf, const struct timespec *ts); +KEKSTimespecToTAI64(unsigned char *buf, const struct timespec *ts); -// TEXINFO: YACTimespecToTAI -// @deftypefun bool YACTimespecToTAI (struct timespec *ts) +// TEXINFO: KEKSTimespecToTAI +// @deftypefun bool KEKSTimespecToTAI (struct timespec *ts) // Convert UTC stored in @var{ts} structure to TAI. // False is returned if represented time is out of allowable bounds. // @end deftypefun bool -YACTimespecToTAI(struct timespec *ts); +KEKSTimespecToTAI(struct timespec *ts); -#endif // YAC_ENCTAI_H +#endif // KEKS_ENCTAI_H diff --git a/cyac/lib/err.c b/c/lib/err.c similarity index 53% rename from cyac/lib/err.c rename to c/lib/err.c index 0c638c2..5455700 100644 --- a/cyac/lib/err.c +++ b/c/lib/err.c @@ -1,52 +1,52 @@ #include "err.h" const char * -YACErr2Str(const enum YACErr err) +KEKSErr2Str(const enum KEKSErr err) { switch (err) { - case YACErrInvalid: + case KEKSErrInvalid: return "Invalid"; - case YACErrNo: + case KEKSErrNo: return "No"; - case YACErrNotEnough: + case KEKSErrNotEnough: return "NotEnough"; - case YACErrUnknownType: + case KEKSErrUnknownType: return "UnknownType"; - case YACErrLenTooBig: + case KEKSErrLenTooBig: return "LenTooBig"; - case YACErrBadUTF8: + case KEKSErrBadUTF8: return "BadUTF8"; - case YACErrIntNonBin: + case KEKSErrIntNonBin: return "IntNonBin"; - case YACErrIntNonMinimal: + case KEKSErrIntNonMinimal: return "IntNonMinimal"; - case YACErrBlobBadAtom: + case KEKSErrBlobBadAtom: return "BlobBadAtom"; - case YACErrBlobBadTerm: + case KEKSErrBlobBadTerm: return "BlobBadTerm"; - case YACErrTAI64TooBig: + case KEKSErrTAI64TooBig: return "TAI64TooBig"; - case YACErrTAI64BadNsec: + case KEKSErrTAI64BadNsec: return "TAI64BadNsec"; - case YACErrTAI64BadAsec: + case KEKSErrTAI64BadAsec: return "TAI64BadAsec"; - case YACErrTAI64InPast: + case KEKSErrTAI64InPast: return "TAI64InPast"; - case YACErrTAI64IsLeap: + case KEKSErrTAI64IsLeap: return "TAI64IsLeap"; - case YACErrTAI64NonMinimal: + case KEKSErrTAI64NonMinimal: return "TAI64NonMinimal"; - case YACErrMapBadKey: + case KEKSErrMapBadKey: return "MapBadKey"; - case YACErrMapUnordered: + case KEKSErrMapUnordered: return "MapUnordered"; - case YACErrNoMem: + case KEKSErrNoMem: return "NoMem"; - case YACErrUnsatisfiedSchema: + case KEKSErrUnsatisfiedSchema: return "UnsatisfiedSchema"; - case YACErrDeepRecursion: + case KEKSErrDeepRecursion: return "DeepRecursion"; - case YACErrUnexpectedEOC: + case KEKSErrUnexpectedEOC: return "UnexpectedEOC"; default: return "unknown"; diff --git a/c/lib/err.h b/c/lib/err.h new file mode 100644 index 0000000..3bc111c --- /dev/null +++ b/c/lib/err.h @@ -0,0 +1,78 @@ +#ifndef KEKS_ERR_H +#define KEKS_ERR_H + +// TEXINFO: KEKSErr +// @deftp {Data type} {enum KEKSErr} +// Errors are just a predefined enumeration value. +// @table @code +// @item KEKSErrInvalid +// Unset error, must be never met. +// @item KEKSErrNo +// No error, everything is good. +// @item KEKSErrNotEnough +// Not enough data. Atom's @code{.off} must contain how much. +// @item KEKSErrUnknownType, // unknown atom's type +// Unknown atom's type. +// @item KEKSErrLenTooBig, +// Too long string (>1<<60), can not be decoded. +// @item KEKSErrBadUTF8 +// Invalid UTF-8 codepoint or zero byte met. +// @item KEKSErrIntNonMinimal +// Non minimal integer encoding. +// @item KEKSErrBlobBadAtom +// Blob contains unexpected atom. +// @item KEKSErrBlobBadTerm +// Blob contains invalid terminator. +// @item KEKSErrTAI64TooBig +// Too large TAI64 value, out-of-bounds. +// @item KEKSErrTAI64BadNsec +// Invalid TAI64 nanoseconds value. +// @item KEKSErrTAI64BadAsec +// Invalid TAI64 attoseconds value. +// @item KEKSErrMapBadKey +// Either bad type of map's key, or it is empty. +// @item KEKSErrMapUnordered +// Unordered map keys. +// @item KEKSErrNoMem +// Not enough memory for allocation. +// @item KEKSErrUnsatisfiedSchema +// Unsatisfied structure's schema. +// @item KEKSErrDeepRecursion +// Too deep recursion involved during parsing. +// @item KEKSErrUnexpectedEOC +// Unexpected EOC met. +// @end table +// @end deftp +enum KEKSErr { + KEKSErrInvalid = 0, + KEKSErrNo = 1, + KEKSErrNotEnough, + KEKSErrUnknownType, + KEKSErrLenTooBig, + KEKSErrBadUTF8, + KEKSErrIntNonBin, + KEKSErrIntNonMinimal, + KEKSErrBlobBadAtom, + KEKSErrBlobBadTerm, + KEKSErrTAI64TooBig, + KEKSErrTAI64BadNsec, + KEKSErrTAI64BadAsec, + KEKSErrTAI64InPast, + KEKSErrTAI64IsLeap, + KEKSErrTAI64NonMinimal, + KEKSErrMapBadKey, + KEKSErrMapUnordered, + KEKSErrNoMem, + KEKSErrUnsatisfiedSchema, + KEKSErrDeepRecursion, + KEKSErrUnexpectedEOC, +}; + +// TEXINFO: KEKSErr2Str +// @deftypefun {const char *} KEKSErr2Str (const enum KEKSErr) +// Get human-readable string of the error. +// @end deftypefun +const char * +KEKSErr2Str(const enum KEKSErr); + +#endif // KEKS_ERR_H diff --git a/cyac/lib/frombe.c b/c/lib/frombe.c similarity index 97% rename from cyac/lib/frombe.c rename to c/lib/frombe.c index d194cb4..b535b39 100644 --- a/cyac/lib/frombe.c +++ b/c/lib/frombe.c @@ -4,7 +4,7 @@ #include "frombe.h" uint64_t -yacFromBE(const unsigned char *buf, const size_t len) +keksFromBE(const unsigned char *buf, const size_t len) { uint64_t v = 0; switch (len) { diff --git a/c/lib/frombe.h b/c/lib/frombe.h new file mode 100644 index 0000000..8038000 --- /dev/null +++ b/c/lib/frombe.h @@ -0,0 +1,11 @@ +#ifndef KEKS_FROMBE_H +#define KEKS_FROMBE_H + +#include +#include + +// Decode big-endian integer of the length @var{len}. +uint64_t +keksFromBE(const unsigned char *buf, const size_t len); + +#endif // KEKS_FROMBE_H diff --git a/cyac/lib/h-extract.pl b/c/lib/h-extract.pl similarity index 100% rename from cyac/lib/h-extract.pl rename to c/lib/h-extract.pl diff --git a/c/lib/install.do b/c/lib/install.do new file mode 100644 index 0000000..a24b107 --- /dev/null +++ b/c/lib/install.do @@ -0,0 +1,6 @@ +redo-ifchange *.h libkeks.a ../conf/prefix +read PREFIX <../conf/prefix +mkdir -p $PREFIX/include/keks $PREFIX/lib +cp -f *.h $PREFIX/include/keks +cp -f libkeks.a $PREFIX/lib +chmod 644 $PREFIX/include/keks/*.h $PREFIX/lib/libkeks.a diff --git a/cyac/lib/items.c b/c/lib/items.c similarity index 64% rename from cyac/lib/items.c rename to c/lib/items.c index a6c57d5..015a568 100644 --- a/cyac/lib/items.c +++ b/c/lib/items.c @@ -1,4 +1,4 @@ -// cyac -- C YAC encoder implementation +// ckeks -- C KEKS encoder implementation // Copyright (C) 2024-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify @@ -25,98 +25,98 @@ #include "err.h" #include "items.h" -static const ptrdiff_t yacItemsPoolGrowLen = 64; +static const ptrdiff_t keksItemsPoolGrowLen = 64; static const size_t parseMaxRecursionDepth = 1024; -enum YACErr -YACItemsInit(struct YACItems *items) +enum KEKSErr +KEKSItemsInit(struct KEKSItems *items) { items->len = 0; - items->cap = yacItemsPoolGrowLen; - items->list = calloc((size_t)(items->cap), sizeof(struct YACItem)); + items->cap = keksItemsPoolGrowLen; + items->list = calloc((size_t)(items->cap), sizeof(struct KEKSItem)); if (items->list == NULL) { - return YACErrNoMem; + return KEKSErrNoMem; } items->offsets = calloc((size_t)(items->cap), sizeof(size_t)); if (items->offsets == NULL) { - return YACErrNoMem; + return KEKSErrNoMem; } - return YACErrNo; + return KEKSErrNo; } -enum YACErr -YACItemsGrow(struct YACItems *items) +enum KEKSErr +KEKSItemsGrow(struct KEKSItems *items) { if (items->cap == -1) { - return YACErrNoMem; + return KEKSErrNoMem; } - if ((SIZE_MAX - yacItemsPoolGrowLen) < (size_t)(items->cap)) { - return YACErrNoMem; + if ((SIZE_MAX - keksItemsPoolGrowLen) < (size_t)(items->cap)) { + return KEKSErrNoMem; } - items->cap += yacItemsPoolGrowLen; + items->cap += keksItemsPoolGrowLen; { - const ptrdiff_t possibleN = SIZE_MAX / sizeof(struct YACItem); + const ptrdiff_t possibleN = SIZE_MAX / sizeof(struct KEKSItem); if (items->cap > possibleN) { - return YACErrNoMem; + return KEKSErrNoMem; } } - size_t size = (size_t)(items->cap) * sizeof(struct YACItem); + size_t size = (size_t)(items->cap) * sizeof(struct KEKSItem); items->list = realloc(items->list, size); if (items->list == NULL) { - return YACErrNoMem; + return KEKSErrNoMem; } - size_t begin = items->len * sizeof(struct YACItem); + size_t begin = items->len * sizeof(struct KEKSItem); memset((unsigned char *)(items->list) + begin, 0, size - begin); if (items->offsets != NULL) { size = (size_t)(items->cap) * sizeof(size_t); items->offsets = realloc(items->offsets, size); if (items->offsets == NULL) { - return YACErrNoMem; + return KEKSErrNoMem; } begin = items->len * sizeof(size_t); memset((unsigned char *)(items->offsets) + begin, 0, size - begin); } - return YACErrNo; + return KEKSErrNo; } -static enum YACErr -yacItemsAdd( - struct YACItems *items, +static enum KEKSErr +keksItemsAdd( + struct KEKSItems *items, size_t *off, const unsigned char *buf, const size_t len) { - enum YACErr err = YACErrInvalid; + enum KEKSErr err = KEKSErrInvalid; if (items->len == (size_t)(items->cap)) { - err = YACItemsGrow(items); - if (err != YACErrNo) { + err = KEKSItemsGrow(items); + if (err != KEKSErrNo) { return err; } } - struct YACItem *item = &(items->list[items->len]); + struct KEKSItem *item = &(items->list[items->len]); item->next = 0; if (items->offsets != NULL) { items->offsets[items->len] = *off; } size_t got = 0; assert(len >= (*off)); - err = YACAtomDecode(&got, &(item->atom), buf + *off, len - (*off)); - if (err != YACErrNo) { + err = KEKSAtomDecode(&got, &(item->atom), buf + *off, len - (*off)); + if (err != KEKSErrNo) { return err; } if ((SIZE_MAX - got) < (*off)) { - return YACErrLenTooBig; + return KEKSErrLenTooBig; } (*off) += got; items->len++; - return YACErrNo; + return KEKSErrNo; } -static enum YACErr -yacItemsParse( // NOLINT(misc-no-recursion) - struct YACItems *items, +static enum KEKSErr +keksItemsParse( // NOLINT(misc-no-recursion) + struct KEKSItems *items, size_t *off, const unsigned char *buf, const size_t len, @@ -124,20 +124,20 @@ yacItemsParse( // NOLINT(misc-no-recursion) const size_t recursionDepth) { if (recursionDepth >= parseMaxRecursionDepth) { - return YACErrDeepRecursion; + return KEKSErrDeepRecursion; } size_t item = items->len; - enum YACErr err = yacItemsAdd(items, off, buf, len); - if (err != YACErrNo) { + enum KEKSErr err = keksItemsAdd(items, off, buf, len); + if (err != KEKSErrNo) { return err; } #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wswitch-enum" switch (items->list[item].atom.typ) { #pragma clang diagnostic pop - case YACItemList: { + case KEKSItemList: { if (!allowContainers) { - return YACErrUnknownType; + return KEKSErrUnknownType; } items->list[item].atom.v.list.head = item + 1; items->list[item].atom.v.list.len = 0; @@ -145,16 +145,16 @@ yacItemsParse( // NOLINT(misc-no-recursion) size_t cur = 0; size_t idx = item; for (;;) { - err = yacItemsParse(items, off, buf, len, true, recursionDepth + 1); - if (err != YACErrNo) { + err = keksItemsParse(items, off, buf, len, true, recursionDepth + 1); + if (err != KEKSErrNo) { return err; } cur = idx + 1; - if (items->list[cur].atom.typ == YACItemEOC) { + if (items->list[cur].atom.typ == KEKSItemEOC) { if (items->list[item].atom.v.list.len == 0) { items->list[item].atom.v.list.head = 0; } - return YACErrNo; + return KEKSErrNo; } if (prev != 0) { items->list[prev].next = cur; @@ -164,9 +164,9 @@ yacItemsParse( // NOLINT(misc-no-recursion) items->list[item].atom.v.list.len++; } } - case YACItemMap: { + case KEKSItemMap: { if (!allowContainers) { - return YACErrUnknownType; + return KEKSErrUnknownType; } items->list[item].atom.v.list.head = item + 1; items->list[item].atom.v.list.len = 0; @@ -176,8 +176,8 @@ yacItemsParse( // NOLINT(misc-no-recursion) size_t prevKeyLen = 0; const unsigned char *prevKey = NULL; for (;;) { - err = yacItemsParse(items, off, buf, len, false, recursionDepth + 1); - if (err != YACErrNo) { + err = keksItemsParse(items, off, buf, len, false, recursionDepth + 1); + if (err != KEKSErrNo) { return err; } cur = idx + 1; @@ -185,25 +185,25 @@ yacItemsParse( // NOLINT(misc-no-recursion) #pragma clang diagnostic ignored "-Wswitch-enum" switch (items->list[cur].atom.typ) { #pragma clang diagnostic pop - case YACItemEOC: + case KEKSItemEOC: if (items->list[item].atom.v.list.len == 0) { items->list[item].atom.v.list.head = 0; } - return YACErrNo; - case YACItemStr: + return KEKSErrNo; + case KEKSItemStr: break; default: - return YACErrMapBadKey; + return KEKSErrMapBadKey; } if (items->list[cur].atom.v.str.len == 0) { - return YACErrMapBadKey; + return KEKSErrMapBadKey; } if (items->list[cur].atom.v.str.len < prevKeyLen) { - return YACErrMapUnordered; + return KEKSErrMapUnordered; } if ((items->list[cur].atom.v.str.len == prevKeyLen) && (memcmp(prevKey, items->list[cur].atom.v.str.ptr, prevKeyLen) >= 0)) { - return YACErrMapUnordered; + return KEKSErrMapUnordered; } prevKeyLen = items->list[cur].atom.v.str.len; prevKey = items->list[cur].atom.v.str.ptr; @@ -212,13 +212,13 @@ yacItemsParse( // NOLINT(misc-no-recursion) } prev = cur; idx = (items->len) - 1; - err = yacItemsParse(items, off, buf, len, true, recursionDepth + 1); - if (err != YACErrNo) { + err = keksItemsParse(items, off, buf, len, true, recursionDepth + 1); + if (err != KEKSErrNo) { return err; } cur = idx + 1; - if (items->list[cur].atom.typ == YACItemEOC) { - return YACErrUnexpectedEOC; + if (items->list[cur].atom.typ == KEKSItemEOC) { + return KEKSErrUnexpectedEOC; } items->list[prev].next = cur; prev = cur; @@ -226,9 +226,9 @@ yacItemsParse( // NOLINT(misc-no-recursion) items->list[item].atom.v.list.len++; } } - case YACItemBlob: { + case KEKSItemBlob: { if (!allowContainers) { - return YACErrUnknownType; + return KEKSErrUnknownType; } items->list[item].atom.v.blob.chunks = 0; const size_t chunkLen = items->list[item].atom.v.blob.chunkLen; @@ -237,37 +237,37 @@ yacItemsParse( // NOLINT(misc-no-recursion) size_t cur = 0; bool eoc = false; while (!eoc) { - err = yacItemsParse(items, off, buf, len, false, recursionDepth + 1); - if (err != YACErrNo) { + err = keksItemsParse(items, off, buf, len, false, recursionDepth + 1); + if (err != KEKSErrNo) { return err; } cur = idx + 1; - struct YACAtom *atom = &(items->list[cur].atom); + struct KEKSAtom *atom = &(items->list[cur].atom); #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wswitch-enum" switch (atom->typ) { #pragma clang diagnostic pop - case YACItemNIL: + case KEKSItemNIL: atom->v.str.len = chunkLen; assert(len >= (*off)); if ((len - (*off)) <= chunkLen) { - return YACErrNotEnough; + return KEKSErrNotEnough; } - atom->typ = YACItemBin; + atom->typ = KEKSItemBin; atom->v.str.ptr = buf + *off; if ((SIZE_MAX - chunkLen) < (*off)) { - return YACErrLenTooBig; + return KEKSErrLenTooBig; } (*off) += chunkLen; break; - case YACItemBin: + case KEKSItemBin: if (atom->v.str.len >= chunkLen) { - return YACErrBlobBadTerm; + return KEKSErrBlobBadTerm; } eoc = true; break; default: - return YACErrBlobBadAtom; + return KEKSErrBlobBadAtom; } if (prev != 0) { items->list[prev].next = cur; @@ -281,59 +281,59 @@ yacItemsParse( // NOLINT(misc-no-recursion) default: break; } - return YACErrNo; + return KEKSErrNo; } -enum YACErr -YACItemsParse( // NOLINT(misc-no-recursion) - struct YACItems *items, +enum KEKSErr +KEKSItemsParse( // NOLINT(misc-no-recursion) + struct KEKSItems *items, size_t *off, const unsigned char *buf, const size_t len) { - enum YACErr err = yacItemsParse(items, off, buf, len, true, 0); - if (items->list[0].atom.typ == YACItemEOC) { - err = YACErrUnexpectedEOC; + enum KEKSErr err = keksItemsParse(items, off, buf, len, true, 0); + if (items->list[0].atom.typ == KEKSItemEOC) { + err = KEKSErrUnexpectedEOC; } return err; } bool -YACItemsEncode( // NOLINT(misc-no-recursion) - const struct YACItems *items, +KEKSItemsEncode( // NOLINT(misc-no-recursion) + const struct KEKSItems *items, size_t idx, size_t *off, unsigned char *buf, const size_t cap) { - const struct YACItem *item = &(items->list[idx]); + const struct KEKSItem *item = &(items->list[idx]); size_t got = 0; bool ok = false; assert(cap >= (*off)); switch (item->atom.typ) { - case YACItemInvalid: - case YACItemEOC: + case KEKSItemInvalid: + case KEKSItemEOC: return false; - case YACItemNIL: - ok = YACAtomNILEncode(&got, buf + *off, cap - (*off)); + case KEKSItemNIL: + ok = KEKSAtomNILEncode(&got, buf + *off, cap - (*off)); break; - case YACItemFalse: - ok = YACAtomBoolEncode(&got, buf + *off, cap - (*off), false); + case KEKSItemFalse: + ok = KEKSAtomBoolEncode(&got, buf + *off, cap - (*off), false); break; - case YACItemTrue: - ok = YACAtomBoolEncode(&got, buf + *off, cap - (*off), true); + case KEKSItemTrue: + ok = KEKSAtomBoolEncode(&got, buf + *off, cap - (*off), true); break; - case YACItemUUID: - ok = YACAtomUUIDEncode(&got, buf + *off, cap - (*off), item->atom.v.uuid); + case KEKSItemUUID: + ok = KEKSAtomUUIDEncode(&got, buf + *off, cap - (*off), item->atom.v.uuid); break; - case YACItemPint: - ok = YACAtomUintEncode(&got, buf + *off, cap - (*off), item->atom.v.pint); + case KEKSItemPint: + ok = KEKSAtomUintEncode(&got, buf + *off, cap - (*off), item->atom.v.pint); break; - case YACItemNint: - ok = YACAtomSintEncode(&got, buf + *off, cap - (*off), item->atom.v.nint); + case KEKSItemNint: + ok = KEKSAtomSintEncode(&got, buf + *off, cap - (*off), item->atom.v.nint); break; - case YACItemList: - ok = YACAtomListEncode(&got, buf + *off, cap - (*off)); + case KEKSItemList: + ok = KEKSAtomListEncode(&got, buf + *off, cap - (*off)); if (!ok) { return false; } @@ -343,17 +343,17 @@ YACItemsEncode( // NOLINT(misc-no-recursion) (*off) += got; idx = item->atom.v.list.head; while (idx != 0) { - ok = YACItemsEncode(items, idx, off, buf, cap); + ok = KEKSItemsEncode(items, idx, off, buf, cap); if (!ok) { return false; } idx = items->list[idx].next; } assert(cap >= (*off)); - ok = YACAtomEOCEncode(&got, buf + *off, cap - (*off)); + ok = KEKSAtomEOCEncode(&got, buf + *off, cap - (*off)); break; - case YACItemMap: - ok = YACAtomMapEncode(&got, buf + *off, cap - (*off)); + case KEKSItemMap: + ok = KEKSAtomMapEncode(&got, buf + *off, cap - (*off)); if (!ok) { return false; } @@ -363,17 +363,17 @@ YACItemsEncode( // NOLINT(misc-no-recursion) (*off) += got; idx = item->atom.v.list.head; while (idx != 0) { - ok = YACItemsEncode(items, idx, off, buf, cap); + ok = KEKSItemsEncode(items, idx, off, buf, cap); if (!ok) { return false; } idx = items->list[idx].next; } - ok = YACAtomEOCEncode(&got, buf + *off, cap - (*off)); + ok = KEKSAtomEOCEncode(&got, buf + *off, cap - (*off)); break; - case YACItemBlob: { + case KEKSItemBlob: { const size_t chunkLen = (item->atom.v.blob.chunkLen); - ok = YACAtomBlobEncode(&got, buf + *off, cap - (*off), chunkLen); + ok = KEKSAtomBlobEncode(&got, buf + *off, cap - (*off), chunkLen); if (!ok) { return 0; } @@ -388,7 +388,7 @@ YACItemsEncode( // NOLINT(misc-no-recursion) break; } assert(cap >= (*off)); - ok = YACAtomChunkEncode( + ok = KEKSAtomChunkEncode( &got, buf + *off, cap - (*off), @@ -404,26 +404,26 @@ YACItemsEncode( // NOLINT(misc-no-recursion) continue; } assert(cap >= (*off)); - ok = YACAtomBinEncode( + ok = KEKSAtomBinEncode( &got, buf + *off, cap - (*off), item->atom.v.str.ptr, item->atom.v.str.len); break; } - case YACItemFloat: + case KEKSItemFloat: return false; - case YACItemTAI64: - ok = YACAtomTAI64Encode( + case KEKSItemTAI64: + ok = KEKSAtomTAI64Encode( &got, buf + *off, cap - (*off), item->atom.v.str.ptr, item->atom.v.str.len); break; - case YACItemBin: - ok = YACAtomBinEncode( + case KEKSItemBin: + ok = KEKSAtomBinEncode( &got, buf + *off, cap - (*off), item->atom.v.str.ptr, item->atom.v.str.len); break; - case YACItemStr: - ok = YACAtomStrEncode( + case KEKSItemStr: + ok = KEKSAtomStrEncode( &got, buf + *off, cap - (*off), item->atom.v.str.ptr, item->atom.v.str.len); break; - case YACItemRaw: - ok = YACAtomRawEncode( + case KEKSItemRaw: + ok = KEKSAtomRawEncode( &got, buf + *off, cap - (*off), @@ -445,14 +445,14 @@ YACItemsEncode( // NOLINT(misc-no-recursion) } size_t -YACItemsGetByKeyLen( - const struct YACItems *items, +KEKSItemsGetByKeyLen( + const struct KEKSItems *items, const size_t itemIdx, const char *key, const size_t keyLen) { - const struct YACItem *item = &(items->list[itemIdx]); - if (item->atom.typ != YACItemMap) { + const struct KEKSItem *item = &(items->list[itemIdx]); + if (item->atom.typ != KEKSItemMap) { return 0; } size_t idx = item->atom.v.list.head; @@ -468,19 +468,19 @@ YACItemsGetByKeyLen( } size_t -YACItemsGetByKey(const struct YACItems *items, const size_t itemIdx, const char *key) +KEKSItemsGetByKey(const struct KEKSItems *items, const size_t itemIdx, const char *key) { - return YACItemsGetByKeyLen(items, itemIdx, key, strlen(key)); + return KEKSItemsGetByKeyLen(items, itemIdx, key, strlen(key)); } size_t -YACItemsGetByKeyAndType( - const struct YACItems *items, +KEKSItemsGetByKeyAndType( + const struct KEKSItems *items, const size_t itemIdx, const char *key, - const enum YACItemType typ) + const enum KEKSItemType typ) { - const size_t idx = YACItemsGetByKey(items, itemIdx, key); + const size_t idx = KEKSItemsGetByKey(items, itemIdx, key); if ((idx == 0) || (items->list[idx].atom.typ != typ)) { return 0; } @@ -488,14 +488,17 @@ YACItemsGetByKeyAndType( } bool -YACStrEqual(const struct YACAtom *atom, const char *s) +KEKSStrEqual(const struct KEKSAtom *atom, const char *s) { return (atom->v.str.len == strlen(s)) && (memcmp(atom->v.str.ptr, s, atom->v.str.len) == 0); } bool -YACListHasOnlyType(const struct YACItems *items, size_t idx, const enum YACItemType typ) +KEKSListHasOnlyType( + const struct KEKSItems *items, + size_t idx, + const enum KEKSItemType typ) { idx = items->list[idx].atom.v.list.head; while (idx != 0) { @@ -508,7 +511,10 @@ YACListHasOnlyType(const struct YACItems *items, size_t idx, const enum YACItemT } bool -YACMapHasOnlyType(const struct YACItems *items, size_t idx, const enum YACItemType typ) +KEKSMapHasOnlyType( + const struct KEKSItems *items, + size_t idx, + const enum KEKSItemType typ) { idx = items->list[idx].atom.v.list.head; while (idx != 0) { diff --git a/cyac/lib/items.h b/c/lib/items.h similarity index 58% rename from cyac/lib/items.h rename to c/lib/items.h index fce7856..8c09624 100644 --- a/cyac/lib/items.h +++ b/c/lib/items.h @@ -1,5 +1,5 @@ -#ifndef YAC_POOL_H -#define YAC_POOL_H +#ifndef KEKS_POOL_H +#define KEKS_POOL_H #include #include @@ -7,8 +7,8 @@ #include "dec.h" #include "err.h" -// TEXINFO: YACItem -// @deftp {Data type} {struct YACItem} +// TEXINFO: KEKSItem +// @deftp {Data type} {struct KEKSItem} // Each item contain the @code{.atom} structure. But item can be a part // of the list or map, so @code{.next} contains the pool index value to // the next element of the list or map. It equals to 0, if it is the @@ -20,14 +20,14 @@ // Blob's first element always exists and it is the next binary string // item, until its length is less than chunk length. // @end deftp -struct YACItem { +struct KEKSItem { size_t next; - struct YACAtom atom; + struct KEKSAtom atom; }; -// TEXINFO: YACItems -// @deftp {Data type} {struct YACItems} -// Items pool @code{.list} contains concatenated @code{YACItem}s. Item's +// TEXINFO: KEKSItems +// @deftp {Data type} {struct KEKSItems} +// Items pool @code{.list} contains concatenated @code{KEKSItem}s. Item's // @code{.next} can be used as an index in that pool: // @code{items->list[item.next]}. // @@ -37,9 +37,9 @@ struct YACItem { // element. // // @code{.cap} and @code{.len} are capacity and length of the -// @code{.list}. If you use @ref{YACItemsParse}, then it parses the +// @code{.list}. If you use @ref{KEKSItemsParse}, then it parses the // buffer and continuously appends new items to that list. If its length -// matches with the capacity, then @ref{YACItemsGrow} is called to +// matches with the capacity, then @ref{KEKSItemsGrow} is called to // enlarge the underlying buffer, possibly reallocating the whole of it. // So be careful with the pointers to the list's items, because they // could be invalidated after the growth. Using their indices instead @@ -48,16 +48,16 @@ struct YACItem { // Corresponding @code{.offsets} store the offset of the decoded item // relative to the previously provided buffer. // @end deftp -struct YACItems { - struct YACItem *list; +struct KEKSItems { + struct KEKSItem *list; size_t *offsets; size_t len; ptrdiff_t cap; }; -// TEXINFO: YACItemsInit -// @deftypefun {enum YACErr} YACItemsInit (struct YACItems *items) -// Initialise the @ref{YACItems} structure by allocating an initial +// TEXINFO: KEKSItemsInit +// @deftypefun {enum KEKSErr} KEKSItemsInit (struct KEKSItems *items) +// Initialise the @ref{KEKSItems} structure by allocating an initial // capacity for the underlying storage. // // If you do not want to use heap allocation and want to use @@ -65,46 +65,46 @@ struct YACItems { // the proper @code{.cap}acity. // // If you do not want to store items offsets during decoding, or you use -// @ref{YACItems} only for encoding purposes, then set @code{.offsets} +// @ref{KEKSItems} only for encoding purposes, then set @code{.offsets} // to NULL (do not forget to free it, if it was initialised before). // @end deftypefun -enum YACErr -YACItemsInit(struct YACItems *); +enum KEKSErr +KEKSItemsInit(struct KEKSItems *); -// TEXINFO: YACItemsGrow -// @deftypefun {enum YACErr} YACItemsGrow (struct YACItems *items) +// TEXINFO: KEKSItemsGrow +// @deftypefun {enum KEKSErr} KEKSItemsGrow (struct KEKSItems *items) // Enlarge underlying storage of items, increasing its capacity. If // @code{.cap} equals to -1, then nothing will happen and -// @code{YACErrNoMem} error will be returned. You can use that -1 value +// @code{KEKSErrNoMem} error will be returned. You can use that -1 value // to omit attempts to call heap allocation functions. // @end deftypefun -enum YACErr -YACItemsGrow(struct YACItems *); +enum KEKSErr +KEKSItemsGrow(struct KEKSItems *); -// TEXINFO: YACItemsParse -// @deftypefun {enum YACErr} YACItemsParse ( @ -// struct YACItems *items, @ +// TEXINFO: KEKSItemsParse +// @deftypefun {enum KEKSErr} KEKSItemsParse ( @ +// struct KEKSItems *items, @ // size_t *off, @ // const unsigned char *buf, @ // const size_t len) // Parse the provided @var{buf} appending newly created linked -// @ref{YACItem}s in @var{items}. If there is not enough capacity -// available, then @ref{YACItemsGrow} is automatically called. If +// @ref{KEKSItem}s in @var{items}. If there is not enough capacity +// available, then @ref{KEKSItemsGrow} is automatically called. If // @code{.offsets} equal to NULL, then no offsets will be stored. // // @code{off}set is a position in @var{buf} from which the parsing will // be done. Its final value is the position when we stopped. // @end deftypefun -enum YACErr -YACItemsParse( - struct YACItems *, +enum KEKSErr +KEKSItemsParse( + struct KEKSItems *, size_t *off, const unsigned char *buf, const size_t len); -// TEXINFO: YACItemsEncode -// @deftypefun bool YACItemsEncode ( @ -// const struct YACItems *items, @ +// TEXINFO: KEKSItemsEncode +// @deftypefun bool KEKSItemsEncode ( @ +// const struct KEKSItems *items, @ // size_t idx, @ // size_t *off, @ // unsigned char *buf, @ @@ -115,16 +115,16 @@ YACItemsParse( // length of the encoded data. // @end deftypefun bool -YACItemsEncode( - const struct YACItems *, +KEKSItemsEncode( + const struct KEKSItems *, size_t idx, size_t *off, unsigned char *buf, const size_t cap); -// TEXINFO: YACItemsGetByKeyLen -// @deftypefun size_t YACItemsGetByKeyLen ( @ -// const struct YACItems *items, @ +// TEXINFO: KEKSItemsGetByKeyLen +// @deftypefun size_t KEKSItemsGetByKeyLen ( @ +// const struct KEKSItems *items, @ // const size_t itemIdx, @ // const char *key, @ // const size_t keyLen) @@ -132,65 +132,65 @@ YACItemsEncode( // in @var{items}'es element @var{itemIdx}. Returns zero if none found. // @end deftypefun size_t -YACItemsGetByKeyLen( - const struct YACItems *, +KEKSItemsGetByKeyLen( + const struct KEKSItems *, const size_t itemIdx, const char *key, const size_t keyLen); -// TEXINFO: YACItemsGetByKey -// @deftypefun size_t YACItemsGetByKey ( @ -// const struct YACItems *items, @ +// TEXINFO: KEKSItemsGetByKey +// @deftypefun size_t KEKSItemsGetByKey ( @ +// const struct KEKSItems *items, @ // const size_t itemIdx, @ // const char *key) // Get the index of the null-terminated key with @var{key} name in // @var{items}'es element @var{itemIdx}. Returns zero if none found. // @end deftypefun size_t -YACItemsGetByKey(const struct YACItems *, const size_t itemIdx, const char *key); +KEKSItemsGetByKey(const struct KEKSItems *, const size_t itemIdx, const char *key); -// TEXINFO: YACItemsGetByKeyAndType -// @deftypefun size_t YACItemsGetByKeyAndType ( @ -// const struct YACItems *items, @ +// TEXINFO: KEKSItemsGetByKeyAndType +// @deftypefun size_t KEKSItemsGetByKeyAndType ( @ +// const struct KEKSItems *items, @ // const size_t itemIdx, @ // const char *key, @ -// const enum YACItemType typ) -// Same as @ref{YACItemsGetByKey}, but also check that value's type is @var{typ}. +// const enum KEKSItemType typ) +// Same as @ref{KEKSItemsGetByKey}, but also check that value's type is @var{typ}. // @end deftypefun size_t -YACItemsGetByKeyAndType( - const struct YACItems *, +KEKSItemsGetByKeyAndType( + const struct KEKSItems *, const size_t itemIdx, const char *key, - const enum YACItemType typ); + const enum KEKSItemType typ); -// TEXINFO: YACStrEqual -// @deftypefun bool YACStrEqual (const struct YACAtom *atom, const char *s) +// TEXINFO: KEKSStrEqual +// @deftypefun bool KEKSStrEqual (const struct KEKSAtom *atom, const char *s) // Returns true if string atom's value equal to null-terminated @var{s}. // @end deftypefun bool -YACStrEqual(const struct YACAtom *, const char *s); +KEKSStrEqual(const struct KEKSAtom *, const char *s); -// TEXINFO: YACListHasOnlyType -// @deftypefun bool YACListHasOnlyType ( @ -// const struct YACItems *items, @ +// TEXINFO: KEKSListHasOnlyType +// @deftypefun bool KEKSListHasOnlyType ( @ +// const struct KEKSItems *items, @ // const size_t idx, @ -// const enum YACItemType typ) +// const enum KEKSItemType typ) // Returns true if @var{idx} list in @var{items} contains only values // with the @var{typ} type. // @end deftypefun bool -YACListHasOnlyType(const struct YACItems *, size_t idx, const enum YACItemType typ); +KEKSListHasOnlyType(const struct KEKSItems *, size_t idx, const enum KEKSItemType typ); -// TEXINFO: YACMapHasOnlyType -// @deftypefun bool YACMapHasOnlyType ( @ -// const struct YACItems *items, @ +// TEXINFO: KEKSMapHasOnlyType +// @deftypefun bool KEKSMapHasOnlyType ( @ +// const struct KEKSItems *items, @ // const size_t idx, @ -// const enum YACItemType typ) +// const enum KEKSItemType typ) // Returns true if @var{idx} map in @var{items} contains only values // with the @var{typ} type. // @end deftypefun bool -YACMapHasOnlyType(const struct YACItems *, size_t idx, const enum YACItemType typ); +KEKSMapHasOnlyType(const struct KEKSItems *, size_t idx, const enum KEKSItemType typ); -#endif // YAC_POOL_H +#endif // KEKS_POOL_H diff --git a/cyac/lib/iter.c b/c/lib/iter.c similarity index 66% rename from cyac/lib/iter.c rename to c/lib/iter.c index 26e3e9d..258d96e 100644 --- a/cyac/lib/iter.c +++ b/c/lib/iter.c @@ -1,4 +1,4 @@ -// cyac -- C YAC encoder implementation +// ckeks -- C KEKS encoder implementation // Copyright (C) 2024-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify @@ -23,161 +23,161 @@ #include "err.h" #include "iter.h" -enum YACErr -YACIterList( +enum KEKSErr +KEKSIterList( void *cbState, - struct YACAtom *atom, + struct KEKSAtom *atom, size_t *off, const unsigned char *buf, const size_t len, - YACIterCb cb) + KEKSIterCb cb) { size_t got = 0; - enum YACErr err = YACErrInvalid; + enum KEKSErr err = KEKSErrInvalid; bool eoc = false; for (size_t n = 0;; n++) { assert(len >= (*off)); - err = YACAtomDecode(&got, atom, buf + *off, len - (*off)); - if (err != YACErrNo) { + err = KEKSAtomDecode(&got, atom, buf + *off, len - (*off)); + if (err != KEKSErrNo) { return err; } if ((SIZE_MAX - got) < (*off)) { - return YACErrLenTooBig; + return KEKSErrLenTooBig; } (*off) += got; - eoc = atom->typ == YACItemEOC; + eoc = atom->typ == KEKSItemEOC; err = cb(NULL, 0, !eoc, n, cbState, atom, off, buf, len); - if (err != YACErrNo) { + if (err != KEKSErrNo) { return err; } if (eoc) { break; } } - return YACErrNo; + return KEKSErrNo; } -enum YACErr -YACIterMap( +enum KEKSErr +KEKSIterMap( void *cbState, - struct YACAtom *atom, + struct KEKSAtom *atom, size_t *off, const unsigned char *buf, const size_t len, - YACIterCb cb) + KEKSIterCb cb) { - enum YACErr err = YACErrInvalid; + enum KEKSErr err = KEKSErrInvalid; size_t got = 0; const unsigned char *key = NULL; size_t keyLen = 0; for (;;) { assert(len >= (*off)); - err = YACAtomDecode(&got, atom, buf + *off, len - (*off)); - if (err != YACErrNo) { + err = KEKSAtomDecode(&got, atom, buf + *off, len - (*off)); + if (err != KEKSErrNo) { return err; } if ((SIZE_MAX - got) < (*off)) { - return YACErrLenTooBig; + return KEKSErrLenTooBig; } (*off) += got; - if (atom->typ == YACItemEOC) { + if (atom->typ == KEKSItemEOC) { err = cb(NULL, 0, false, 0, cbState, atom, off, buf, len); - if (err != YACErrNo) { + if (err != KEKSErrNo) { return err; } break; } - if (atom->typ != YACItemStr) { - return YACErrMapBadKey; + if (atom->typ != KEKSItemStr) { + return KEKSErrMapBadKey; } if (atom->v.str.len == 0) { - return YACErrMapBadKey; + return KEKSErrMapBadKey; } if (atom->v.str.len < keyLen) { - return YACErrMapUnordered; + return KEKSErrMapUnordered; } if ((atom->v.str.len == keyLen) && (memcmp(key, atom->v.str.ptr, keyLen) >= 0)) { - return YACErrMapUnordered; + return KEKSErrMapUnordered; } keyLen = atom->v.str.len; key = atom->v.str.ptr; assert(len >= (*off)); - err = YACAtomDecode(&got, atom, buf + *off, len - (*off)); - if (err != YACErrNo) { + err = KEKSAtomDecode(&got, atom, buf + *off, len - (*off)); + if (err != KEKSErrNo) { return err; } if ((SIZE_MAX - got) < (*off)) { - return YACErrLenTooBig; + return KEKSErrLenTooBig; } (*off) += got; - if (atom->typ == YACItemEOC) { - return YACErrUnexpectedEOC; + if (atom->typ == KEKSItemEOC) { + return KEKSErrUnexpectedEOC; } err = cb(key, keyLen, false, 0, cbState, atom, off, buf, len); - if (err != YACErrNo) { + if (err != KEKSErrNo) { return err; } } - return YACErrNo; + return KEKSErrNo; } -enum YACErr -YACIterBlob( +enum KEKSErr +KEKSIterBlob( void *cbState, - struct YACAtom *atom, + struct KEKSAtom *atom, size_t *off, const unsigned char *buf, const size_t len, - YACIterCb cb) + KEKSIterCb cb) { const size_t chunkLen = atom->v.blob.chunkLen; - enum YACErr err = YACErrInvalid; + enum KEKSErr err = KEKSErrInvalid; size_t got = 0; bool eoc = false; for (size_t n = 0; !eoc; n++) { assert(len >= (*off)); - err = YACAtomDecode(&got, atom, buf + *off, len - (*off)); - if (err != YACErrNo) { + err = KEKSAtomDecode(&got, atom, buf + *off, len - (*off)); + if (err != KEKSErrNo) { return err; } if ((SIZE_MAX - got) < (*off)) { - return YACErrLenTooBig; + return KEKSErrLenTooBig; } (*off) += got; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wswitch-enum" switch (atom->typ) { #pragma clang diagnostic pop - case YACItemNIL: + case KEKSItemNIL: assert(len >= (*off)); if ((len - *off) <= chunkLen) { atom->v.str.len = chunkLen; - return YACErrNotEnough; + return KEKSErrNotEnough; } - atom->typ = YACItemBin; + atom->typ = KEKSItemBin; atom->v.str.ptr = buf + *off; atom->v.str.len = chunkLen; if ((SIZE_MAX - chunkLen) < (*off)) { - return YACErrLenTooBig; + return KEKSErrLenTooBig; } (*off) += chunkLen; break; - case YACItemBin: + case KEKSItemBin: if ((atom->v.str.len) >= chunkLen) { - return YACErrBlobBadTerm; + return KEKSErrBlobBadTerm; } eoc = true; break; default: - return YACErrBlobBadAtom; + return KEKSErrBlobBadAtom; } err = cb(NULL, 0, true, n, cbState, atom, off, buf, len); - if (err != YACErrNo) { + if (err != KEKSErrNo) { return err; } } - atom->typ = YACItemEOC; + atom->typ = KEKSItemEOC; err = cb(NULL, 0, false, 0, cbState, atom, off, buf, len); return err; } diff --git a/cyac/lib/iter.h b/c/lib/iter.h similarity index 60% rename from cyac/lib/iter.h rename to c/lib/iter.h index 028ae6d..9499812 100644 --- a/cyac/lib/iter.h +++ b/c/lib/iter.h @@ -1,5 +1,5 @@ -#ifndef YAC_ITER_H -#define YAC_ITER_H +#ifndef KEKS_ITER_H +#define KEKS_ITER_H #include #include @@ -7,42 +7,42 @@ #include "dec.h" #include "err.h" -typedef enum YACErr (*YACIterCb)( +typedef enum KEKSErr (*KEKSIterCb)( const unsigned char *key, const size_t keyLen, const bool inList, const size_t idx, void *cbState, - struct YACAtom *atom, + struct KEKSAtom *atom, size_t *off, const unsigned char *buf, const size_t len); -enum YACErr -YACIterList( +enum KEKSErr +KEKSIterList( void *cbState, - struct YACAtom *atom, + struct KEKSAtom *atom, size_t *off, const unsigned char *buf, const size_t len, - YACIterCb cb); + KEKSIterCb cb); -enum YACErr -YACIterMap( +enum KEKSErr +KEKSIterMap( void *cbState, - struct YACAtom *atom, + struct KEKSAtom *atom, size_t *off, const unsigned char *buf, const size_t len, - YACIterCb cb); + KEKSIterCb cb); -enum YACErr -YACIterBlob( +enum KEKSErr +KEKSIterBlob( void *cbState, - struct YACAtom *atom, + struct KEKSAtom *atom, size_t *off, const unsigned char *buf, const size_t len, - YACIterCb cb); + KEKSIterCb cb); -#endif // YAC_ITER_H +#endif // KEKS_ITER_H diff --git a/cyac/lib/leapsecs.c b/c/lib/leapsecs.c similarity index 92% rename from cyac/lib/leapsecs.c rename to c/lib/leapsecs.c index ec7fef8..f8aff15 100644 --- a/cyac/lib/leapsecs.c +++ b/c/lib/leapsecs.c @@ -2,8 +2,8 @@ #include "leapsecs.h" -const int64_t YACLeapsecsN = 27; -const int64_t YACLeapsecs[] = { +const int64_t KEKSLeapsecsN = 27; +const int64_t KEKSLeapsecs[] = { 78796810, // 1972-07 94694411, // 1973-01 126230412, // 1974-01 diff --git a/c/lib/leapsecs.h b/c/lib/leapsecs.h new file mode 100644 index 0000000..2f55f95 --- /dev/null +++ b/c/lib/leapsecs.h @@ -0,0 +1,15 @@ +#ifndef KEKS_LEAPSECS_H +#define KEKS_LEAPSECS_H + +#include + +// TEXINFO: KEKSLeapsecs +// @deftypevar {const int64_t *} KEKSLeapsecs +// Leap seconds database. It contains TAI seconds when an additional +// second was added. @var{KEKSLeapsecsN} variable holds the length of +// that list. +// @end deftypevar +extern const int64_t KEKSLeapsecsN; +extern const int64_t KEKSLeapsecs[]; + +#endif // KEKS_LEAPSECS_H diff --git a/cyac/lib/libyac.a.do b/c/lib/libkeks.a.do similarity index 100% rename from cyac/lib/libyac.a.do rename to c/lib/libkeks.a.do diff --git a/cyac/lib/o.list b/c/lib/o.list similarity index 100% rename from cyac/lib/o.list rename to c/lib/o.list diff --git a/c/lib/pki/.gitignore b/c/lib/pki/.gitignore new file mode 100644 index 0000000..3016f89 --- /dev/null +++ b/c/lib/pki/.gitignore @@ -0,0 +1 @@ +/libkekspki.a diff --git a/cyac/lib/pki/cer.c b/c/lib/pki/cer.c similarity index 59% rename from cyac/lib/pki/cer.c rename to c/lib/pki/cer.c index 8b3dce0..b4fe532 100644 --- a/cyac/lib/pki/cer.c +++ b/c/lib/pki/cer.c @@ -9,226 +9,226 @@ #include "../items.h" #include "cer.h" -enum YACErr -YACCerParse( - struct YACCer *cer, +enum KEKSErr +KEKSCerParse( + struct KEKSCer *cer, size_t *off, char **failReason, const unsigned char *buf, const size_t len) { - struct YACItems *items = &(cer->items); - YACItemsInit(items); - enum YACErr err = YACItemsParse(items, off, buf, len); - if (err != YACErrNo) { + struct KEKSItems *items = &(cer->items); + KEKSItemsInit(items); + enum KEKSErr err = KEKSItemsParse(items, off, buf, len); + if (err != KEKSErrNo) { return err; } size_t idx = 0; - struct YACItem *item = NULL; - if (YACItemsGetByKey(items, 0, "hash") != 0) { + struct KEKSItem *item = NULL; + if (KEKSItemsGetByKey(items, 0, "hash") != 0) { (*failReason) = "unexpected /hash"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } - size_t loadIdx = YACItemsGetByKey(items, 0, "load"); + size_t loadIdx = KEKSItemsGetByKey(items, 0, "load"); { if (loadIdx == 0) { (*failReason) = "no /load"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } - idx = YACItemsGetByKeyAndType(items, loadIdx, "t", YACItemStr); + idx = KEKSItemsGetByKeyAndType(items, loadIdx, "t", KEKSItemStr); if (loadIdx == 0) { (*failReason) = "no /load/t"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } - if (!YACStrEqual(&(items->list[idx].atom), "cer")) { + if (!KEKSStrEqual(&(items->list[idx].atom), "cer")) { (*failReason) = "/load/t != cer"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } } - cer->load = YACItemsGetByKey(items, loadIdx, "v"); + cer->load = KEKSItemsGetByKey(items, loadIdx, "v"); { if (cer->load == 0) { (*failReason) = "no /load/v"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } - idx = YACItemsGetByKey(items, cer->load, "ku"); + idx = KEKSItemsGetByKey(items, cer->load, "ku"); if (idx != 0) { item = &(items->list[idx]); if (item->atom.v.list.len == 0) { (*failReason) = "empty /load/v/ku"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } - if (!YACMapHasOnlyType(items, idx, YACItemNIL)) { + if (!KEKSMapHasOnlyType(items, idx, KEKSItemNIL)) { (*failReason) = "bad /load/v/ku value"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } } } - idx = YACItemsGetByKey(items, cer->load, "pub"); + idx = KEKSItemsGetByKey(items, cer->load, "pub"); { if (idx == 0) { (*failReason) = "no /load/v/pub"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } item = &(items->list[idx]); if (item->atom.v.list.len != 1) { (*failReason) = "len(/load/v/pub) != 1"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } idx = items->list[idx].atom.v.list.head; cer->pub = idx; while (idx != 0) { - if (YACItemsGetByKeyAndType(items, idx, "a", YACItemStr) == 0) { + if (KEKSItemsGetByKeyAndType(items, idx, "a", KEKSItemStr) == 0) { (*failReason) = "no /load/v/pub/a"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } - if (YACItemsGetByKeyAndType(items, idx, "v", YACItemBin) == 0) { + if (KEKSItemsGetByKeyAndType(items, idx, "v", KEKSItemBin) == 0) { (*failReason) = "no /load/v/pub/v"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } { - size_t pkidIdx = YACItemsGetByKeyAndType(items, idx, "id", YACItemUUID); + size_t pkidIdx = KEKSItemsGetByKeyAndType(items, idx, "id", KEKSItemUUID); if (pkidIdx == 0) { (*failReason) = "no /load/v/pub/id"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } cer->pkid = items->list[pkidIdx].atom.v.uuid; } idx = items->list[idx].next; } } - cer->sub = YACItemsGetByKey(items, cer->load, "sub"); + cer->sub = KEKSItemsGetByKey(items, cer->load, "sub"); { if (cer->sub == 0) { (*failReason) = "no /load/v/sub"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } item = &(items->list[cer->sub]); if (item->atom.v.list.len == 0) { (*failReason) = "empty /load/v/sub"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } - if (!YACMapHasOnlyType(items, cer->sub, YACItemStr)) { + if (!KEKSMapHasOnlyType(items, cer->sub, KEKSItemStr)) { (*failReason) = "bad /load/v/sub value"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } } - if (YACItemsGetByKey(items, cer->load, "crit") != 0) { + if (KEKSItemsGetByKey(items, cer->load, "crit") != 0) { (*failReason) = "/load/v/crit is unsupported"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } - size_t sigsIdx = YACItemsGetByKey(items, 0, "sigs"); + size_t sigsIdx = KEKSItemsGetByKey(items, 0, "sigs"); { if (sigsIdx == 0) { (*failReason) = "no /sigs"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } item = &(items->list[sigsIdx]); if (item->atom.v.list.len != 1) { (*failReason) = "len(/load/sigs) != 1"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } size_t sigIdx = items->list[sigsIdx].atom.v.list.head; cer->sig = sigIdx; while (sigIdx != 0) { - if (YACItemsGetByKey(items, sigIdx, "hash") != 0) { + if (KEKSItemsGetByKey(items, sigIdx, "hash") != 0) { (*failReason) = "unexpected /sigs/./hash met"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } { - idx = YACItemsGetByKey(items, sigIdx, "sign"); + idx = KEKSItemsGetByKey(items, sigIdx, "sign"); if (idx == 0) { (*failReason) = "no /sigs/./sign"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } - if (YACItemsGetByKeyAndType(items, idx, "a", YACItemStr) == 0) { + if (KEKSItemsGetByKeyAndType(items, idx, "a", KEKSItemStr) == 0) { (*failReason) = "no /sigs/./sign/a"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } - if (YACItemsGetByKeyAndType(items, idx, "v", YACItemBin) == 0) { + if (KEKSItemsGetByKeyAndType(items, idx, "v", KEKSItemBin) == 0) { (*failReason) = "no /sigs/./sign/v"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } } { - idx = YACItemsGetByKey(items, sigIdx, "tbs"); + idx = KEKSItemsGetByKey(items, sigIdx, "tbs"); if (idx == 0) { (*failReason) = "no /sigs/./tbs"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } { size_t cidIdx = - YACItemsGetByKeyAndType(items, idx, "cid", YACItemUUID); + KEKSItemsGetByKeyAndType(items, idx, "cid", KEKSItemUUID); if (cidIdx == 0) { (*failReason) = "no /sigs/./tbs/cid"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } cer->cid = items->list[cidIdx].atom.v.uuid; } { size_t sidIdx = - YACItemsGetByKeyAndType(items, idx, "sid", YACItemUUID); + KEKSItemsGetByKeyAndType(items, idx, "sid", KEKSItemUUID); if (sidIdx == 0) { (*failReason) = "no /sigs/./tbs/sid"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } cer->sid = items->list[sidIdx].atom.v.uuid; } - idx = YACItemsGetByKeyAndType(items, idx, "exp", YACItemList); + idx = KEKSItemsGetByKeyAndType(items, idx, "exp", KEKSItemList); if (idx == 0) { (*failReason) = "no /sigs/./tbs/exp"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } - if (!YACListHasOnlyType(items, idx, YACItemTAI64)) { + if (!KEKSListHasOnlyType(items, idx, KEKSItemTAI64)) { (*failReason) = "bad /sigs/./tbs/exp value"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } item = &(items->list[idx]); if (item->atom.v.list.len != 2) { (*failReason) = "len(/sigs/./tbs/exp) != 2"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } - err = YACTAI64ToTimespec( + err = KEKSTAI64ToTimespec( &(cer->since), items->list[idx + 1].atom.v.str.ptr, items->list[idx + 1].atom.v.str.len); - if ((err != YACErrNo) || (cer->since.tv_nsec != 0)) { + if ((err != KEKSErrNo) || (cer->since.tv_nsec != 0)) { (*failReason) = "bad /sigs/./tbs/exp/since value"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } - err = YACTimespecToUTC(&(cer->since)); - if (err != YACErrNo) { + err = KEKSTimespecToUTC(&(cer->since)); + if (err != KEKSErrNo) { (*failReason) = "bad /sigs/./tbs/exp/since UTC value"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } - err = YACTAI64ToTimespec( + err = KEKSTAI64ToTimespec( &(cer->till), items->list[idx + 2].atom.v.str.ptr, items->list[idx + 2].atom.v.str.len); - if ((err != YACErrNo) || (cer->till.tv_nsec != 0)) { + if ((err != KEKSErrNo) || (cer->till.tv_nsec != 0)) { (*failReason) = "bad /sigs/./tbs/exp/till value"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } - err = YACTimespecToUTC(&(cer->till)); - if (err != YACErrNo) { + err = KEKSTimespecToUTC(&(cer->till)); + if (err != KEKSErrNo) { (*failReason) = "bad /sigs/./tbs/exp/till UTC value"; - return YACErrUnsatisfiedSchema; + return KEKSErrUnsatisfiedSchema; } } sigIdx = items->list[sigIdx].next; } } - return YACErrNo; + return KEKSErrNo; } bool -YACCerVerify( +KEKSCerVerify( char **failReason, - struct YACCer **verifier, - struct YACCer *cer, - struct YACCer *pool, + struct KEKSCer **verifier, + struct KEKSCer *cer, + struct KEKSCer *pool, const size_t poolLen, - const struct YACCerVerifyOpts opts) + const struct KEKSCerVerifyOpts opts) { if (opts.t.tv_sec <= cer->since.tv_sec) { (*failReason) = "unsatisfied since"; @@ -249,16 +249,16 @@ YACCerVerify( (*failReason) = "no verifier found"; return false; } - struct YACItem *pubA = &((*verifier)->items.list[YACItemsGetByKey( + struct KEKSItem *pubA = &((*verifier)->items.list[KEKSItemsGetByKey( &((*verifier)->items), (*verifier)->pub, "a")]); - struct YACItem *pubV = &((*verifier)->items.list[YACItemsGetByKey( + struct KEKSItem *pubV = &((*verifier)->items.list[KEKSItemsGetByKey( &((*verifier)->items), (*verifier)->pub, "v")]); - size_t signIdx = YACItemsGetByKey(&(cer->items), cer->sig, "sign"); - struct YACItem *sigV = - &(cer->items.list[YACItemsGetByKey(&(cer->items), signIdx, "v")]); + size_t signIdx = KEKSItemsGetByKey(&(cer->items), cer->sig, "sign"); + struct KEKSItem *sigV = + &(cer->items.list[KEKSItemsGetByKey(&(cer->items), signIdx, "v")]); { - struct YACItem *sigA = - &(cer->items.list[YACItemsGetByKey(&(cer->items), signIdx, "a")]); + struct KEKSItem *sigA = + &(cer->items.list[KEKSItemsGetByKey(&(cer->items), signIdx, "a")]); if ((sigA->atom.v.str.len != pubA->atom.v.str.len) || (memcmp(sigA->atom.v.str.ptr, pubA->atom.v.str.ptr, sigA->atom.v.str.len) != 0)) { @@ -271,53 +271,53 @@ YACCerVerify( size_t off = 0; { const size_t items = 5; - struct YACItem tbsItems[5]; + struct KEKSItem tbsItems[5]; memset(&tbsItems, 0, sizeof tbsItems); - struct YACItems tbs = { + struct KEKSItems tbs = { .list = tbsItems, .offsets = NULL, .len = items, .cap = -1}; - tbsItems[0].atom.typ = YACItemMap; + tbsItems[0].atom.typ = KEKSItemMap; tbsItems[0].atom.v.list.head = 1; - tbsItems[1].atom.typ = YACItemStr; + tbsItems[1].atom.typ = KEKSItemStr; tbsItems[1].atom.v.str.len = 1; tbsItems[1].atom.v.str.ptr = (const unsigned char *)"t"; tbsItems[1].next = 2; - tbsItems[2].atom.typ = YACItemStr; + tbsItems[2].atom.typ = KEKSItemStr; tbsItems[2].atom.v.str.len = 3; tbsItems[2].atom.v.str.ptr = (const unsigned char *)"cer"; tbsItems[2].next = 3; - tbsItems[3].atom.typ = YACItemStr; + tbsItems[3].atom.typ = KEKSItemStr; tbsItems[3].atom.v.str.len = 1; tbsItems[3].atom.v.str.ptr = (const unsigned char *)"v"; tbsItems[3].next = 4; - tbsItems[4].atom.typ = YACItemNIL; + tbsItems[4].atom.typ = KEKSItemNIL; tbsItems[4].next = 0; - if (!YACItemsEncode(&tbs, 0, &off, buf, cap)) { + if (!KEKSItemsEncode(&tbs, 0, &off, buf, cap)) { (*failReason) = "can not prepare tbs: start"; return false; } } off -= 2; // strip off NIL and EOC, continue map generation - if (!YACItemsEncode(&(cer->items), cer->load, &off, buf, cap)) { + if (!KEKSItemsEncode(&(cer->items), cer->load, &off, buf, cap)) { (*failReason) = "can not prepare tbs: load"; return false; } { size_t got = 0; - if (!YACAtomStrEncode( + if (!KEKSAtomStrEncode( &got, buf + off, cap - off, (const unsigned char *)"tbs", 3)) { (*failReason) = "can not prepare tbs: tbs key"; return false; } off += got; } - if (!YACItemsEncode( + if (!KEKSItemsEncode( &(cer->items), - YACItemsGetByKey(&(cer->items), cer->sig, "tbs"), + KEKSItemsGetByKey(&(cer->items), cer->sig, "tbs"), &off, buf, cap)) { @@ -326,14 +326,14 @@ YACCerVerify( } { size_t got = 0; - if (!YACAtomEOCEncode(&got, buf + off, cap - off)) { + if (!KEKSAtomEOCEncode(&got, buf + off, cap - off)) { (*failReason) = "can not prepare tbs: eoc"; return false; } off += got; } for (size_t i = 0; opts.sigVerifiers[i].algo != NULL; i++) { - if (!YACStrEqual(&(pubA->atom), opts.sigVerifiers[i].algo)) { + if (!KEKSStrEqual(&(pubA->atom), opts.sigVerifiers[i].algo)) { continue; } return opts.sigVerifiers[i].func( diff --git a/cyac/lib/pki/cer.h b/c/lib/pki/cer.h similarity index 67% rename from cyac/lib/pki/cer.h rename to c/lib/pki/cer.h index 9314d27..08eb4e8 100644 --- a/cyac/lib/pki/cer.h +++ b/c/lib/pki/cer.h @@ -1,5 +1,5 @@ -#ifndef YAC_CER_H -#define YAC_CER_H +#ifndef KEKS_CER_H +#define KEKS_CER_H #include #include @@ -8,12 +8,12 @@ #include "../err.h" #include "../items.h" -// TEXINFO: YACCer -// @deftp {Data type} {struct YACCer} +// TEXINFO: KEKSCer +// @deftp {Data type} {struct KEKSCer} // Parsed certificate structure. // @table @code // @item .items -// Holds parsed @ref{YACItems} items. +// Holds parsed @ref{KEKSItems} items. // @item .load // Items index of the @code{/load/v}, certificate body. // @item .pub @@ -35,8 +35,8 @@ // Parsed un"till" datetime. // @end table // @end deftp -struct YACCer { - struct YACItems items; +struct KEKSCer { + struct KEKSItems items; size_t load; size_t pub; size_t sub; @@ -48,29 +48,29 @@ struct YACCer { struct timespec till; }; -// TEXINFO: YACCerParse -// @deftypefun {enum YACErr} YACCerParse ( @ -// struct YACCer *cer, @ +// TEXINFO: KEKSCerParse +// @deftypefun {enum KEKSErr} KEKSCerParse ( @ +// struct KEKSCer *cer, @ // size_t *off, @ // char **failReason, @ // const unsigned char *buf, @ // const size_t len) -// Parse represented YAC certificate from @var{buf} of @var{len} length, +// Parse represented KEKS certificate from @var{buf} of @var{len} length, // to the @var{cer}, starting with @var{off} offset in the buffer. // Offset will be updated to show where parsing stopped. If parsing, -// made by @ref{YACItemsParse}, finished successfully, then -// @code{YACErrUnsatisfiedSchema} may be returned after that, setting +// made by @ref{KEKSItemsParse}, finished successfully, then +// @code{KEKSErrUnsatisfiedSchema} may be returned after that, setting // the @var{failReason} to the string describing the error. // @end deftypefun -enum YACErr -YACCerParse( - struct YACCer *, +enum KEKSErr +KEKSCerParse( + struct KEKSCer *, size_t *off, char **failReason, const unsigned char *buf, const size_t len); -typedef bool (*yacSigVerifier)( +typedef bool (*keksSigVerifier)( char **failReason, const unsigned char *ai, const size_t aiLen, @@ -81,43 +81,43 @@ typedef bool (*yacSigVerifier)( const unsigned char *data, const size_t dataLen); -// TEXINFO: YACCerSigVerifier -// @deftp {Data type} {struct YACCerSigVerifier} +// TEXINFO: KEKSCerSigVerifier +// @deftp {Data type} {struct KEKSCerSigVerifier} // Cryptographic signature verifier. That structure's @code{.algo} holds -// the string identifier of the algorithm met in the YAC structures. +// the string identifier of the algorithm met in the KEKS structures. // @code{.func} holds the pointer to the verifier function itself, that // accepts the algorithm identifier, signature, raw public key, the data // to be verified. // @end deftp -struct YACCerSigVerifier { +struct KEKSCerSigVerifier { char *algo; - yacSigVerifier func; + keksSigVerifier func; }; -// TEXINFO: YACCerVerifyOpts -// @deftp {Data type} {struct YACCerVerifyOpts} +// TEXINFO: KEKSCerVerifyOpts +// @deftp {Data type} {struct KEKSCerVerifyOpts} // Certificate verification options: // @table @code // @item .t // Validity time to check against. // @item .sigVerifiers -// List of @ref{YACCerSigVerifier}. +// List of @ref{KEKSCerSigVerifier}. // Its last dummy element must have NULL @code{.algo}. // @end table // @end deftp -struct YACCerVerifyOpts { +struct KEKSCerVerifyOpts { struct timespec t; - struct YACCerSigVerifier *sigVerifiers; + struct KEKSCerSigVerifier *sigVerifiers; }; -// TEXINFO: YACCerVerify -// @deftypefun bool YACCerVerify ( @ +// TEXINFO: KEKSCerVerify +// @deftypefun bool KEKSCerVerify ( @ // char **failReason, @ -// struct YACCer **verifier, @ -// struct YACCer *cer, @ -// struct YACCer *pool, @ +// struct KEKSCer **verifier, @ +// struct KEKSCer *cer, @ +// struct KEKSCer *pool, @ // const size_t poolLen, @ -// const struct YACCerVerifyOpts opts) +// const struct KEKSCerVerifyOpts opts) // Verify @var{cer} certificate. @var{pool} is a list of certificates of // @var{poolLen} length, which is searched for verifier certificates. If // verifier is found (certificate with @code{pkid} equals to @code{sid}), @@ -125,12 +125,12 @@ struct YACCerVerifyOpts { // verification process. // @end deftypefun bool -YACCerVerify( +KEKSCerVerify( char **failReason, - struct YACCer **verifier, - struct YACCer *cer, - struct YACCer *pool, + struct KEKSCer **verifier, + struct KEKSCer *cer, + struct KEKSCer *pool, const size_t poolLen, - const struct YACCerVerifyOpts opts); + const struct KEKSCerVerifyOpts opts); -#endif // YAC_CER_H +#endif // KEKS_CER_H diff --git a/cyac/lib/pki/clean b/c/lib/pki/clean similarity index 100% rename from cyac/lib/pki/clean rename to c/lib/pki/clean diff --git a/c/lib/pki/install.do b/c/lib/pki/install.do new file mode 100644 index 0000000..686011b --- /dev/null +++ b/c/lib/pki/install.do @@ -0,0 +1,6 @@ +redo-ifchange *.h libkekspki.a ../../conf/prefix +read PREFIX <../../conf/prefix +mkdir -p $PREFIX/include/keks/pki $PREFIX/lib +cp -f *.h $PREFIX/include/keks/pki +cp -f libkekspki.a $PREFIX/lib +chmod 644 $PREFIX/include/keks/pki/*.h $PREFIX/lib/libkekspki.a diff --git a/cyac/lib/pki/libyacpki.a.do b/c/lib/pki/libkekspki.a.do similarity index 100% rename from cyac/lib/pki/libyacpki.a.do rename to c/lib/pki/libkekspki.a.do diff --git a/cyac/lib/pki/o.list b/c/lib/pki/o.list similarity index 100% rename from cyac/lib/pki/o.list rename to c/lib/pki/o.list diff --git a/cyac/lib/tobe.c b/c/lib/tobe.c similarity index 97% rename from cyac/lib/tobe.c rename to c/lib/tobe.c index 9dacd33..d079e2a 100644 --- a/cyac/lib/tobe.c +++ b/c/lib/tobe.c @@ -4,7 +4,7 @@ #include "tobe.h" void -yacToBE(unsigned char *buf, const size_t len, const uint64_t v) +keksToBE(unsigned char *buf, const size_t len, const uint64_t v) { switch (len) { case 1: diff --git a/c/lib/tobe.h b/c/lib/tobe.h new file mode 100644 index 0000000..0afb7ec --- /dev/null +++ b/c/lib/tobe.h @@ -0,0 +1,11 @@ +#ifndef KEKS_TOBE_H +#define KEKS_TOBE_H + +#include +#include + +// Store big-endian integer of the length @var{len}. +void +keksToBE(unsigned char *buf, const size_t len, const uint64_t v); + +#endif // KEKS_TOBE_H diff --git a/cyac/lib/utf8.c b/c/lib/utf8.c similarity index 88% rename from cyac/lib/utf8.c rename to c/lib/utf8.c index 865ec08..c6a118a 100644 --- a/cyac/lib/utf8.c +++ b/c/lib/utf8.c @@ -10,7 +10,7 @@ #define BETWEEN(c, l, u) (((c) >= (l)) && ((c) <= (u))) -const uint32_t YACUTF8InvalidCp = 0xFFFD; +const uint32_t KEKSUTF8InvalidCp = 0xFFFD; static const struct { uint32_t mincp; @@ -54,15 +54,15 @@ static const struct { }; size_t -YACUTF8CpDecode(uint32_t *cp, const unsigned char *str, const size_t len) +KEKSUTF8CpDecode(uint32_t *cp, const unsigned char *str, const size_t len) { assert(cp != NULL); if (str == NULL || len == 0) { - (*cp) = YACUTF8InvalidCp; + (*cp) = KEKSUTF8InvalidCp; return 0; } if (str[0] == 0) { - (*cp) = YACUTF8InvalidCp; + (*cp) = KEKSUTF8InvalidCp; return 1; } size_t off = 0; @@ -73,12 +73,12 @@ YACUTF8CpDecode(uint32_t *cp, const unsigned char *str, const size_t len) } } if (off == 4) { - (*cp) = YACUTF8InvalidCp; + (*cp) = KEKSUTF8InvalidCp; return 1; } size_t i = 0; if ((1 + off) > len) { - (*cp) = YACUTF8InvalidCp; + (*cp) = KEKSUTF8InvalidCp; for (i = 0; 1 + i < len; i++) { if (!BETWEEN(str[1 + i], 0x80, 0xBF)) { break; @@ -88,14 +88,14 @@ YACUTF8CpDecode(uint32_t *cp, const unsigned char *str, const size_t len) } for (i = 1; i <= off; i++) { if (!BETWEEN(str[i], 0x80, 0xBF)) { - (*cp) = YACUTF8InvalidCp; + (*cp) = KEKSUTF8InvalidCp; return 1 + (i - 1); } (*cp) = (*cp << (uint8_t)6) | // NOLINT(hicpp-signed-bitwise) (str[i] & (uint8_t)0x3F); } if ((*cp < lut[off].mincp) || BETWEEN(*cp, 0xD800, 0xDFFF) || (*cp > 0x10FFFF)) { - (*cp) = YACUTF8InvalidCp; + (*cp) = KEKSUTF8InvalidCp; } return 1 + off; } diff --git a/c/lib/utf8.h b/c/lib/utf8.h new file mode 100644 index 0000000..accabb5 --- /dev/null +++ b/c/lib/utf8.h @@ -0,0 +1,12 @@ +#ifndef KEKS_UTF8_H +#define KEKS_UTF8_H + +#include +#include + +extern const uint32_t KEKSUTF8InvalidCp; + +size_t +KEKSUTF8CpDecode(uint32_t *cp, const unsigned char *str, const size_t len); + +#endif // KEKS_UTF8_H diff --git a/cyac/lint/.clang-format b/c/lint/.clang-format similarity index 100% rename from cyac/lint/.clang-format rename to c/lint/.clang-format diff --git a/cyac/lint/iwyu-maps.imp b/c/lint/iwyu-maps.imp similarity index 100% rename from cyac/lint/iwyu-maps.imp rename to c/lint/iwyu-maps.imp diff --git a/cyac/README b/cyac/README deleted file mode 100644 index f18c2cb..0000000 --- a/cyac/README +++ /dev/null @@ -1,2 +0,0 @@ -C99 implementation of the YAC codec. -Look at doc/ for more information. diff --git a/cyac/cmd/lib/printai.h b/cyac/cmd/lib/printai.h deleted file mode 100644 index c408b4d..0000000 --- a/cyac/cmd/lib/printai.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef YAC_PRINTAI_H -#define YAC_PRINTAI_H - -#include - -#include - -enum YACErr -PrintTAI64(const unsigned char *buf, const size_t len); - -#endif // YAC_PRINTAI_H diff --git a/cyac/cmd/lib/uuid.h b/cyac/cmd/lib/uuid.h deleted file mode 100644 index fbe31c3..0000000 --- a/cyac/cmd/lib/uuid.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef YAC_UUID_H -#define YAC_UUID_H - -void -UUIDPrint(const unsigned char *buf); - -#endif // YAC_UUID_H diff --git a/cyac/cmd/test-vector/test-vector.c b/cyac/cmd/test-vector/test-vector.c deleted file mode 100644 index 42a3b98..0000000 --- a/cyac/cmd/test-vector/test-vector.c +++ /dev/null @@ -1,252 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -static size_t Off = 0; -static size_t Got = 0; - -static void -adder(const bool ok) -{ - assert(ok); - Off += Got; -} - -int -main(void) -{ - const size_t len = (size_t)68 * (uint16_t)1024; - unsigned char *buf = malloc(len); - assert(buf != NULL); - unsigned char *bin = malloc((uint32_t)1 << (uint8_t)17); - assert(bin != NULL); - - adder(YACAtomMapEncode(&Got, buf + Off, len - Off)); // . - - adder( - YACAtomStrEncode(&Got, buf + Off, len - Off, (const unsigned char *)"nil", 3)); - adder(YACAtomNILEncode(&Got, buf + Off, len - Off)); - - adder( - YACAtomStrEncode(&Got, buf + Off, len - Off, (const unsigned char *)"str", 3)); - adder(YACAtomMapEncode(&Got, buf + Off, len - Off)); // .str - - adder( - YACAtomStrEncode(&Got, buf + Off, len - Off, (const unsigned char *)"bin", 3)); - adder(YACAtomListEncode(&Got, buf + Off, len - Off)); // .str.bin - adder(YACAtomBinEncode(&Got, buf + Off, len - Off, (const unsigned char *)"", 0)); - memset(bin, '0', 60); - adder(YACAtomBinEncode(&Got, buf + Off, len - Off, bin, 60)); - memset(bin, '1', 61); - adder(YACAtomBinEncode(&Got, buf + Off, len - Off, bin, 61)); - memset(bin, '2', 255); - adder(YACAtomBinEncode(&Got, buf + Off, len - Off, bin, 255)); - memset(bin, 'A', 61 + 255); - adder(YACAtomBinEncode(&Got, buf + Off, len - Off, bin, 61 + 255)); - memset(bin, 'B', 62 + 255); - adder(YACAtomBinEncode(&Got, buf + Off, len - Off, bin, 62 + 255)); - memset(bin, '3', 1024); - adder(YACAtomBinEncode(&Got, buf + Off, len - Off, bin, 1024)); - memset(bin, '4', 63 + 255 + 65535 + 1); - adder(YACAtomBinEncode(&Got, buf + Off, len - Off, bin, 63 + 255 + 65535 + 1)); - adder(YACAtomEOCEncode(&Got, buf + Off, len - Off)); // .str.bin - - adder( - YACAtomStrEncode(&Got, buf + Off, len - Off, (const unsigned char *)"utf8", 4)); - adder(YACAtomStrEncode( - &Got, buf + Off, len - Off, (const unsigned char *)"привет мир", 19)); - adder(YACAtomEOCEncode(&Got, buf + Off, len - Off)); // .str - - adder( - YACAtomStrEncode(&Got, buf + Off, len - Off, (const unsigned char *)"blob", 4)); - adder(YACAtomListEncode(&Got, buf + Off, len - Off)); // .blob - - adder(YACAtomBlobEncode(&Got, buf + Off, len - Off, 12)); // .blob.0 - memset(bin, '5', 1); - adder(YACAtomBinEncode(&Got, buf + Off, len - Off, bin, 1)); - - adder(YACAtomBlobEncode(&Got, buf + Off, len - Off, 12)); // .blob.1 - memset(bin, '6', 12); - adder(YACAtomChunkEncode(&Got, buf + Off, len - Off, bin, 12)); - adder(YACAtomBinEncode(&Got, buf + Off, len - Off, NULL, 0)); - - adder(YACAtomBlobEncode(&Got, buf + Off, len - Off, 12)); // .blob.2 - memset(bin, '7', 12); - adder(YACAtomChunkEncode(&Got, buf + Off, len - Off, bin, 12)); - adder(YACAtomBinEncode(&Got, buf + Off, len - Off, bin, 1)); - - adder(YACAtomBlobEncode(&Got, buf + Off, len - Off, 5)); // .blob.3 - adder(YACAtomChunkEncode( - &Got, buf + Off, len - Off, (const unsigned char *)"12345", 5)); - adder(YACAtomChunkEncode( - &Got, buf + Off, len - Off, (const unsigned char *)"67890", 5)); - adder(YACAtomBinEncode(&Got, buf + Off, len - Off, (const unsigned char *)"-", 1)); - - adder(YACAtomEOCEncode(&Got, buf + Off, len - Off)); // .blob - - adder( - YACAtomStrEncode(&Got, buf + Off, len - Off, (const unsigned char *)"bool", 4)); - adder(YACAtomListEncode(&Got, buf + Off, len - Off)); // .bool - adder(YACAtomBoolEncode(&Got, buf + Off, len - Off, true)); - adder(YACAtomBoolEncode(&Got, buf + Off, len - Off, false)); - adder(YACAtomEOCEncode(&Got, buf + Off, len - Off)); // .bool - - adder( - YACAtomStrEncode(&Got, buf + Off, len - Off, (const unsigned char *)"ints", 4)); - adder(YACAtomMapEncode(&Got, buf + Off, len - Off)); // .ints - - adder( - YACAtomStrEncode(&Got, buf + Off, len - Off, (const unsigned char *)"neg", 3)); - adder(YACAtomListEncode(&Got, buf + Off, len - Off)); // .ints.neg - adder(YACAtomSintEncode(&Got, buf + Off, len - Off, -1)); - adder(YACAtomSintEncode(&Got, buf + Off, len - Off, -2)); - adder(YACAtomSintEncode(&Got, buf + Off, len - Off, -32)); - adder(YACAtomSintEncode(&Got, buf + Off, len - Off, -33)); - adder(YACAtomSintEncode(&Got, buf + Off, len - Off, -123)); - adder(YACAtomSintEncode(&Got, buf + Off, len - Off, -1234)); - adder(YACAtomSintEncode(&Got, buf + Off, len - Off, -12345678)); - adder(YACAtomRawEncode( - &Got, - buf + Off, - len - Off, - YACAtomNint, - (const unsigned char *)"\x8A\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", - 11)); - adder(YACAtomRawEncode( - &Got, - buf + Off, - len - Off, - YACAtomNint, - (const unsigned char - *)"\x91\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", - 18)); - adder(YACAtomRawEncode( - &Got, - buf + Off, - len - Off, - YACAtomNint, - (const unsigned char - *)"\xBE\x00\xA1\xE5\xA4\x61\x28\x03\x41\x85\x6D\x4A\xD9\x08\xA6\x9E\xA5\xF3\xCC\xC1\x0C\x78\x82\x14\x2B\xB7\xD8\x01\xCC\x38\x0F\x26\xB6\xB4\xD6\x96\x32\x02\x4E\xE5\x21\xF8\xCF\xAF\xB4\x43\xD4\x9A\x2A\x3D\x0C\xC7\x3B\xB4\x75\x7E\x88\x2F\x53\x96\xED\x30\x2B\x41\x82\x10\xD0\xD4\x9D\x71\xBE\x86\xCA\x69\x9C\xF5\xEE\x3B\xD6\xD5\x7E\xD6\x58\xE6\x93\x16\x22\x96\x44\xBA\x65\x0C\x92\xD7\xF0\xD4\xDB\x29\xC3\xAD\x1D\xFA\x99\x79\x16\x6F\x4C\x6E\x79\x56\x1A\x58\xF8\xE2\xC6\x3D\x08\xDF\x4E\x22\x46\xED\x1F\x64\xD2\xD6\x13\xA1\x9D\x8C\x9A\x68\x70\xE6\x18\x8E\x2F\x3A\xD4\x0C\x03\x8F\xDA\x30\x45\x2F\x8D\xDF\xCD\x21\x2A\x6A\x97\x4B\xC2\x5E\xC6\xA0\x56\x4C\x66\xA7\xD2\x87\x50\xFF\x9D\xB4\x58\xB7\x44\x41\xE4\x9E\xE5\xE8\x2D\xBF\x49\x74\xD6\x45\x67\x8E\x0A\xD0\x31\xF9\x7A\xAB\xA8\x55\x45\x1E\xEF\x17\xA8\x9B\x42\x82\x1E\x53\x08\x16\xDD\x57\x93\xA8\x3B\x7A\x82\xE8\xED\xE8\x1E\x7F\x33\x95\x69\x1F\x76\x17\x84\xF8\xBC\x62\x79\x61\xCD\x40\x84\x5E\xE9\x08\xA4\x0B\x9D\x1F\x01\x92\x7B\x38\xEB\x1A\x7D\x4E\xFD\x60\xDB\x09\x44\xF7\xEC\x1B\x83\x2B\x7E\x6E\xB1\x83\x3F\x9A\x35\x15\x76\xAD\x5D\xE5\x71\xFA\xE8\x86\x5D\xA7\x51\x4F\x06\xB0\xFB\xF3\x8C\x1F\x2A\x85\x38\xF5\xD3\x8B\x4E\x18\x00\x1C\xCB\xB9\xDD\xCB\x48\x85\x30\xF6\x08\x6D\x14\x74\x4D\x8B\x56\x72\x16\x6E\x48\xE9\xEF\x93\x77\x25\x75\xDB\x66\xB6\xF2\x57\xC6\xFF\xAD\x6E\x2C\x29\x15\x10\xC5\xED\x02\xE1\xA8\xB2\x4B\x44\xEC\x1E\x2A\x91\x68\x62\x38\xE8\xDE\xFD\x18\xC0\x19\x98\x63\x4A\x50\x76\xA6\xB7\xF8\x5F\xC8\x1A\x1D\x61\xA1\x5B\x2C\x52\x8D\xFA\x08\x2C\xE3\xE3\xE2\xCA\x64\x9A\xC0\x48\x17\xEC\x5C\x12\x3E\x0B\x76\x1A\xB1\x03\xF7\x80\xC0\x14\xF0\x21\xBB\xEB\x7E\xA3\xB8\x6E\x0C\xA1\xC8\x33\xE3\x8E\xF5\xC8\x97\xA6\xD7\xE1\xF4\xA2\x39\x8C\x49\x0B\x3D\x65\xE2\xF4\x5C\x7F\xAE\x40\x2D\x1D\xF1\x69\x8B\x6F\xDD\xB1\x85\x48\x16\x64\x87\x1C\x26\x64\xBF\xD1\x68\x6B\x2B\x33\x72\x78\x3F\x18\x56\xF6\x24\x7A\x3F\x84\x37\xA2\x81\x8F\x68\xB7\xC4\xEA\x13\xA5\xF5\x7B\x73\xC7\x28\x70\xB6\x84\x04\x5F\x14", - 481)); - adder(YACAtomEOCEncode(&Got, buf + Off, len - Off)); // .ints.neg - - adder( - YACAtomStrEncode(&Got, buf + Off, len - Off, (const unsigned char *)"pos", 3)); - adder(YACAtomListEncode(&Got, buf + Off, len - Off)); // .ints.pos - adder(YACAtomUintEncode(&Got, buf + Off, len - Off, 0)); - adder(YACAtomUintEncode(&Got, buf + Off, len - Off, 1)); - adder(YACAtomUintEncode(&Got, buf + Off, len - Off, 31)); - adder(YACAtomUintEncode(&Got, buf + Off, len - Off, 32)); - adder(YACAtomUintEncode(&Got, buf + Off, len - Off, 123)); - adder(YACAtomUintEncode(&Got, buf + Off, len - Off, 1234)); - adder(YACAtomUintEncode(&Got, buf + Off, len - Off, 12345678)); - adder(YACAtomRawEncode( - &Got, - buf + Off, - len - Off, - YACAtomPint, - (const unsigned char *)"\x8B\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", - 12)); - adder(YACAtomRawEncode( - &Got, - buf + Off, - len - Off, - YACAtomPint, - (const unsigned char - *)"\x91\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", - 18)); - adder(YACAtomEOCEncode(&Got, buf + Off, len - Off)); // .ints.pos - - adder(YACAtomEOCEncode(&Got, buf + Off, len - Off)); // .ints - - adder( - YACAtomStrEncode(&Got, buf + Off, len - Off, (const unsigned char *)"uuid", 4)); - adder(YACAtomUUIDEncode( - &Got, - buf + Off, - len - Off, - (const unsigned char - *)"\x0e\x87\x5e\x3f\xd3\x85\x49\xeb\x87\xb4\xbe\x42\xd6\x41\xc3\x67")); - - adder(YACAtomStrEncode( - &Got, buf + Off, len - Off, (const unsigned char *)"dates", 5)); - adder(YACAtomListEncode(&Got, buf + Off, len - Off)); // .dates - { - struct timespec ts; - ts.tv_sec = 1234567890; - assert(YACTimespecToTAI(&ts)); - unsigned char tai[12] = {0}; - assert(YACTimespecToTAI64(tai, &ts)); - adder(YACAtomTAI64Encode(&Got, buf + Off, len - Off, tai, 8)); - - ts.tv_nsec = 456000; - assert(YACTimespecToTAI64(tai, &ts)); - adder(YACAtomTAI64Encode(&Got, buf + Off, len - Off, tai, 12)); - - adder(YACAtomRawEncode( - &Got, - buf + Off, - len - Off, - YACAtomTAI64N, - (const unsigned char *)"\x40\x00\x00\x00\x49\x96\x02\xF4\x00\x06\xF8\x55", - 12)); - - adder(YACAtomRawEncode( - &Got, - buf + Off, - len - Off, - YACAtomTAI64NA, - (const unsigned char - *)"\x40\x00\x00\x00\x49\x96\x02\xF4\x00\x06\xF8\x55\x07\x5B\xCD\x15", - 16)); - } - adder(YACAtomEOCEncode(&Got, buf + Off, len - Off)); // .dates - - adder(YACAtomStrEncode( - &Got, buf + Off, len - Off, (const unsigned char *)"floats", 6)); - adder(YACAtomListEncode(&Got, buf + Off, len - Off)); // .floats - adder(YACAtomRawEncode( - &Got, - buf + Off, - len - Off, - YACAtomFloat32, - (const unsigned char *)"\x01\x02\x03\x04", - 4)); - adder(YACAtomEOCEncode(&Got, buf + Off, len - Off)); // .floats - - adder(YACAtomStrEncode( - &Got, buf + Off, len - Off, (const unsigned char *)"empties", 7)); - adder(YACAtomListEncode(&Got, buf + Off, len - Off)); // .empties - adder(YACAtomListEncode(&Got, buf + Off, len - Off)); - adder(YACAtomEOCEncode(&Got, buf + Off, len - Off)); - adder(YACAtomMapEncode(&Got, buf + Off, len - Off)); - adder(YACAtomEOCEncode(&Got, buf + Off, len - Off)); - adder(YACAtomBlobEncode(&Got, buf + Off, len - Off, 123)); - adder(YACAtomBinEncode(&Got, buf + Off, len - Off, NULL, 0)); - memset(bin, '\x00', 16); - adder(YACAtomUUIDEncode(&Got, buf + Off, len - Off, bin)); - adder(YACAtomRawEncode( - &Got, - buf + Off, - len - Off, - YACAtomTAI64, - (const unsigned char *)"\x00\x00\x00\x00\x00\x00\x00\x00", - 8)); - adder(YACAtomEOCEncode(&Got, buf + Off, len - Off)); // .empties - - adder(YACAtomEOCEncode(&Got, buf + Off, len - Off)); // . - - free(bin); - assert(write(STDOUT_FILENO, buf, Off) == (ssize_t)Off); - free(buf); - - return EXIT_SUCCESS; -} diff --git a/cyac/doc/atom.texi b/cyac/doc/atom.texi deleted file mode 100644 index 0ad1bff..0000000 --- a/cyac/doc/atom.texi +++ /dev/null @@ -1,29 +0,0 @@ -@node Atom -@cindex atom -@unnumbered Atom - -@anchor{YACAtom} -@DOCSTRING YACAtom@ - -@anchor{YACItemType} -@DOCSTRING YACItemType@ - -@DOCSTRING YACAtomDecode@ - -@DOCSTRING YACAtomEOCEncode@ -@anchor{YACAtomNILEncode} -@DOCSTRING YACAtomNILEncode@ -@DOCSTRING YACAtomBoolEncode@ -@DOCSTRING YACAtomUUIDEncode@ -@DOCSTRING YACAtomUintEncode@ -@DOCSTRING YACAtomSintEncode@ -@DOCSTRING YACAtomListEncode@ -@DOCSTRING YACAtomMapEncode@ -@DOCSTRING YACAtomBlobEncode@ -@DOCSTRING YACAtomStrEncode@ -@anchor{YACAtomBinEncode} -@DOCSTRING YACAtomBinEncode@ -@anchor{YACAtomChunkEncode} -@DOCSTRING YACAtomChunkEncode@ -@DOCSTRING YACAtomTAI64Encode@ -@DOCSTRING YACAtomRawEncode@ diff --git a/cyac/doc/items.texi b/cyac/doc/items.texi deleted file mode 100644 index d80a750..0000000 --- a/cyac/doc/items.texi +++ /dev/null @@ -1,24 +0,0 @@ -@node Items -@cindex items -@unnumbered Items - -Streamable decoding by one atom is not very convenient in many cases. -There is ability to recursively decode the whole structures. - -@anchor{YACItems} -@DOCSTRING YACItems@ -@anchor{YACItem} -@DOCSTRING YACItem@ -@DOCSTRING YACItemsInit@ -@anchor{YACItemsGrow} -@DOCSTRING YACItemsGrow@ -@anchor{YACItemsParse} -@DOCSTRING YACItemsParse@ -@DOCSTRING YACItemsEncode@ -@DOCSTRING YACItemsGetByKeyLen@ -@anchor{YACItemsGetByKey} -@DOCSTRING YACItemsGetByKey@ -@DOCSTRING YACItemsGetByKeyAndType@ -@DOCSTRING YACStrEqual@ -@DOCSTRING YACListHasOnlyType@ -@DOCSTRING YACMapHasOnlyType@ diff --git a/cyac/doc/pki.texi b/cyac/doc/pki.texi deleted file mode 100644 index 745fa9b..0000000 --- a/cyac/doc/pki.texi +++ /dev/null @@ -1,19 +0,0 @@ -@node PKI -@cindex PKI -@unnumbered PKI - -@file{lib/pki} contains PKI-related code. It is not directly related to -the YAC codec, so it is placed isolated nearby. Currently there are -functions to deal with certificate verification: - -@anchor{YACCer} -@DOCSTRING YACCer@ - -@DOCSTRING YACCerParse@ - -@DOCSTRING YACCerVerify@ - -@DOCSTRING YACCerVerifyOpts@ - -@anchor{YACCerSigVerifier} -@DOCSTRING YACCerSigVerifier@ diff --git a/cyac/doc/tai64.texi b/cyac/doc/tai64.texi deleted file mode 100644 index 17a3d0a..0000000 --- a/cyac/doc/tai64.texi +++ /dev/null @@ -1,13 +0,0 @@ -@node Datetime -@cindex TAI64 -@cindex datetime -@unnumbered Datetime - -YAC uses @url{http://cr.yp.to/libtai/tai64.html, TAI64} for datetime -objects. There are helpers to convert it to UTC and vice versa. - -@DOCSTRING YACTAI64ToTimespec@ -@DOCSTRING YACTimespecToUTC@ -@DOCSTRING YACTimespecToTAI64@ -@DOCSTRING YACTimespecToTAI@ -@DOCSTRING YACLeapsecs@ diff --git a/cyac/lib/atoms.h b/cyac/lib/atoms.h deleted file mode 100644 index bf3c255..0000000 --- a/cyac/lib/atoms.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef YAC_ATOMS_H -#define YAC_ATOMS_H - -enum YACAtomType { - YACAtomEOC = 0x00, - YACAtomNIL = 0x01, - YACAtomFalse = 0x02, - YACAtomTrue = 0x03, - YACAtomUUID = 0x04, - YACAtomList = 0x08, - YACAtomMap = 0x09, - YACAtomBlob = 0x0B, - YACAtomPint = 0x0C, - YACAtomNint = 0x0D, - YACAtomFloat16 = 0x10, - YACAtomFloat32 = 0x11, - YACAtomFloat64 = 0x12, - YACAtomFloat128 = 0x13, - YACAtomFloat256 = 0x14, - YACAtomTAI64 = 0x18, - YACAtomTAI64N = 0x19, - YACAtomTAI64NA = 0x1A, - - YACAtomStrings = 0x80, - YACAtomIsUTF8 = 0x40, -}; - -#endif // YAC_ATOMS_H diff --git a/cyac/lib/dectai.h b/cyac/lib/dectai.h deleted file mode 100644 index 401bb14..0000000 --- a/cyac/lib/dectai.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef YAC_DECTAI_H -#define YAC_DECTAI_H - -#include -#include - -#include "err.h" - -// TEXINFO: YACTAI64ToTimespec -// @deftypefun {enum YACErr} YACTAI64ToTimespec @ -// (struct timespec *tv, const unsigned char *buf, const size_t len) -// Convert TAI64* value from @var{buf} to @var{ts} structure. -// @code{YACErrTAI64InPast} error is returned if value represents time -// before 1970. Some systems support those dates, but not guaranteed to. -// @code{YACErrTAI64TooBig} error is returned when time is out of bounds -// of @code{time_t} representation. @code{YACErrTAI64BadAsec} is -// returned if TAI64NA is provided, because currently no systems support -// attoseconds. -// @end deftypefun -enum YACErr -YACTAI64ToTimespec(struct timespec *ts, const unsigned char *buf, const size_t len); - -// TEXINFO: YACTimespecToUTC -// @deftypefun {enum YACErr} YACTimespecToUTC (struct timespec *ts) -// Convert TAI stored in @var{ts} structure to UTC. @code{YACErrTAI64InPast} -// error is returned if value represents time before 1970. -// @end deftypefun -enum YACErr -YACTimespecToUTC(struct timespec *ts); - -#endif // YAC_DECTAI_H diff --git a/cyac/lib/err.h b/cyac/lib/err.h deleted file mode 100644 index 8debb4d..0000000 --- a/cyac/lib/err.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef YAC_ERR_H -#define YAC_ERR_H - -// TEXINFO: YACErr -// @deftp {Data type} {enum YACErr} -// Errors are just a predefined enumeration value. -// @table @code -// @item YACErrInvalid -// Unset error, must be never met. -// @item YACErrNo -// No error, everything is good. -// @item YACErrNotEnough -// Not enough data. Atom's @code{.off} must contain how much. -// @item YACErrUnknownType, // unknown atom's type -// Unknown atom's type. -// @item YACErrLenTooBig, -// Too long string (>1<<60), can not be decoded. -// @item YACErrBadUTF8 -// Invalid UTF-8 codepoint or zero byte met. -// @item YACErrIntNonMinimal -// Non minimal integer encoding. -// @item YACErrBlobBadAtom -// Blob contains unexpected atom. -// @item YACErrBlobBadTerm -// Blob contains invalid terminator. -// @item YACErrTAI64TooBig -// Too large TAI64 value, out-of-bounds. -// @item YACErrTAI64BadNsec -// Invalid TAI64 nanoseconds value. -// @item YACErrTAI64BadAsec -// Invalid TAI64 attoseconds value. -// @item YACErrMapBadKey -// Either bad type of map's key, or it is empty. -// @item YACErrMapUnordered -// Unordered map keys. -// @item YACErrNoMem -// Not enough memory for allocation. -// @item YACErrUnsatisfiedSchema -// Unsatisfied structure's schema. -// @item YACErrDeepRecursion -// Too deep recursion involved during parsing. -// @item YACErrUnexpectedEOC -// Unexpected EOC met. -// @end table -// @end deftp -enum YACErr { - YACErrInvalid = 0, - YACErrNo = 1, - YACErrNotEnough, - YACErrUnknownType, - YACErrLenTooBig, - YACErrBadUTF8, - YACErrIntNonBin, - YACErrIntNonMinimal, - YACErrBlobBadAtom, - YACErrBlobBadTerm, - YACErrTAI64TooBig, - YACErrTAI64BadNsec, - YACErrTAI64BadAsec, - YACErrTAI64InPast, - YACErrTAI64IsLeap, - YACErrTAI64NonMinimal, - YACErrMapBadKey, - YACErrMapUnordered, - YACErrNoMem, - YACErrUnsatisfiedSchema, - YACErrDeepRecursion, - YACErrUnexpectedEOC, -}; - -// TEXINFO: YACErr2Str -// @deftypefun {const char *} YACErr2Str (const enum YACErr) -// Get human-readable string of the error. -// @end deftypefun -const char * -YACErr2Str(const enum YACErr); - -#endif // YAC_ERR_H diff --git a/cyac/lib/frombe.h b/cyac/lib/frombe.h deleted file mode 100644 index 78651f9..0000000 --- a/cyac/lib/frombe.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef YAC_FROMBE_H -#define YAC_FROMBE_H - -#include -#include - -// Decode big-endian integer of the length @var{len}. -uint64_t -yacFromBE(const unsigned char *buf, const size_t len); - -#endif // YAC_FROMBE_H diff --git a/cyac/lib/install.do b/cyac/lib/install.do deleted file mode 100644 index c2d5470..0000000 --- a/cyac/lib/install.do +++ /dev/null @@ -1,6 +0,0 @@ -redo-ifchange *.h libyac.a ../conf/prefix -read PREFIX <../conf/prefix -mkdir -p $PREFIX/include/yac $PREFIX/lib -cp -f *.h $PREFIX/include/yac -cp -f libyac.a $PREFIX/lib -chmod 644 $PREFIX/include/yac/*.h $PREFIX/lib/libyac.a diff --git a/cyac/lib/leapsecs.h b/cyac/lib/leapsecs.h deleted file mode 100644 index 726c797..0000000 --- a/cyac/lib/leapsecs.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef YAC_LEAPSECS_H -#define YAC_LEAPSECS_H - -#include - -// TEXINFO: YACLeapsecs -// @deftypevar {const int64_t *} YACLeapsecs -// Leap seconds database. It contains TAI seconds when an additional -// second was added. @var{YACLeapsecsN} variable holds the length of -// that list. -// @end deftypevar -extern const int64_t YACLeapsecsN; -extern const int64_t YACLeapsecs[]; - -#endif // YAC_LEAPSECS_H diff --git a/cyac/lib/pki/.gitignore b/cyac/lib/pki/.gitignore deleted file mode 100644 index 60f79ef..0000000 --- a/cyac/lib/pki/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/libyacpki.a diff --git a/cyac/lib/pki/install.do b/cyac/lib/pki/install.do deleted file mode 100644 index 219b91b..0000000 --- a/cyac/lib/pki/install.do +++ /dev/null @@ -1,6 +0,0 @@ -redo-ifchange *.h libyacpki.a ../../conf/prefix -read PREFIX <../../conf/prefix -mkdir -p $PREFIX/include/yac/pki $PREFIX/lib -cp -f *.h $PREFIX/include/yac/pki -cp -f libyacpki.a $PREFIX/lib -chmod 644 $PREFIX/include/yac/pki/*.h $PREFIX/lib/libyacpki.a diff --git a/cyac/lib/tobe.h b/cyac/lib/tobe.h deleted file mode 100644 index 2b0318e..0000000 --- a/cyac/lib/tobe.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef YAC_TOBE_H -#define YAC_TOBE_H - -#include -#include - -// Store big-endian integer of the length @var{len}. -void -yacToBE(unsigned char *buf, const size_t len, const uint64_t v); - -#endif // YAC_TOBE_H diff --git a/cyac/lib/utf8.h b/cyac/lib/utf8.h deleted file mode 100644 index 6c455e0..0000000 --- a/cyac/lib/utf8.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef YAC_UTF8_H -#define YAC_UTF8_H - -#include -#include - -extern const uint32_t YACUTF8InvalidCp; - -size_t -YACUTF8CpDecode(uint32_t *cp, const unsigned char *str, const size_t len); - -#endif // YAC_UTF8_H diff --git a/gyac/COPYING b/go/COPYING similarity index 100% rename from gyac/COPYING rename to go/COPYING diff --git a/gyac/COPYING.LESSER b/go/COPYING.LESSER similarity index 100% rename from gyac/COPYING.LESSER rename to go/COPYING.LESSER diff --git a/gyac/README b/go/README similarity index 54% rename from gyac/README rename to go/README index a49cdf6..9f02496 100644 --- a/gyac/README +++ b/go/README @@ -1,7 +1,7 @@ -Go implementation of the YAC codec. +GoKEKS is Go implementation of the KEKS codec. * No FLOAT*, INTs greater than 64-bit, TAI64NA. They are stored/decoded just as a raw value * Actual negative integer maximal size is -2^63-1 -gyac is free software: see the file COPYING.LESSER for copying conditions. +GoKEKS is free software: see the file COPYING.LESSER for copying conditions. diff --git a/gyac/atom/be/be.go b/go/atom/be/be.go similarity index 98% rename from gyac/atom/be/be.go rename to go/atom/be/be.go index 3773c41..3d16b7e 100644 --- a/gyac/atom/be/be.go +++ b/go/atom/be/be.go @@ -1,4 +1,4 @@ -// gyac -- Go YAC encoder implementation +// keks -- Go KEKS encoder implementation // Copyright (C) 2024-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify diff --git a/gyac/atom/dec.go b/go/atom/dec.go similarity index 96% rename from gyac/atom/dec.go rename to go/atom/dec.go index 59dca13..1497914 100644 --- a/gyac/atom/dec.go +++ b/go/atom/dec.go @@ -1,4 +1,4 @@ -// gyac -- Go YAC encoder implementation +// keks -- Go KEKS encoder implementation // Copyright (C) 2024-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify @@ -25,8 +25,8 @@ import ( "github.com/google/uuid" - "go.cypherpunks.su/yac/gyac/atom/be" - "go.cypherpunks.su/yac/gyac/types" + "go.cypherpunks.su/keks/atom/be" + "go.cypherpunks.su/keks/types" ) var ( @@ -75,7 +75,7 @@ func strDecode(r io.Reader, tag byte) (read int64, v []byte, err error) { return } -// Decode a single YAC-encoded atom. Atom means that it does not decode +// Decode a single KEKS-encoded atom. Atom means that it does not decode // full lists, maps, blobs and may return types.EOC. func Decode(r io.Reader) (t types.Type, v any, read int64, err error) { buf := make([]byte, 1) diff --git a/gyac/atom/enc.go b/go/atom/enc.go similarity index 98% rename from gyac/atom/enc.go rename to go/atom/enc.go index d9979f4..10f15ac 100644 --- a/gyac/atom/enc.go +++ b/go/atom/enc.go @@ -1,4 +1,4 @@ -// gyac -- Go YAC encoder implementation +// keks -- Go KEKS encoder implementation // Copyright (C) 2024-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify @@ -22,7 +22,7 @@ import ( "github.com/google/uuid" - "go.cypherpunks.su/yac/gyac/atom/be" + "go.cypherpunks.su/keks/atom/be" ) var bigIntZero = big.NewInt(0) diff --git a/gyac/atom/raw.go b/go/atom/raw.go similarity index 96% rename from gyac/atom/raw.go rename to go/atom/raw.go index 337bea5..1528c9f 100644 --- a/gyac/atom/raw.go +++ b/go/atom/raw.go @@ -1,4 +1,4 @@ -// gyac -- Go YAC encoder implementation +// keks -- Go KEKS encoder implementation // Copyright (C) 2024-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify diff --git a/gyac/atom/type_string.go b/go/atom/type_string.go similarity index 100% rename from gyac/atom/type_string.go rename to go/atom/type_string.go diff --git a/gyac/blob.go b/go/blob.go similarity index 94% rename from gyac/blob.go rename to go/blob.go index 3aa4cda..2a74d8c 100644 --- a/gyac/blob.go +++ b/go/blob.go @@ -1,4 +1,4 @@ -// gyac -- Go YAC encoder implementation +// keks -- Go KEKS encoder implementation // Copyright (C) 2024-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify @@ -13,7 +13,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with this program. If not, see . -package gyac +package keks import ( "fmt" diff --git a/gyac/cmd/print/main.go b/go/cmd/print/main.go similarity index 70% rename from gyac/cmd/print/main.go rename to go/cmd/print/main.go index 2d33fb4..57a1cce 100644 --- a/gyac/cmd/print/main.go +++ b/go/cmd/print/main.go @@ -6,11 +6,11 @@ import ( "log" "os" - "go.cypherpunks.su/yac/gyac" + "go.cypherpunks.su/keks" ) func main() { - item, read, err := gyac.Decode(bufio.NewReader(os.Stdin)) + item, read, err := keks.Decode(bufio.NewReader(os.Stdin)) if err != nil { log.Fatal(err) } diff --git a/gyac/cmd/test-vector-anys/main.go b/go/cmd/test-vector-anys/main.go similarity index 89% rename from gyac/cmd/test-vector-anys/main.go rename to go/cmd/test-vector-anys/main.go index c307203..48fb67b 100644 --- a/gyac/cmd/test-vector-anys/main.go +++ b/go/cmd/test-vector-anys/main.go @@ -11,8 +11,8 @@ import ( "github.com/google/uuid" - "go.cypherpunks.su/yac/gyac" - "go.cypherpunks.su/yac/gyac/atom" + "go.cypherpunks.su/keks" + "go.cypherpunks.su/keks/atom" ) func mustHexDec(s string) []byte { @@ -80,15 +80,15 @@ func main() { "utf8": "привет мир", }, "blob": []any{ - gyac.Blob{ChunkLen: 12, R: strings.NewReader("5")}, - gyac.Blob{ChunkLen: 12, R: strings.NewReader(strings.Repeat("6", 12))}, - gyac.Blob{ChunkLen: 12, R: strings.NewReader(strings.Repeat("7", 13))}, - gyac.Blob{ChunkLen: 5, R: strings.NewReader("1234567890-")}, + keks.Blob{ChunkLen: 12, R: strings.NewReader("5")}, + keks.Blob{ChunkLen: 12, R: strings.NewReader(strings.Repeat("6", 12))}, + keks.Blob{ChunkLen: 12, R: strings.NewReader(strings.Repeat("7", 13))}, + keks.Blob{ChunkLen: 5, R: strings.NewReader("1234567890-")}, }, "empties": []any{ []any{}, map[string]any{}, - gyac.Blob{ChunkLen: 123, R: bytes.NewReader(nil)}, + keks.Blob{ChunkLen: 123, R: bytes.NewReader(nil)}, uuid.Nil, atom.Raw{T: atom.TAI64, V: mustHexDec("0000000000000000")}, }, @@ -106,7 +106,7 @@ func main() { }, "uuid": uuid.MustParse("0e875e3f-d385-49eb-87b4-be42d641c367"), } - item, err := gyac.FromGo(data) + item, err := keks.FromGo(data) if err != nil { log.Fatal(err) } diff --git a/gyac/cmd/test-vector-manual/main.go b/go/cmd/test-vector-manual/main.go similarity index 99% rename from gyac/cmd/test-vector-manual/main.go rename to go/cmd/test-vector-manual/main.go index 151a7e4..79c4a3a 100644 --- a/gyac/cmd/test-vector-manual/main.go +++ b/go/cmd/test-vector-manual/main.go @@ -10,7 +10,7 @@ import ( "github.com/google/uuid" "go.cypherpunks.su/tai64n/v4" - "go.cypherpunks.su/yac/gyac/atom" + "go.cypherpunks.su/keks/atom" ) func mustHexDec(s string) []byte { diff --git a/gyac/dec.go b/go/dec.go similarity index 96% rename from gyac/dec.go rename to go/dec.go index 5b51597..0cec447 100644 --- a/gyac/dec.go +++ b/go/dec.go @@ -1,4 +1,4 @@ -// gyac -- Go YAC encoder implementation +// keks -- Go KEKS encoder implementation // Copyright (C) 2024-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify @@ -13,15 +13,15 @@ // You should have received a copy of the GNU Lesser General Public // License along with this program. If not, see . -package gyac +package keks import ( "bytes" "errors" "io" - "go.cypherpunks.su/yac/gyac/atom" - "go.cypherpunks.su/yac/gyac/types" + "go.cypherpunks.su/keks/atom" + "go.cypherpunks.su/keks/types" ) const parseMaxRecursionDepth = 1 << 10 @@ -192,7 +192,7 @@ func decode( return } -// Decode single YAC-encoded data item. +// Decode single KEKS-encoded data item. func Decode(r io.Reader) (item Item, read int64, err error) { item, read, err = decode(r, true, 0) if item.T == types.EOC { diff --git a/go/doc.go b/go/doc.go new file mode 100644 index 0000000..126d303 --- /dev/null +++ b/go/doc.go @@ -0,0 +1,6 @@ +// KEKS (http://www.keks.cypherpunks.su) is compact, deterministic, +// concise and streaming binary serialisation format. It is aimed to be +// lightweight in terms of CPU, memory, storage and codec implementation +// size usage. It supports wide range of data types, making it able to +// transparently replace JSON. +package keks diff --git a/gyac/enc.go b/go/enc.go similarity index 96% rename from gyac/enc.go rename to go/enc.go index 6506fb3..eb3910e 100644 --- a/gyac/enc.go +++ b/go/enc.go @@ -1,4 +1,4 @@ -// gyac -- Go YAC encoder implementation +// keks -- Go KEKS encoder implementation // Copyright (C) 2024-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify @@ -13,7 +13,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with this program. If not, see . -package gyac +package keks import ( "bytes" @@ -24,8 +24,8 @@ import ( "github.com/google/uuid" - "go.cypherpunks.su/yac/gyac/atom" - "go.cypherpunks.su/yac/gyac/types" + "go.cypherpunks.su/keks/atom" + "go.cypherpunks.su/keks/types" ) // Encode an item. diff --git a/gyac/fromgo.go b/go/fromgo.go similarity index 97% rename from gyac/fromgo.go rename to go/fromgo.go index d7beeed..6c22467 100644 --- a/gyac/fromgo.go +++ b/go/fromgo.go @@ -1,4 +1,4 @@ -// gyac -- Go YAC encoder implementation +// keks -- Go KEKS encoder implementation // Copyright (C) 2024-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify @@ -13,7 +13,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with this program. If not, see . -package gyac +package keks import ( "fmt" @@ -25,13 +25,13 @@ import ( "github.com/google/uuid" "go.cypherpunks.su/tai64n/v4" - "go.cypherpunks.su/yac/gyac/atom" - "go.cypherpunks.su/yac/gyac/types" + "go.cypherpunks.su/keks/atom" + "go.cypherpunks.su/keks/types" ) func structTagRead(f reflect.StructField) (name string, omit bool) { name = f.Name - v, ok := f.Tag.Lookup("yac") + v, ok := f.Tag.Lookup("keks") if !ok { return } diff --git a/gyac/fuzz_test.go b/go/fuzz_test.go similarity index 97% rename from gyac/fuzz_test.go rename to go/fuzz_test.go index b46304b..c9bc4c6 100644 --- a/gyac/fuzz_test.go +++ b/go/fuzz_test.go @@ -1,4 +1,4 @@ -package gyac +package keks import ( "bytes" diff --git a/gyac/go.mod b/go/go.mod similarity index 80% rename from gyac/go.mod rename to go/go.mod index 7ec9b5a..e1b4cc9 100644 --- a/gyac/go.mod +++ b/go/go.mod @@ -1,4 +1,4 @@ -module go.cypherpunks.su/yac/gyac +module go.cypherpunks.su/keks go 1.22 diff --git a/gyac/go.sum b/go/go.sum similarity index 100% rename from gyac/go.sum rename to go/go.sum diff --git a/gyac/mapstruct/dec.go b/go/mapstruct/dec.go similarity index 83% rename from gyac/mapstruct/dec.go rename to go/mapstruct/dec.go index 08415e8..6ec8b2e 100644 --- a/gyac/mapstruct/dec.go +++ b/go/mapstruct/dec.go @@ -1,4 +1,4 @@ -// gyac -- Go YAC encoder implementation +// keks -- Go KEKS encoder implementation // Copyright (C) 2024-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify @@ -19,15 +19,15 @@ import ( "errors" "io" - "go.cypherpunks.su/yac/gyac" - "go.cypherpunks.su/yac/gyac/types" + "go.cypherpunks.su/keks" + "go.cypherpunks.su/keks/types" ) -// Decode YAC-encoded data to the dst structure. +// Decode KEKS-encoded data to the dst structure. // It will return an error if decoded data is not map. func Decode(dst any, src io.Reader) (err error) { - var item gyac.Item - item, _, err = gyac.Decode(src) + var item keks.Item + item, _, err = keks.Decode(src) if err != nil { return } diff --git a/gyac/mapstruct/map.go b/go/mapstruct/map.go similarity index 93% rename from gyac/mapstruct/map.go rename to go/mapstruct/map.go index ffcd493..cec5f6a 100644 --- a/gyac/mapstruct/map.go +++ b/go/mapstruct/map.go @@ -1,4 +1,4 @@ -// gyac -- Go YAC encoder implementation +// keks -- Go KEKS encoder implementation // Copyright (C) 2024-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify @@ -22,7 +22,7 @@ import ( // Fill up dst structure with the contents taken from the src map. func FromMap(dst any, src map[string]any) error { decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ - Result: dst, TagName: "yac", + Result: dst, TagName: "keks", }) if err != nil { return err diff --git a/gyac/mk-fuzz-testdata b/go/mk-fuzz-testdata similarity index 91% rename from gyac/mk-fuzz-testdata rename to go/mk-fuzz-testdata index 3c4ea8f..32e91d0 100755 --- a/gyac/mk-fuzz-testdata +++ b/go/mk-fuzz-testdata @@ -4,7 +4,7 @@ root="$(dirname "$(realpath -- "$0")")" tmp=$(mktemp -d) trap "rm -fr $tmp" HUP PIPE INT QUIT TERM EXIT cd $tmp -PATH="$root/../tyac:$PATH" +PATH="$root/../tcl:$PATH" mk-fuzz-inputs cd "$root" dst=testdata/fuzz/FuzzItemDecode diff --git a/gyac/pki/algo.go b/go/pki/algo.go similarity index 63% rename from gyac/pki/algo.go rename to go/pki/algo.go index 22d3b76..c85029b 100644 --- a/gyac/pki/algo.go +++ b/go/pki/algo.go @@ -1,8 +1,8 @@ package pki import ( - "go.cypherpunks.su/yac/gyac/pki/ed25519-blake2b" - "go.cypherpunks.su/yac/gyac/pki/gost" + "go.cypherpunks.su/keks/pki/ed25519-blake2b" + "go.cypherpunks.su/keks/pki/gost" ) const ( diff --git a/gyac/pki/av.go b/go/pki/av.go similarity index 83% rename from gyac/pki/av.go rename to go/pki/av.go index 83c9e48..830bfc1 100644 --- a/gyac/pki/av.go +++ b/go/pki/av.go @@ -6,14 +6,14 @@ import ( "github.com/google/uuid" - "go.cypherpunks.su/yac/gyac" - pkihash "go.cypherpunks.su/yac/gyac/pki/hash" + "go.cypherpunks.su/keks" + pkihash "go.cypherpunks.su/keks/pki/hash" ) // Algorithm-value often used structure. type AV struct { - A string `yac:"a"` - V []byte `yac:"v"` + A string `keks:"a"` + V []byte `keks:"v"` } // Calculate UUID of the AV. UUIDv4 is generated from the hash output of @@ -30,7 +30,7 @@ func (av *AV) Id() (id uuid.UUID) { id = uuid.Nil return } - item, err := gyac.FromGo(av) + item, err := keks.FromGo(av) if err != nil { panic(err) } diff --git a/gyac/pki/cer.go b/go/pki/cer.go similarity index 90% rename from gyac/pki/cer.go rename to go/pki/cer.go index bd48070..bfdb495 100644 --- a/gyac/pki/cer.go +++ b/go/pki/cer.go @@ -8,10 +8,10 @@ import ( "github.com/google/uuid" - "go.cypherpunks.su/yac/gyac" - "go.cypherpunks.su/yac/gyac/mapstruct" - ed25519blake2b "go.cypherpunks.su/yac/gyac/pki/ed25519-blake2b" - "go.cypherpunks.su/yac/gyac/pki/gost" + "go.cypherpunks.su/keks" + "go.cypherpunks.su/keks/mapstruct" + ed25519blake2b "go.cypherpunks.su/keks/pki/ed25519-blake2b" + "go.cypherpunks.su/keks/pki/gost" ) const ( @@ -21,17 +21,17 @@ const ( // Public key. type Pub struct { - A string `yac:"a"` - V []byte `yac:"v"` - Id uuid.UUID `yac:"id"` + A string `keks:"a"` + V []byte `keks:"v"` + Id uuid.UUID `keks:"id"` } // Certificate load (contents). type CerLoad struct { - KU *map[string]*struct{} `yac:"ku,omitempty"` - Subj map[string]string `yac:"sub"` - Crit *[]map[string]any `yac:"crit,omitempty"` - Pub []Pub `yac:"pub"` + KU *map[string]*struct{} `keks:"ku,omitempty"` + Subj map[string]string `keks:"sub"` + Crit *[]map[string]any `keks:"crit,omitempty"` + Pub []Pub `keks:"pub"` } // Parse SignedData contents as CerLoad (certificate) and check its @@ -96,7 +96,7 @@ func (sd *SignedData) CerParse() error { return nil } -// Parse YAC-encoded data as SignedData with the CerLoad (certificate) contents. +// Parse KEKS-encoded data as SignedData with the CerLoad (certificate) contents. func CerParse(data []byte) (sd *SignedData, err error) { sd, err = SignedDataParse(data) if err != nil { @@ -176,8 +176,8 @@ func (sd *SignedData) CerCheckSignatureFrom(parent *CerLoad) (err error) { return } tbs := SignedDataTBS{T: sd.Load.T, V: sd.Load.V, TBS: sig.TBS} - var item gyac.Item - item, err = gyac.FromGo(tbs) + var item keks.Item + item, err = keks.FromGo(tbs) if err != nil { return } diff --git a/gyac/pki/cmd/yacertool/basic.t b/go/pki/cmd/kekscertool/basic.t similarity index 72% rename from gyac/pki/cmd/yacertool/basic.t rename to go/pki/cmd/kekscertool/basic.t index fccc5d3..14b9c48 100755 --- a/gyac/pki/cmd/yacertool/basic.t +++ b/go/pki/cmd/kekscertool/basic.t @@ -11,37 +11,37 @@ echo "gost3410-512C gost3410-256A ed25519-blake2b ed25519-blake2b" | while read caAlgo eeAlgo ; do subj="-subj CN=CA -subj C=RU" -test_expect_success "$caAlgo: CA generation" "yacertool \ +test_expect_success "$caAlgo: CA generation" "kekscertool \ -algo $caAlgo \ -ku ca -ku sig $subj \ -prv $TMPDIR/ca.prv -cer $TMPDIR/ca.cer" -test_expect_success "$caAlgo: CA regeneration" "yacertool \ +test_expect_success "$caAlgo: CA regeneration" "kekscertool \ -algo $caAlgo \ -ku ca -ku sig $subj \ -prv $TMPDIR/ca.prv -cer $TMPDIR/ca.cer \ -reuse-key" -test_expect_success "$caAlgo: CA self-signature" "yacertool \ +test_expect_success "$caAlgo: CA self-signature" "kekscertool \ -ca-cer $TMPDIR/ca.cer \ -cer $TMPDIR/ca.cer \ -verify" subj="-subj CN=SubCA -subj C=RU" -test_expect_success "$eeAlgo: SubCA generation" "yacertool \ +test_expect_success "$eeAlgo: SubCA generation" "kekscertool \ -algo $eeAlgo \ -ku ca -ku sig $subj \ -prv $TMPDIR/subca.prv -cer $TMPDIR/subca.cer \ -ca-cer $TMPDIR/ca.cer -ca-prv $TMPDIR/ca.prv" -test_expect_success "$eeAlgo: SubCA signature" "yacertool \ +test_expect_success "$eeAlgo: SubCA signature" "kekscertool \ -ca-cer $TMPDIR/ca.cer \ -cer $TMPDIR/subca.cer \ -verify" subj="-subj CN=EE -subj C=RU" -test_expect_success "$eeAlgo: EE generation" "yacertool \ +test_expect_success "$eeAlgo: EE generation" "kekscertool \ -algo $eeAlgo $subj \ -ca-prv $TMPDIR/subca.prv -ca-cer $TMPDIR/subca.cer \ -prv $TMPDIR/ee.prv -cer $TMPDIR/ee.cer" -test_expect_success "$eeAlgo: EE chain" "yacertool \ +test_expect_success "$eeAlgo: EE chain" "kekscertool \ -ca-cer $TMPDIR/ca.cer \ -ca-cer $TMPDIR/subca.cer \ -cer $TMPDIR/ee.cer \ diff --git a/gyac/pki/cmd/yacertool/main.go b/go/pki/cmd/kekscertool/main.go similarity index 92% rename from gyac/pki/cmd/yacertool/main.go rename to go/pki/cmd/kekscertool/main.go index 9b9ee48..7a7e1f4 100644 --- a/gyac/pki/cmd/yacertool/main.go +++ b/go/pki/cmd/kekscertool/main.go @@ -9,11 +9,11 @@ import ( "strings" "time" - "go.cypherpunks.su/yac/gyac" - "go.cypherpunks.su/yac/gyac/pki" - ed25519blake2b "go.cypherpunks.su/yac/gyac/pki/ed25519-blake2b" - "go.cypherpunks.su/yac/gyac/pki/gost" - "go.cypherpunks.su/yac/gyac/pki/utils" + "go.cypherpunks.su/keks" + "go.cypherpunks.su/keks/pki" + ed25519blake2b "go.cypherpunks.su/keks/pki/ed25519-blake2b" + "go.cypherpunks.su/keks/pki/gost" + "go.cypherpunks.su/keks/pki/utils" ) func main() { @@ -121,7 +121,7 @@ func main() { log.Fatal("no -prv is set") } - var item gyac.Item + var item keks.Item var prv crypto.Signer var prvRaw []byte var pub []byte @@ -142,7 +142,7 @@ func main() { if err != nil { log.Fatal(err) } - item, err = gyac.FromGo(pki.AV{A: *algo, V: prvRaw}) + item, err = keks.FromGo(pki.AV{A: *algo, V: prvRaw}) if err != nil { log.Fatal(err) } @@ -179,7 +179,7 @@ func main() { log.Fatal(err) } - item, err = gyac.FromGo(sd) + item, err = keks.FromGo(sd) if err != nil { log.Fatal(err) } diff --git a/gyac/pki/cmd/yacsdtool/main.go b/go/pki/cmd/kekssdtool/main.go similarity index 92% rename from gyac/pki/cmd/yacsdtool/main.go rename to go/pki/cmd/kekssdtool/main.go index 38830c3..781daef 100644 --- a/gyac/pki/cmd/yacsdtool/main.go +++ b/go/pki/cmd/kekssdtool/main.go @@ -10,10 +10,10 @@ import ( "os" "time" - "go.cypherpunks.su/yac/gyac" - "go.cypherpunks.su/yac/gyac/pki" - pkihash "go.cypherpunks.su/yac/gyac/pki/hash" - "go.cypherpunks.su/yac/gyac/pki/utils" + "go.cypherpunks.su/keks" + "go.cypherpunks.su/keks/pki" + pkihash "go.cypherpunks.su/keks/pki/hash" + "go.cypherpunks.su/keks/pki/utils" ) func main() { @@ -98,8 +98,8 @@ func main() { if err != nil { log.Fatal(err) } - var item gyac.Item - item, err = gyac.FromGo(sd) + var item keks.Item + item, err = keks.FromGo(sd) if err != nil { log.Fatal(err) } diff --git a/go/pki/doc.go b/go/pki/doc.go new file mode 100644 index 0000000..196a44d --- /dev/null +++ b/go/pki/doc.go @@ -0,0 +1,2 @@ +// keks/pki provides PKI-related capabilities based on KEKS encoded formats. +package pki diff --git a/gyac/pki/ed25519-blake2b/.gitignore b/go/pki/ed25519-blake2b/.gitignore similarity index 100% rename from gyac/pki/ed25519-blake2b/.gitignore rename to go/pki/ed25519-blake2b/.gitignore diff --git a/gyac/pki/ed25519-blake2b/algo.go b/go/pki/ed25519-blake2b/algo.go similarity index 100% rename from gyac/pki/ed25519-blake2b/algo.go rename to go/pki/ed25519-blake2b/algo.go diff --git a/gyac/pki/ed25519-blake2b/clean b/go/pki/ed25519-blake2b/clean similarity index 100% rename from gyac/pki/ed25519-blake2b/clean rename to go/pki/ed25519-blake2b/clean diff --git a/gyac/pki/ed25519-blake2b/ed25519-to-blake2b.patch b/go/pki/ed25519-blake2b/ed25519-to-blake2b.patch similarity index 98% rename from gyac/pki/ed25519-blake2b/ed25519-to-blake2b.patch rename to go/pki/ed25519-blake2b/ed25519-to-blake2b.patch index 3bbb776..f3cbc22 100644 --- a/gyac/pki/ed25519-blake2b/ed25519-to-blake2b.patch +++ b/go/pki/ed25519-blake2b/ed25519-to-blake2b.patch @@ -2,7 +2,7 @@ +++ ed25519/ed25519.go 2024-12-03 11:07:51.892841000 +0300 @@ -20,11 +20,12 @@ "crypto" - "go.cypherpunks.su/yac/gyac/pki/ed25519-blake2b/edwards25519" + "go.cypherpunks.su/gokeks/pki/ed25519-blake2b/edwards25519" cryptorand "crypto/rand" - "crypto/sha512" "crypto/subtle" diff --git a/gyac/pki/ed25519-blake2b/kp.go b/go/pki/ed25519-blake2b/kp.go similarity index 85% rename from gyac/pki/ed25519-blake2b/kp.go rename to go/pki/ed25519-blake2b/kp.go index e366c33..06dbdc2 100644 --- a/gyac/pki/ed25519-blake2b/kp.go +++ b/go/pki/ed25519-blake2b/kp.go @@ -4,7 +4,7 @@ import ( "crypto" "crypto/rand" - "go.cypherpunks.su/yac/gyac/pki/ed25519-blake2b/ed25519" + "go.cypherpunks.su/keks/pki/ed25519-blake2b/ed25519" ) func NewKeypair() (signer crypto.Signer, prv, pub []byte, err error) { diff --git a/gyac/pki/ed25519-blake2b/mk-from-go b/go/pki/ed25519-blake2b/mk-from-go similarity index 92% rename from gyac/pki/ed25519-blake2b/mk-from-go rename to go/pki/ed25519-blake2b/mk-from-go index 80c7493..666b053 100755 --- a/gyac/pki/ed25519-blake2b/mk-from-go +++ b/go/pki/ed25519-blake2b/mk-from-go @@ -4,7 +4,7 @@ # That script copies the library (tested on 1.23.3) and patches it to # use BLAKE2b hash. -modname=go.cypherpunks.su/yac/gyac/pki/ed25519-blake2b +modname=go.cypherpunks.su/gokeks/pki/ed25519-blake2b go mod init $modname dst=$PWD cd $(go env GOROOT)/src diff --git a/gyac/pki/ed25519-blake2b/prv.go b/go/pki/ed25519-blake2b/prv.go similarity index 83% rename from gyac/pki/ed25519-blake2b/prv.go rename to go/pki/ed25519-blake2b/prv.go index cf725c5..638e1d1 100644 --- a/gyac/pki/ed25519-blake2b/prv.go +++ b/go/pki/ed25519-blake2b/prv.go @@ -4,7 +4,7 @@ import ( "crypto" "errors" - "go.cypherpunks.su/yac/gyac/pki/ed25519-blake2b/ed25519" + "go.cypherpunks.su/keks/pki/ed25519-blake2b/ed25519" ) func NewSigner(v []byte) (prv crypto.Signer, pub []byte, err error) { diff --git a/gyac/pki/ed25519-blake2b/verify.go b/go/pki/ed25519-blake2b/verify.go similarity index 83% rename from gyac/pki/ed25519-blake2b/verify.go rename to go/pki/ed25519-blake2b/verify.go index 9c92f0c..b6cd21b 100644 --- a/gyac/pki/ed25519-blake2b/verify.go +++ b/go/pki/ed25519-blake2b/verify.go @@ -3,7 +3,7 @@ package ed25519blake2b import ( "errors" - "go.cypherpunks.su/yac/gyac/pki/ed25519-blake2b/ed25519" + "go.cypherpunks.su/keks/pki/ed25519-blake2b/ed25519" ) func Verify(pub, signed, signature []byte) (valid bool, err error) { diff --git a/gyac/pki/go.mod b/go/pki/go.mod similarity index 78% rename from gyac/pki/go.mod rename to go/pki/go.mod index c73c6ac..54d4284 100644 --- a/gyac/pki/go.mod +++ b/go/pki/go.mod @@ -1,4 +1,4 @@ -module go.cypherpunks.su/yac/gyac/pki +module go.cypherpunks.su/keks/pki go 1.22 diff --git a/gyac/pki/go.sum b/go/pki/go.sum similarity index 100% rename from gyac/pki/go.sum rename to go/pki/go.sum diff --git a/gyac/pki/gost/gost.go b/go/pki/gost/gost.go similarity index 100% rename from gyac/pki/gost/gost.go rename to go/pki/gost/gost.go diff --git a/gyac/pki/gost/kp.go b/go/pki/gost/kp.go similarity index 100% rename from gyac/pki/gost/kp.go rename to go/pki/gost/kp.go diff --git a/gyac/pki/gost/signer.go b/go/pki/gost/signer.go similarity index 100% rename from gyac/pki/gost/signer.go rename to go/pki/gost/signer.go diff --git a/gyac/pki/gost/verify.go b/go/pki/gost/verify.go similarity index 94% rename from gyac/pki/gost/verify.go rename to go/pki/gost/verify.go index 89bf1f4..a307b55 100644 --- a/gyac/pki/gost/verify.go +++ b/go/pki/gost/verify.go @@ -6,7 +6,7 @@ import ( "go.cypherpunks.su/gogost/v6/gost3410" "go.cypherpunks.su/gogost/v6/gost34112012256" "go.cypherpunks.su/gogost/v6/gost34112012512" - "go.cypherpunks.su/yac/gyac/pki/utils" + "go.cypherpunks.su/keks/pki/utils" ) func Verify(algo string, pub, signed, signature []byte) (valid bool, err error) { diff --git a/gyac/pki/hash/algo.go b/go/pki/hash/algo.go similarity index 100% rename from gyac/pki/hash/algo.go rename to go/pki/hash/algo.go diff --git a/gyac/pki/prv.go b/go/pki/prv.go similarity index 73% rename from gyac/pki/prv.go rename to go/pki/prv.go index b8aca7e..1c642ba 100644 --- a/gyac/pki/prv.go +++ b/go/pki/prv.go @@ -6,12 +6,12 @@ import ( "errors" "fmt" - "go.cypherpunks.su/yac/gyac/mapstruct" - ed25519blake2b "go.cypherpunks.su/yac/gyac/pki/ed25519-blake2b" - "go.cypherpunks.su/yac/gyac/pki/gost" + "go.cypherpunks.su/keks/mapstruct" + ed25519blake2b "go.cypherpunks.su/keks/pki/ed25519-blake2b" + "go.cypherpunks.su/keks/pki/gost" ) -// Parse private key contained in AV YAC-encoded structure. +// Parse private key contained in AV KEKS-encoded structure. func PrvParse(data []byte) (prv crypto.Signer, pub []byte, err error) { var av AV var tail []byte diff --git a/gyac/pki/signed-data.go b/go/pki/signed-data.go similarity index 72% rename from gyac/pki/signed-data.go rename to go/pki/signed-data.go index bf346ab..3ee5db8 100644 --- a/gyac/pki/signed-data.go +++ b/go/pki/signed-data.go @@ -9,45 +9,45 @@ import ( "github.com/google/uuid" - "go.cypherpunks.su/yac/gyac" - "go.cypherpunks.su/yac/gyac/mapstruct" - "go.cypherpunks.su/yac/gyac/types" + "go.cypherpunks.su/keks" + "go.cypherpunks.su/keks/mapstruct" + "go.cypherpunks.su/keks/types" ) type SignedDataLoad struct { - V any `yac:"v,omitempty"` - T string `yac:"t"` + V any `keks:"v,omitempty"` + T string `keks:"t"` } type SigTBS struct { - Hashes *map[string][]byte `yac:"hash,omitempty"` - CID *uuid.UUID `yac:"cid,omitempty"` - Exp *[]time.Time `yac:"exp,omitempty"` - When *time.Time `yac:"when,omitempty"` - SID uuid.UUID `yac:"sid"` + Hashes *map[string][]byte `keks:"hash,omitempty"` + CID *uuid.UUID `keks:"cid,omitempty"` + Exp *[]time.Time `keks:"exp,omitempty"` + When *time.Time `keks:"when,omitempty"` + SID uuid.UUID `keks:"sid"` } type Sig struct { - TBS SigTBS `yac:"tbs,omitempty"` - CerLoc *[]string `yac:"cer-loc,omitempty"` - Sign AV `yac:"sign"` + TBS SigTBS `keks:"tbs,omitempty"` + CerLoc *[]string `keks:"cer-loc,omitempty"` + Sign AV `keks:"sign"` } type SignedDataTBS struct { - V any `yac:"v"` - T string `yac:"t"` - TBS SigTBS `yac:"tbs"` + V any `keks:"v"` + T string `keks:"t"` + TBS SigTBS `keks:"tbs"` } type SignedData struct { - Hashes *map[string]*struct{} `yac:"hash,omitempty"` - Cers *[]*SignedData `yac:"certs,omitempty"` - Load SignedDataLoad `yac:"load"` - Sigs []*Sig `yac:"sigs"` + Hashes *map[string]*struct{} `keks:"hash,omitempty"` + Cers *[]*SignedData `keks:"certs,omitempty"` + Load SignedDataLoad `keks:"load"` + Sigs []*Sig `keks:"sigs"` } // Parse signed-data from decoded item. -func SignedDataParseItem(item gyac.Item) (sd *SignedData, err error) { +func SignedDataParseItem(item keks.Item) (sd *SignedData, err error) { if item.T != types.Map { err = errors.New("SignedDataParse: non-map") return @@ -122,11 +122,11 @@ func SignedDataParseItem(item gyac.Item) (sd *SignedData, err error) { return } -// Parse signed-data from YAC-encoded data. This is just a wrapper over +// Parse signed-data from KEKS-encoded data. This is just a wrapper over // SignedDataParseItem. func SignedDataParse(data []byte) (sd *SignedData, err error) { - var item gyac.Item - item, _, err = gyac.Decode(bytes.NewReader(data)) + var item keks.Item + item, _, err = keks.Decode(bytes.NewReader(data)) if err != nil { return } @@ -149,8 +149,8 @@ func (sd *SignedData) SignWith( sdTBS := SignedDataTBS{T: sd.Load.T, V: sd.Load.V, TBS: sigTBS} sig := Sig{TBS: sigTBS} sig.Sign.A = parent.Pub[0].A - var item gyac.Item - item, err = gyac.FromGo(sdTBS) + var item keks.Item + item, err = keks.FromGo(sdTBS) if err != nil { return } diff --git a/gyac/pki/utils/utils.go b/go/pki/utils/utils.go similarity index 100% rename from gyac/pki/utils/utils.go rename to go/pki/utils/utils.go diff --git a/gyac/sort.go b/go/sort.go similarity index 96% rename from gyac/sort.go rename to go/sort.go index 66f751f..6859711 100644 --- a/gyac/sort.go +++ b/go/sort.go @@ -1,4 +1,4 @@ -package gyac +package keks // Bitewise sorting by length first. type ByLenFirst []string diff --git a/gyac/togo.go b/go/togo.go similarity index 95% rename from gyac/togo.go rename to go/togo.go index c4d5b09..ce4f86a 100644 --- a/gyac/togo.go +++ b/go/togo.go @@ -1,4 +1,4 @@ -// gyac -- Go YAC encoder implementation +// keks -- Go KEKS encoder implementation // Copyright (C) 2024-2025 Sergey Matveev // // This program is free software: you can redistribute it and/or modify @@ -13,7 +13,7 @@ // You should have received a copy of the GNU Lesser General Public // License along with this program. If not, see . -package gyac +package keks import ( "fmt" @@ -22,8 +22,8 @@ import ( "github.com/google/uuid" "go.cypherpunks.su/tai64n/v4" - "go.cypherpunks.su/yac/gyac/atom" - "go.cypherpunks.su/yac/gyac/types" + "go.cypherpunks.su/keks/atom" + "go.cypherpunks.su/keks/types" ) // Convert an item to various native Go types, atom.Raw, Blob, uuid.UUID. diff --git a/gyac/types/type.go b/go/types/type.go similarity index 100% rename from gyac/types/type.go rename to go/types/type.go diff --git a/gyac/types/type_string.go b/go/types/type_string.go similarity index 100% rename from gyac/types/type_string.go rename to go/types/type_string.go diff --git a/gyac/doc.go b/gyac/doc.go deleted file mode 100644 index 67ebca6..0000000 --- a/gyac/doc.go +++ /dev/null @@ -1,6 +0,0 @@ -// YAC (http://www.yac.cypherpunks.su) is yet another binary -// serialisation encoding format. It is aimed to be lightweight in terms -// of CPU, memory, storage and codec implementation size usage. YAC is -// deterministic and streamable. It supports wide range of data types, -// making it able to transparently replace JSON. -package gyac diff --git a/gyac/pki/doc.go b/gyac/pki/doc.go deleted file mode 100644 index 42f80de..0000000 --- a/gyac/pki/doc.go +++ /dev/null @@ -1,2 +0,0 @@ -// gyac/pki provides PKI-related capabilities based on YAC encoded formats. -package pki diff --git a/pyac/.gitignore b/py3/.gitignore similarity index 100% rename from pyac/.gitignore rename to py3/.gitignore diff --git a/pyac/COPYING b/py3/COPYING similarity index 100% rename from pyac/COPYING rename to py3/COPYING diff --git a/pyac/COPYING.LESSER b/py3/COPYING.LESSER similarity index 100% rename from pyac/COPYING.LESSER rename to py3/COPYING.LESSER diff --git a/py3/README b/py3/README new file mode 100644 index 0000000..2a74634 --- /dev/null +++ b/py3/README @@ -0,0 +1,6 @@ +PyKEKS Python3 implementation of KEKS codec. + +* No FLOAT*, TAI64NA, or nanoseconds support. + They are stored/decoded just as a raw value + +PyKEKS is free software: see the file COPYING.LESSER for copying conditions. diff --git a/pyac/pyac.py b/py3/keks.py similarity index 94% rename from pyac/pyac.py rename to py3/keks.py index 39c49bb..58d2593 100755 --- a/pyac/pyac.py +++ b/py3/keks.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# pyac -- Python YAC implementation +# PyKEKS -- Python KEKS implementation # Copyright (C) 2024-2025 Sergey Matveev # # This program is free software: you can redistribute it and/or modify @@ -13,22 +13,22 @@ # # You should have received a copy of the GNU Lesser General Public # License along with this program. If not, see . -"""Python YAC encoder/decoder implementation +"""Python KEKS encoder/decoder implementation -`YAC `__ is yet another binary -serialisation encoding format. It is aimed to be lightweight in -terms of CPU, memory, storage and codec implementation size usage. -YAC is deterministic and streamable. It supports wide range of data -types, making it able to transparently replace JSON. +`KEKS `__ is compact, deterministic, +concise and streaming binary serialisation format. It is aimed to be +lightweight in terms of CPU, memory, storage and codec implementation +size usage. It supports wide range of data types, making it able to +transparently replace JSON. It has :py:func:`loads` and :py:func:`dumps` functions, similar to -native :py:module:`json` library's. YAC supports dictionaries, lists, +native :py:module:`json` library's. KEKS supports dictionaries, lists, None, booleans, UUID, floats (currently not implemented!), integers (including big ones), datetime, Unicode and binary strings. -There is special :py:func:`pyac.Raw` namedtuple, that holds arbitrary -YAC encoded data, that can not be represented in native Python types. -Also there is :py:func:`pyac.Blob` namedtuple, that holds the data, that +There is special :py:func:`keks.Raw` namedtuple, that holds arbitrary +KEKS encoded data, that can not be represented in native Python types. +Also there is :py:func:`keks.Blob` namedtuple, that holds the data, that is encoded streamingly in chunks. """ @@ -427,7 +427,7 @@ def _loads(v, sets=False, leapsecUTCAllow=False, _allowContainers=True): def loads(v, **kwargs): - """Decode YAC-encoded data. + """Decode KEKS-encoded data. :param bool sets: transform maps with NIL-only values to set()s :param bool leapsecUTCAllow: allow TAI64 values equal to leap seconds, @@ -448,7 +448,7 @@ def loads(v, **kwargs): if __name__ == "__main__": from argparse import ArgumentParser from argparse import FileType - parser = ArgumentParser(description="Decode YAC file") + parser = ArgumentParser(description="Decode KEKS file") parser.add_argument( "--nosets", action="store_true", help="Do not fold NIL-valued maps to sets") diff --git a/pyac/test-vector.py b/py3/test-vector.py similarity index 81% rename from pyac/test-vector.py rename to py3/test-vector.py index 6e17051..e36061e 100644 --- a/pyac/test-vector.py +++ b/py3/test-vector.py @@ -1,7 +1,7 @@ from datetime import datetime from datetime import timedelta from uuid import UUID -import pyac +import keks data = { @@ -16,7 +16,7 @@ data = { -123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789, ], }, - "floats": [pyac.Raw(pyac.TagFloat32, bytes.fromhex("01020304"))], + "floats": [keks.Raw(keks.TagFloat32, bytes.fromhex("01020304"))], "nil": None, "bool": [True, False], "str": { @@ -33,29 +33,29 @@ data = { "utf8": "привет мир", }, "blob": [ - pyac.Blob(12, 1 * b"5"), - pyac.Blob(12, 12 * b"6"), - pyac.Blob(12, 13 * b"7"), - pyac.Blob(5, b"1234567890-"), + keks.Blob(12, 1 * b"5"), + keks.Blob(12, 12 * b"6"), + keks.Blob(12, 13 * b"7"), + keks.Blob(5, b"1234567890-"), ], "empties": [ [], {}, - pyac.Blob(123, b""), + keks.Blob(123, b""), UUID("00000000-0000-0000-0000-000000000000"), - pyac.Raw(pyac.TagTAI64, bytes.fromhex("0000000000000000")), + keks.Raw(keks.TagTAI64, bytes.fromhex("0000000000000000")), ], "uuid": UUID("0e875e3f-d385-49eb-87b4-be42d641c367"), } data["dates"] = [ (datetime(1970, 1, 1) + timedelta(seconds=1234567890)), (datetime(1970, 1, 1) + timedelta(seconds=1234567890)).replace(microsecond=456), - pyac.Raw(pyac.TagTAI64N, bytes.fromhex("40000000499602F40006F855")), - pyac.Raw(pyac.TagTAI64NA, bytes.fromhex("40000000499602F40006F855075BCD15")), + keks.Raw(keks.TagTAI64N, bytes.fromhex("40000000499602F40006F855")), + keks.Raw(keks.TagTAI64NA, bytes.fromhex("40000000499602F40006F855075BCD15")), ] -raw = pyac.dumps(data) -dec, tail = pyac.loads(raw) +raw = keks.dumps(data) +dec, tail = keks.loads(raw) assert tail == b"" -assert pyac.dumps(dec) == raw +assert keks.dumps(dec) == raw assert dec == data print(raw.hex()) diff --git a/pyac/tests/.gitignore b/py3/tests/.gitignore similarity index 100% rename from pyac/tests/.gitignore rename to py3/tests/.gitignore diff --git a/pyac/tests/__init__.py b/py3/tests/__init__.py similarity index 100% rename from pyac/tests/__init__.py rename to py3/tests/__init__.py diff --git a/pyac/tests/fuzz.py b/py3/tests/fuzz.py similarity index 77% rename from pyac/tests/fuzz.py rename to py3/tests/fuzz.py index 603d696..0a9a4d8 100755 --- a/pyac/tests/fuzz.py +++ b/py3/tests/fuzz.py @@ -5,8 +5,8 @@ from os import _exit import afl -from pyac import loads -from pyac import DecodeError +from keks import loads +from keks import DecodeError afl.init() data = stdin.buffer.read() diff --git a/pyac/tests/requirements.txt b/py3/tests/requirements.txt similarity index 100% rename from pyac/tests/requirements.txt rename to py3/tests/requirements.txt diff --git a/pyac/tests/strategies.py b/py3/tests/strategies.py similarity index 96% rename from pyac/tests/strategies.py rename to py3/tests/strategies.py index 4d8d383..2de9856 100644 --- a/pyac/tests/strategies.py +++ b/py3/tests/strategies.py @@ -1,4 +1,4 @@ -# pyac -- Python YAC implementation +# PyKEKS -- Python KEKS implementation # Copyright (C) 2024-2025 Antont Rudenko # 2024-2025 Sergey Matveev # @@ -29,7 +29,7 @@ from hypothesis.strategies import text from hypothesis.strategies import tuples from hypothesis.strategies import uuids -from pyac import Blob +from keks import Blob junk_st = binary(max_size=8) diff --git a/pyac/tests/test_blob.py b/py3/tests/test_blob.py similarity index 96% rename from pyac/tests/test_blob.py rename to py3/tests/test_blob.py index 65efa45..2c7ae19 100644 --- a/pyac/tests/test_blob.py +++ b/py3/tests/test_blob.py @@ -1,4 +1,4 @@ -# pyac -- Python YAC implementation +# PyKEKS -- Python KEKS implementation # Copyright (C) 2024-2025 Antont Rudenko # 2024-2025 Sergey Matveev # @@ -20,11 +20,11 @@ from unittest import TestCase from hypothesis import given from hypothesis.strategies import integers -from pyac import Blob -from pyac import DecodeError -from pyac import dumps -from pyac import loads -from pyac import NotEnoughData +from keks import Blob +from keks import DecodeError +from keks import dumps +from keks import loads +from keks import NotEnoughData from tests.strategies import junk_st diff --git a/pyac/tests/test_bool.py b/py3/tests/test_bool.py similarity index 94% rename from pyac/tests/test_bool.py rename to py3/tests/test_bool.py index 02fb732..4f4704c 100644 --- a/pyac/tests/test_bool.py +++ b/py3/tests/test_bool.py @@ -1,4 +1,4 @@ -# pyac -- Python YAC implementation +# PyKEKS -- Python KEKS implementation # Copyright (C) 2024-2025 Antont Rudenko # 2024-2025 Sergey Matveev # @@ -18,8 +18,8 @@ from unittest import TestCase from hypothesis import given -from pyac import dumps -from pyac import loads +from keks import dumps +from keks import loads from tests.strategies import junk_st diff --git a/pyac/tests/test_everything.py b/py3/tests/test_everything.py similarity index 93% rename from pyac/tests/test_everything.py rename to py3/tests/test_everything.py index 97a0741..d1f3cd5 100644 --- a/pyac/tests/test_everything.py +++ b/py3/tests/test_everything.py @@ -1,4 +1,4 @@ -# pyac -- Python YAC implementation +# PyKEKS -- Python KEKS implementation # Copyright (C) 2024-2025 Antont Rudenko # 2024-2025 Sergey Matveev # @@ -19,8 +19,8 @@ from unittest import TestCase from hypothesis import given -from pyac import dumps -from pyac import loads +from keks import dumps +from keks import loads from tests.strategies import junk_st from tests.strategies import everything_st diff --git a/pyac/tests/test_float.py b/py3/tests/test_float.py similarity index 95% rename from pyac/tests/test_float.py rename to py3/tests/test_float.py index 7afaf51..af90c55 100644 --- a/pyac/tests/test_float.py +++ b/py3/tests/test_float.py @@ -1,4 +1,4 @@ -# pyac -- Python YAC implementation +# PyKEKS -- Python KEKS implementation # Copyright (C) 2024-2025 Antont Rudenko # 2024-2025 Sergey Matveev # @@ -18,10 +18,10 @@ from unittest import TestCase from hypothesis import given -from pyac import dumps -from pyac import loads -from pyac import NotEnoughData -from pyac import Raw +from keks import dumps +from keks import loads +from keks import NotEnoughData +from keks import Raw from tests.strategies import junk_st diff --git a/pyac/tests/test_fuzz_inputs.py b/py3/tests/test_fuzz_inputs.py similarity index 91% rename from pyac/tests/test_fuzz_inputs.py rename to py3/tests/test_fuzz_inputs.py index 964a19e..b95b855 100644 --- a/pyac/tests/test_fuzz_inputs.py +++ b/py3/tests/test_fuzz_inputs.py @@ -6,14 +6,14 @@ from os.path import join as path_join from unittest import skipIf from unittest import TestCase -from pyac import Blob -from pyac import Leapsecs1972 -from pyac import loads -from pyac import Raw -from pyac import TagTAI64 -from pyac import TagTAI64N -from pyac import TagTAI64NA -from pyac import TAI64Base +from keks import Blob +from keks import Leapsecs1972 +from keks import loads +from keks import Raw +from keks import TagTAI64 +from keks import TagTAI64N +from keks import TagTAI64NA +from keks import TAI64Base testsDir = dirname(abspath(__file__)) @@ -35,7 +35,7 @@ def readInput(name: str) -> bytes: class TestFuzzInputs(TestCase): - """Check tyac/mk-fuzz-inputs output + """Check tcl/mk-fuzz-inputs output You have to create fuzz-inputs directory in tests and fill it up with mk-fuzz-inputs. diff --git a/pyac/tests/test_generic.py b/py3/tests/test_generic.py similarity index 92% rename from pyac/tests/test_generic.py rename to py3/tests/test_generic.py index 51b9654..2cde6f5 100644 --- a/pyac/tests/test_generic.py +++ b/py3/tests/test_generic.py @@ -1,4 +1,4 @@ -# pyac -- Python YAC implementation +# PyKEKS -- Python KEKS implementation # Copyright (C) 2024-2025 Antont Rudenko # 2024-2025 Sergey Matveev # @@ -19,11 +19,11 @@ from unittest import TestCase from hypothesis import given from hypothesis.strategies import binary -from pyac import DecodeError -from pyac import dumps -from pyac import loads -from pyac import NotEnoughData -from pyac import Raw +from keks import DecodeError +from keks import dumps +from keks import loads +from keks import NotEnoughData +from keks import Raw class TestUnknownType(TestCase): diff --git a/pyac/tests/test_int.py b/py3/tests/test_int.py similarity index 97% rename from pyac/tests/test_int.py rename to py3/tests/test_int.py index 46bfac2..cfc2d63 100644 --- a/pyac/tests/test_int.py +++ b/py3/tests/test_int.py @@ -1,4 +1,4 @@ -# pyac -- Python YAC implementation +# PyKEKS -- Python KEKS implementation # Copyright (C) 2024-2025 Antont Rudenko # 2024-2025 Sergey Matveev # @@ -19,10 +19,10 @@ from unittest import TestCase from hypothesis import given from hypothesis.strategies import integers -from pyac import DecodeError -from pyac import dumps -from pyac import loads -from pyac import NotEnoughData +from keks import DecodeError +from keks import dumps +from keks import loads +from keks import NotEnoughData from tests.strategies import junk_st diff --git a/pyac/tests/test_list.py b/py3/tests/test_list.py similarity index 94% rename from pyac/tests/test_list.py rename to py3/tests/test_list.py index 47eab06..7be9c7c 100644 --- a/pyac/tests/test_list.py +++ b/py3/tests/test_list.py @@ -1,4 +1,4 @@ -# pyac -- Python YAC implementation +# PyKEKS -- Python KEKS implementation # Copyright (C) 2024-2025 Antont Rudenko # 2024-2025 Sergey Matveev # @@ -20,9 +20,9 @@ from unittest import TestCase from hypothesis import given from hypothesis.strategies import lists -from pyac import dumps -from pyac import loads -from pyac import NotEnoughData +from keks import dumps +from keks import loads +from keks import NotEnoughData from tests.strategies import any_st from tests.strategies import everything_st from tests.strategies import junk_st diff --git a/pyac/tests/test_map.py b/py3/tests/test_map.py similarity index 97% rename from pyac/tests/test_map.py rename to py3/tests/test_map.py index 0f3da4c..b43768d 100644 --- a/pyac/tests/test_map.py +++ b/py3/tests/test_map.py @@ -1,4 +1,4 @@ -# pyac -- Python YAC implementation +# PyKEKS -- Python KEKS implementation # Copyright (C) 2024-2025 Antont Rudenko # 2024-2025 Sergey Matveev # @@ -23,9 +23,9 @@ from hypothesis import given from hypothesis.strategies import dictionaries from hypothesis.strategies import sets -from pyac import DecodeError -from pyac import dumps -from pyac import loads +from keks import DecodeError +from keks import dumps +from keks import loads from tests.strategies import any_st from tests.strategies import junk_st from tests.strategies import mapkey_st diff --git a/pyac/tests/test_not_enough_data.py b/py3/tests/test_not_enough_data.py similarity index 95% rename from pyac/tests/test_not_enough_data.py rename to py3/tests/test_not_enough_data.py index 1cec223..91f35f3 100644 --- a/pyac/tests/test_not_enough_data.py +++ b/py3/tests/test_not_enough_data.py @@ -1,4 +1,4 @@ -# pyac -- Python YAC implementation +# PyKEKS -- Python KEKS implementation # Copyright (C) 2024-2025 Antont Rudenko # 2024-2025 Sergey Matveev # @@ -19,7 +19,7 @@ from unittest import TestCase from hypothesis import given from hypothesis.strategies import integers -from pyac import NotEnoughData +from keks import NotEnoughData class TestNotEnoughData(TestCase): diff --git a/pyac/tests/test_recursion.py b/py3/tests/test_recursion.py similarity index 88% rename from pyac/tests/test_recursion.py rename to py3/tests/test_recursion.py index 902ad3c..b2edbad 100644 --- a/pyac/tests/test_recursion.py +++ b/py3/tests/test_recursion.py @@ -1,4 +1,4 @@ -# pyac -- Python YAC implementation +# PyKEKS -- Python KEKS implementation # Copyright (C) 2024-2025 Antont Rudenko # 2024-2025 Sergey Matveev # @@ -16,12 +16,12 @@ from unittest import TestCase -from pyac import _byte -from pyac import DecodeError -from pyac import loads -from pyac import TagBlob -from pyac import TagList -from pyac import TagPInt +from keks import _byte +from keks import DecodeError +from keks import loads +from keks import TagBlob +from keks import TagList +from keks import TagPInt class TestTooDeepInt(TestCase): diff --git a/pyac/tests/test_str.py b/py3/tests/test_str.py similarity index 98% rename from pyac/tests/test_str.py rename to py3/tests/test_str.py index c1c6224..881d7a9 100644 --- a/pyac/tests/test_str.py +++ b/py3/tests/test_str.py @@ -1,4 +1,4 @@ -# pyac -- Python YAC implementation +# PyKEKS -- Python KEKS implementation # Copyright (C) 2024-2025 Antont Rudenko # 2024-2025 Sergey Matveev # @@ -20,10 +20,10 @@ from hypothesis import given from hypothesis.strategies import binary from hypothesis.strategies import integers -from pyac import DecodeError -from pyac import dumps -from pyac import loads -from pyac import NotEnoughData +from keks import DecodeError +from keks import dumps +from keks import loads +from keks import NotEnoughData from tests.strategies import junk_st from tests.strategies import unicode_allowed diff --git a/pyac/tests/test_tai.py b/py3/tests/test_tai.py similarity index 96% rename from pyac/tests/test_tai.py rename to py3/tests/test_tai.py index ca7f0cd..868d342 100644 --- a/pyac/tests/test_tai.py +++ b/py3/tests/test_tai.py @@ -1,4 +1,4 @@ -# pyac -- Python YAC implementation +# PyKEKS -- Python KEKS implementation # Copyright (C) 2024-2025 Antont Rudenko # 2024-2025 Sergey Matveev # @@ -20,14 +20,14 @@ from unittest import TestCase from hypothesis import given from hypothesis.strategies import datetimes -from pyac import _byte -from pyac import DecodeError -from pyac import dumps -from pyac import Leapsecs -from pyac import loads -from pyac import NotEnoughData -from pyac import Raw -from pyac import TAI64Base +from keks import _byte +from keks import DecodeError +from keks import dumps +from keks import Leapsecs +from keks import loads +from keks import NotEnoughData +from keks import Raw +from keks import TAI64Base from tests.strategies import junk_st @@ -245,7 +245,7 @@ class TestVectors(TestCase): class TestLeapsecs(TestCase): def test_match_DJB(self) -> None: - """Check that our pyac.Leapsecs is equally calculated to DJB's one + """Check that our keks.Leapsecs is equally calculated to DJB's one """ for our, their in zip(Leapsecs, DJB_Leapsecs): self.assertEqual( diff --git a/pyac/tests/test_uuid.py b/py3/tests/test_uuid.py similarity index 94% rename from pyac/tests/test_uuid.py rename to py3/tests/test_uuid.py index 1259997..ea181ec 100644 --- a/pyac/tests/test_uuid.py +++ b/py3/tests/test_uuid.py @@ -1,4 +1,4 @@ -# pyac -- Python YAC implementation +# PyKEKS -- Python KEKS implementation # Copyright (C) 2024-2025 Antont Rudenko # 2024-2025 Sergey Matveev # @@ -20,9 +20,9 @@ from uuid import UUID from hypothesis import given from hypothesis.strategies import uuids -from pyac import dumps -from pyac import loads -from pyac import NotEnoughData +from keks import dumps +from keks import loads +from keks import NotEnoughData from tests.strategies import junk_st diff --git a/pyac/README b/pyac/README deleted file mode 100644 index a705a4d..0000000 --- a/pyac/README +++ /dev/null @@ -1,6 +0,0 @@ -Python implementation of YAC codec. - -* No FLOAT*, TAI64NA, or nanoseconds support. - They are stored/decoded just as a raw value - -pyac is free software: see the file COPYING.LESSER for copying conditions. diff --git a/spec/design.texi b/spec/design.texi index 9c62fef..f32a450 100644 --- a/spec/design.texi +++ b/spec/design.texi @@ -46,7 +46,7 @@ should be able to send it without complication of inventing your own chunked format. @item -Is not embedded strings length, like in YAC and CBOR, is a more +Is not embedded strings length, like in KEKS and CBOR, is a more complicated code? Definitely. But there are so many short strings in a schemaless format for specifying map/structure keys. So many algorithm identifiers, that are also relatively short human-readable strings. So diff --git a/spec/encoding/index.texi b/spec/encoding/index.texi index 7c421c4..c4d6c6a 100644 --- a/spec/encoding/index.texi +++ b/spec/encoding/index.texi @@ -2,7 +2,7 @@ @cindex encoding @unnumbered Encoding -YAC can store various primitive scalar types (strings, integers, ...) +KEKS can store various primitive scalar types (strings, integers, ...) and container types (lists, maps, ...). Serialisation process is just emitting the TLV-like encoding for each item recursively. diff --git a/spec/index.texi b/spec/index.texi index d471df6..9e1bdc1 100644 --- a/spec/index.texi +++ b/spec/index.texi @@ -1,5 +1,5 @@ \input texinfo -@settitle YAC +@settitle KEKS @copying Copyright @copyright{} 2024-2025 @email{stargrave@@stargrave.org, Sergey Matveev} @@ -8,11 +8,17 @@ Copyright @copyright{} 2024-2025 @email{stargrave@@stargrave.org, Sergey Matveev @firstparagraphindent insert @node Top -@top YAC +@top KEKS -YAC (Yet Another Codec) -- yet another format for binary reprensentation -of structured data. But why!? Because there is no satisfiable codec for -all set of requirements below. +KEKS is compact, deterministic, concise and streaming binary +serialisation format. It is aimed to be lightweight in terms of CPU, +memory, storage and codec implementation size usage. It supports wide +range of data types, making it able to transparently replace JSON. + +KEKS means: kompakt, entschlossen, knapp, strömend. + +But why!? Because there is no satisfiable codec for all set of +requirements below. @itemize @item @@ -74,7 +80,7 @@ Are not there any satisfiable codecs? Y @tab Y @tab Y @tab Y @tab ~ @item @url{https://en.wikipedia.org/wiki/Canonical_S-expressions, Canonical S-expression} @tab Y @tab Y @tab Y @tab Y @tab ~ -@item YAC @tab +@item KEKS @tab Y @tab Y @tab Y @tab Y @tab Y @end multitable @@ -105,7 +111,7 @@ Are not there any satisfiable codecs? Y @tab Y @tab N @tab Y @tab Y @tab Y @tab Y @tab N @item CSExp @tab Y @tab Y @tab N @tab N @tab N @tab Y @tab N @tab N -@item YAC @tab +@item KEKS @tab Y @tab Y @tab Y @tab Y @tab Y @tab Y @tab Y @tab Y @end multitable diff --git a/spec/install.texi b/spec/install.texi index 2ede379..072098d 100644 --- a/spec/install.texi +++ b/spec/install.texi @@ -1,14 +1,14 @@ @node Install @unnumbered Install -Currently there are draft versions of the codec written on C, Go, Python -and Tcl. But all of them are currently badly covered with tests. +Currently there are draft versions of the codec written on C, Go, +Python and Tcl. @cindex git You can obtain development source code with -@command{git clone git://git.cypherpunks.su/yac.git} -(also you can use @url{http://git.cypherpunks.su/yac.git}, -@url{https://git.cypherpunks.su/yac.git}). +@command{git clone git://git.cypherpunks.su/keks.git} +(also you can use @url{http://git.cypherpunks.su/keks.git}, +@url{https://git.cypherpunks.su/keks.git}). Also there is @url{https://yggdrasil-network.github.io/, Yggdrasil} -accessible address: @url{http://y.www.yac.cypherpunks.su/}. +accessible address: @url{http://y.www.keks.cypherpunks.su/}. diff --git a/spec/schema.texi b/spec/schema.texi index afcb2ad..d049d43 100644 --- a/spec/schema.texi +++ b/spec/schema.texi @@ -1,7 +1,7 @@ @node Schema @unnumbered Schema -YAC can be decoded without any schema definition. But semantic meaning +KEKS can be decoded without any schema definition. But semantic meaning and constraints of various fields are expected to be written in a human readable language somewhere nearby. diff --git a/tyac/COPYING b/tcl/COPYING similarity index 100% rename from tyac/COPYING rename to tcl/COPYING diff --git a/tyac/COPYING.LESSER b/tcl/COPYING.LESSER similarity index 100% rename from tyac/COPYING.LESSER rename to tcl/COPYING.LESSER diff --git a/tcl/README b/tcl/README new file mode 100644 index 0000000..aafbe0e --- /dev/null +++ b/tcl/README @@ -0,0 +1,5 @@ +TclKEKS implementation of the KEK encoder. + +* No FLOAT* support. They can be stored just as a raw value. + +TclKEKS is free software: see the file COPYING.LESSER for copying conditions. diff --git a/tcl/args b/tcl/args new file mode 100755 index 0000000..a1bfac8 --- /dev/null +++ b/tcl/args @@ -0,0 +1,6 @@ +#!/usr/bin/env tclsh8.6 + +source [file join [file dirname $::argv0] keks.tcl] +namespace import KEKS::* +eval [lindex $::argv 0] +puts [binary encode hex $::KEKS::buf] diff --git a/tyac/tyac.tcl b/tcl/keks.tcl similarity index 98% rename from tyac/tyac.tcl rename to tcl/keks.tcl index f40f0e4..417eb96 100644 --- a/tyac/tyac.tcl +++ b/tcl/keks.tcl @@ -1,4 +1,4 @@ -# tyac -- Tcl YAC encoder implementation +# TclKEKS -- Tcl KEKS encoder implementation # Copyright (C) 2024-2025 Sergey Matveev # # This program is free software: you can redistribute it and/or modify @@ -13,7 +13,7 @@ # You should have received a copy of the GNU Lesser General Public # License along with this program. If not, see . -namespace eval YAC { +namespace eval KEKS { variable buf {} diff --git a/tyac/mk-fuzz-inputs b/tcl/mk-fuzz-inputs similarity index 100% rename from tyac/mk-fuzz-inputs rename to tcl/mk-fuzz-inputs diff --git a/tyac/test-vector.tcl b/tcl/test-vector.tcl similarity index 97% rename from tyac/test-vector.tcl rename to tcl/test-vector.tcl index feb97dc..f2167bf 100644 --- a/tyac/test-vector.tcl +++ b/tcl/test-vector.tcl @@ -1,5 +1,5 @@ -source tyac.tcl -namespace import YAC::* +source keks.tcl +namespace import KEKS::* MAP { ints {MAP { @@ -67,4 +67,4 @@ MAP { uuid {UUID 0e875e3f-d385-49eb-87b4-be42d641c367} } -puts [binary encode hex $::YAC::buf] +puts [binary encode hex $::KEKS::buf] diff --git a/tyac/README b/tyac/README deleted file mode 100644 index c75d95b..0000000 --- a/tyac/README +++ /dev/null @@ -1,5 +0,0 @@ -Tcl implementation of the YAC encoder. - -* No FLOAT* support. They can be stored just as a raw value. - -tyac is free software: see the file COPYING.LESSER for copying conditions. diff --git a/tyac/args b/tyac/args deleted file mode 100755 index d29a8fd..0000000 --- a/tyac/args +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env tclsh8.6 - -source [file join [file dirname $::argv0] tyac.tcl] -namespace import YAC::* -eval [lindex $::argv 0] -puts [binary encode hex $::YAC::buf] -- 2.50.0