Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"workbench.colorTheme": "Gruvbox Dark Soft",
"workbench.colorTheme": "Dreamweaver Dark Theme",
"C_Cpp.default.compileCommands": "${workspaceFolder}/compile_commands.json",
"C_Cpp.default.cppStandard": "c17",
"C_Cpp.default.intelliSenseMode": "clang-x64",
Expand Down
48 changes: 48 additions & 0 deletions compile_commands.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
[
{
"directory": "/workspace/build",
"command": "clang -Ilibgitmind.a.p -I. -I.. -I../core/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -std=c2x -O0 -g -std=c2x -pedantic -Wall -Wextra -Werror -Wvla -Wshadow -Wstrict-prototypes -Wconversion -Wsign-conversion -Wfloat-equal -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -O2 -fno-common -fstrict-aliasing -fPIC -pthread -MD -MQ libgitmind.a.p/core_src_cbor_cbor.c.o -MF libgitmind.a.p/core_src_cbor_cbor.c.o.d -o libgitmind.a.p/core_src_cbor_cbor.c.o -c ../core/src/cbor/cbor.c",
"file": "../core/src/cbor/cbor.c",
"output": "libgitmind.a.p/core_src_cbor_cbor.c.o"
},
{
"directory": "/workspace/build",
"command": "clang -Ilibgitmind.a.p -I. -I.. -I../core/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -std=c2x -O0 -g -std=c2x -pedantic -Wall -Wextra -Werror -Wvla -Wshadow -Wstrict-prototypes -Wconversion -Wsign-conversion -Wfloat-equal -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -O2 -fno-common -fstrict-aliasing -fPIC -pthread -MD -MQ libgitmind.a.p/core_src_crypto_backend.c.o -MF libgitmind.a.p/core_src_crypto_backend.c.o.d -o libgitmind.a.p/core_src_crypto_backend.c.o -c ../core/src/crypto/backend.c",
Expand All @@ -23,6 +29,18 @@
"file": "../core/src/error/error.c",
"output": "libgitmind.a.p/core_src_error_error.c.o"
},
{
"directory": "/workspace/build",
"command": "clang -Ilibgitmind.a.p -I. -I.. -I../core/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -std=c2x -O0 -g -std=c2x -pedantic -Wall -Wextra -Werror -Wvla -Wshadow -Wstrict-prototypes -Wconversion -Wsign-conversion -Wfloat-equal -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -O2 -fno-common -fstrict-aliasing -fPIC -pthread -MD -MQ libgitmind.a.p/core_src_io_io.c.o -MF libgitmind.a.p/core_src_io_io.c.o.d -o libgitmind.a.p/core_src_io_io.c.o -c ../core/src/io/io.c",
"file": "../core/src/io/io.c",
"output": "libgitmind.a.p/core_src_io_io.c.o"
},
{
"directory": "/workspace/build",
"command": "clang -Ilibgitmind.a.p -I. -I.. -I../core/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -std=c2x -O0 -g -std=c2x -pedantic -Wall -Wextra -Werror -Wvla -Wshadow -Wstrict-prototypes -Wconversion -Wsign-conversion -Wfloat-equal -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -O2 -fno-common -fstrict-aliasing -fPIC -pthread -MD -MQ libgitmind.a.p/core_src_time_time.c.o -MF libgitmind.a.p/core_src_time_time.c.o.d -o libgitmind.a.p/core_src_time_time.c.o -c ../core/src/time/time.c",
"file": "../core/src/time/time.c",
"output": "libgitmind.a.p/core_src_time_time.c.o"
},
{
"directory": "/workspace/build",
"command": "clang -Ilibgitmind.a.p -I. -I.. -I../core/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -std=c2x -O0 -g -std=c2x -pedantic -Wall -Wextra -Werror -Wvla -Wshadow -Wstrict-prototypes -Wconversion -Wsign-conversion -Wfloat-equal -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -O2 -fno-common -fstrict-aliasing -fPIC -pthread -MD -MQ libgitmind.a.p/core_src_types_id.c.o -MF libgitmind.a.p/core_src_types_id.c.o.d -o libgitmind.a.p/core_src_types_id.c.o -c ../core/src/types/id.c",
Expand Down Expand Up @@ -53,6 +71,12 @@
"file": "../core/src/types/string_utf8.c",
"output": "libgitmind.a.p/core_src_types_string_utf8.c.o"
},
{
"directory": "/workspace/build",
"command": "clang -Ilibgitmind.a.p -I. -I.. -I../core/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -std=c2x -O0 -g -std=c2x -pedantic -Wall -Wextra -Werror -Wvla -Wshadow -Wstrict-prototypes -Wconversion -Wsign-conversion -Wfloat-equal -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -O2 -fno-common -fstrict-aliasing -fPIC -pthread -MD -MQ libgitmind.a.p/core_src_types_ulid.c.o -MF libgitmind.a.p/core_src_types_ulid.c.o.d -o libgitmind.a.p/core_src_types_ulid.c.o -c ../core/src/types/ulid.c",
"file": "../core/src/types/ulid.c",
"output": "libgitmind.a.p/core_src_types_ulid.c.o"
},
{
"directory": "/workspace/build",
"command": "clang -Ilibgitmind.a.p -I. -I.. -I../core/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -std=c2x -O0 -g -std=c2x -pedantic -Wall -Wextra -Werror -Wvla -Wshadow -Wstrict-prototypes -Wconversion -Wsign-conversion -Wfloat-equal -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -O2 -fno-common -fstrict-aliasing -fPIC -pthread -MD -MQ libgitmind.a.p/core_src_utf8_validate.c.o -MF libgitmind.a.p/core_src_utf8_validate.c.o.d -o libgitmind.a.p/core_src_utf8_validate.c.o -c ../core/src/utf8/validate.c",
Expand Down Expand Up @@ -118,5 +142,29 @@
"command": "clang -Itest_crypto_backend.p -I. -I.. -I../core/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -std=c2x -O0 -g -std=c2x -pedantic -Wall -Wextra -Werror -Wvla -Wshadow -Wstrict-prototypes -Wconversion -Wsign-conversion -Wfloat-equal -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -O2 -fno-common -fstrict-aliasing -pthread -DGITMIND_ENABLE_TEST_BACKEND -MD -MQ test_crypto_backend.p/core_tests_unit_test_crypto_backend.c.o -MF test_crypto_backend.p/core_tests_unit_test_crypto_backend.c.o.d -o test_crypto_backend.p/core_tests_unit_test_crypto_backend.c.o -c ../core/tests/unit/test_crypto_backend.c",
"file": "../core/tests/unit/test_crypto_backend.c",
"output": "test_crypto_backend.p/core_tests_unit_test_crypto_backend.c.o"
},
{
"directory": "/workspace/build",
"command": "clang -Itest_ulid.p -I. -I.. -I../core/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -std=c2x -O0 -g -std=c2x -pedantic -Wall -Wextra -Werror -Wvla -Wshadow -Wstrict-prototypes -Wconversion -Wsign-conversion -Wfloat-equal -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -O2 -fno-common -fstrict-aliasing -pthread -DGITMIND_ENABLE_TEST_BACKEND -MD -MQ test_ulid.p/core_tests_unit_test_ulid.c.o -MF test_ulid.p/core_tests_unit_test_ulid.c.o.d -o test_ulid.p/core_tests_unit_test_ulid.c.o -c ../core/tests/unit/test_ulid.c",
"file": "../core/tests/unit/test_ulid.c",
"output": "test_ulid.p/core_tests_unit_test_ulid.c.o"
},
{
"directory": "/workspace/build",
"command": "clang -Itest_io.p -I. -I.. -I../core/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -std=c2x -O0 -g -std=c2x -pedantic -Wall -Wextra -Werror -Wvla -Wshadow -Wstrict-prototypes -Wconversion -Wsign-conversion -Wfloat-equal -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -O2 -fno-common -fstrict-aliasing -pthread -MD -MQ test_io.p/core_tests_unit_test_io.c.o -MF test_io.p/core_tests_unit_test_io.c.o.d -o test_io.p/core_tests_unit_test_io.c.o -c ../core/tests/unit/test_io.c",
"file": "../core/tests/unit/test_io.c",
"output": "test_io.p/core_tests_unit_test_io.c.o"
},
{
"directory": "/workspace/build",
"command": "clang -Itest_time.p -I. -I.. -I../core/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -std=c2x -O0 -g -std=c2x -pedantic -Wall -Wextra -Werror -Wvla -Wshadow -Wstrict-prototypes -Wconversion -Wsign-conversion -Wfloat-equal -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -O2 -fno-common -fstrict-aliasing -pthread -MD -MQ test_time.p/core_tests_unit_test_time.c.o -MF test_time.p/core_tests_unit_test_time.c.o.d -o test_time.p/core_tests_unit_test_time.c.o -c ../core/tests/unit/test_time.c",
"file": "../core/tests/unit/test_time.c",
"output": "test_time.p/core_tests_unit_test_time.c.o"
},
{
"directory": "/workspace/build",
"command": "clang -Itest_cbor.p -I. -I.. -I../core/include -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -std=c2x -O0 -g -std=c2x -pedantic -Wall -Wextra -Werror -Wvla -Wshadow -Wstrict-prototypes -Wconversion -Wsign-conversion -Wfloat-equal -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -O2 -fno-common -fstrict-aliasing -pthread -MD -MQ test_cbor.p/core_tests_unit_test_cbor.c.o -MF test_cbor.p/core_tests_unit_test_cbor.c.o.d -o test_cbor.p/core_tests_unit_test_cbor.c.o -c ../core/tests/unit/test_cbor.c",
"file": "../core/tests/unit/test_cbor.c",
"output": "test_cbor.p/core_tests_unit_test_cbor.c.o"
}
]
85 changes: 85 additions & 0 deletions core/include/gitmind/cbor/cbor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* SPDX-License-Identifier: LicenseRef-MIND-UCAL-1.0 */
/* 漏 2025 J. Kirby Ross / Neuroglyph Collective */

#ifndef GITMIND_CBOR_CBOR_H
#define GITMIND_CBOR_CBOR_H

#include <gitmind/result.h>
#include <stddef.h>
#include <stdint.h>

/* Result types for CBOR operations */
GM_RESULT_DEF(gm_result_uint64, uint64_t);

/**
* CBOR read operations with Result types.
* All operations return Result types for proper error handling.
*/

/**
* Read a CBOR unsigned integer from buffer.
* @param buf Buffer to read from
* @param offset Pointer to current offset (updated on success)
* @param max_size Maximum buffer size to prevent overruns
* @return Result containing the uint64_t value or error
*/
gm_result_uint64_t gm_cbor_read_uint(const uint8_t *buf, size_t *offset, size_t max_size);

/**
* Read a CBOR byte string from buffer.
* @param buf Buffer to read from
* @param offset Pointer to current offset (updated on success)
* @param max_size Maximum buffer size to prevent overruns
* @param data Buffer to write bytes to
* @param expected_len Expected length of byte string
* @return Result indicating success or error
*/
gm_result_void_t gm_cbor_read_bytes(const uint8_t *buf, size_t *offset, size_t max_size,
uint8_t *data, size_t expected_len);

/**
* Read a CBOR text string from buffer.
* @param buf Buffer to read from
* @param offset Pointer to current offset (updated on success)
* @param max_size Maximum buffer size to prevent overruns
* @param text Buffer to write text to (null-terminated)
* @param max_text_len Maximum text buffer size
* @return Result indicating success or error
*/
gm_result_void_t gm_cbor_read_text(const uint8_t *buf, size_t *offset, size_t max_size,
char *text, size_t max_text_len);

/**
* CBOR write operations with Result types.
*/

/**
* Write a CBOR unsigned integer to buffer.
* @param value Value to write
* @param buf Buffer to write to
* @param buf_size Size of output buffer
* @return Result containing number of bytes written or error
*/
gm_result_size_t gm_cbor_write_uint(uint64_t value, uint8_t *buf, size_t buf_size);

/**
* Write a CBOR byte string to buffer.
* @param buf Buffer to write to
* @param buf_size Size of output buffer
* @param data Bytes to write
* @param data_len Length of bytes to write
* @return Result containing number of bytes written or error
*/
gm_result_size_t gm_cbor_write_bytes(uint8_t *buf, size_t buf_size,
const uint8_t *data, size_t data_len);

/**
* Write a CBOR text string to buffer.
* @param buf Buffer to write to
* @param buf_size Size of output buffer
* @param text Null-terminated text to write
* @return Result containing number of bytes written or error
*/
gm_result_size_t gm_cbor_write_text(uint8_t *buf, size_t buf_size, const char *text);

#endif /* GITMIND_CBOR_CBOR_H */
71 changes: 71 additions & 0 deletions core/include/gitmind/cbor/constants_cbor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* SPDX-License-Identifier: LicenseRef-MIND-UCAL-1.0 */
/* 漏 2025 J. Kirby Ross / Neuroglyph Collective */

#ifndef GITMIND_CONSTANTS_CBOR_H
#define GITMIND_CONSTANTS_CBOR_H

/* CBOR Major Types (RFC 7049) */
#define CBOR_TYPE_UNSIGNED 0x00
#define CBOR_TYPE_NEGATIVE 0x20
#define CBOR_TYPE_BYTES 0x40
#define CBOR_TYPE_TEXT 0x60
#define CBOR_TYPE_ARRAY 0x80
#define CBOR_TYPE_MAP 0xA0
#define CBOR_TYPE_TAG 0xC0
#define CBOR_TYPE_SIMPLE 0xE0

/* CBOR Type Masks */
#define CBOR_TYPE_MASK 0xE0
#define CBOR_ADDITIONAL_INFO_MASK 0x1F

/* CBOR Additional Information Values */
#define CBOR_MAX_IMMEDIATE 0x17
#define CBOR_IMMEDIATE_THRESHOLD 24
#define CBOR_UINT8_FOLLOWS 0x18
#define CBOR_UINT16_FOLLOWS 0x19
#define CBOR_UINT32_FOLLOWS 0x1A
#define CBOR_UINT64_FOLLOWS 0x1B
#define CBOR_RESERVED_28 0x1C
#define CBOR_RESERVED_29 0x1D
#define CBOR_RESERVED_30 0x1E
#define CBOR_INDEFINITE 0x1F

/* CBOR Array Sizes for git-mind */
#define CBOR_ARRAY_SIZE_ATTRIBUTED 13 /* Attributed edge format */
#define CBOR_ARRAY_SIZE_LEGACY 8 /* Legacy edge format */
#define CBOR_ARRAY_SIZE_EDGE 7 /* Basic edge format */

/* Field Sizes */
#define CBOR_SHA_SIZE 20 /* Git SHA1 size in bytes */
#define CBOR_ULID_SIZE 26 /* ULID size in bytes */
#define CBOR_TIMESTAMP_SIZE 8 /* Unix timestamp size */

/* Field Limits */
#define CBOR_MAX_STRING_LENGTH 65536 /* Maximum string field length */
#define CBOR_MAX_PATH_LENGTH 4096 /* Maximum path length */
#define CBOR_MAX_TYPE_LENGTH 64 /* Maximum relationship type length */
#define CBOR_MAX_SOURCE_LENGTH 32 /* Maximum source identifier length */
#define CBOR_MAX_AUTHOR_LENGTH 256 /* Maximum author string length */
#define CBOR_MAX_SESSION_LENGTH 256 /* Maximum session ID length */
#define CBOR_MAX_LANE_LENGTH 32 /* Maximum lane name length */

/* Bit Shift Constants */
#define SHIFT_8 8
#define SHIFT_16 16
#define SHIFT_24 24
#define SHIFT_32 32
#define SHIFT_40 40
#define SHIFT_48 48
#define SHIFT_56 56

/* Byte Operations */
#define BYTE_SIZE 8
#define BYTE_MASK 0xFF

/* Endianness Helpers */
#define CBOR_ENCODE_UINT16(x) ((((x) >> 8) & 0xFF) | (((x) & 0xFF) << 8))
#define CBOR_ENCODE_UINT32(x) \
((((x) >> 24) & 0xFF) | (((x) >> 8) & 0xFF00) | (((x) << 8) & 0xFF0000) | \
(((x) << 24) & 0xFF000000))

#endif /* GITMIND_CONSTANTS_CBOR_H */
9 changes: 6 additions & 3 deletions core/include/gitmind/time/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <gitmind/result.h>
#include <stddef.h>
#include <time.h>
/* NOLINTNEXTLINE(misc-include-cleaner) - provides clockid_t on some systems */
#include <sys/types.h>

/* Result types for time operations */
GM_RESULT_DEF(gm_result_time, time_t);
Expand All @@ -18,11 +20,12 @@ GM_RESULT_DEF(gm_result_tm_ptr, struct tm *);
*/
typedef struct gm_time_ops {
gm_result_time_t (*time)(time_t *tloc);
gm_result_void_t (*clock_gettime)(clockid_t clk_id, struct timespec *tp);
/* NOLINTNEXTLINE(misc-include-cleaner) - clockid_t from time.h/sys/types.h */
gm_result_void_t (*clock_gettime)(clockid_t clk_id, struct timespec *timespec_ptr);
gm_result_tm_ptr_t (*localtime_r)(const time_t *timep, struct tm *result);
gm_result_tm_ptr_t (*gmtime_r)(const time_t *timep, struct tm *result);
gm_result_size_t (*strftime)(char *s, size_t max, const char *format,
const struct tm *tm);
gm_result_size_t (*strftime)(char *str, size_t max, const char *format,
const struct tm *time_ptr);
} gm_time_ops_t;

/**
Expand Down
Loading
Loading