tree.h (1237B)
1 #ifndef KIT_DIST_TREE_H 2 #define KIT_DIST_TREE_H 3 4 #include <kit/core.h> 5 #include <stddef.h> 6 #include <stdint.h> 7 8 #include "dist.h" 9 10 #define DIST_TREE_MAGIC "kit-tree 1" 11 #define DIST_TREE_HASH "blake2b-256" 12 #define DIST_TREE_BLOB_FORMAT "kit-blob-v1" 13 14 typedef enum DistTreeMode { 15 DIST_TREE_MODE_FILE = 0, 16 DIST_TREE_MODE_EXEC = 1, 17 } DistTreeMode; 18 19 typedef struct DistTreeEntry { 20 char path[DIST_PATH_MAX + 1]; 21 uint8_t mode; /* DistTreeMode */ 22 uint8_t blob[DIST_BLAKE2B_LEN]; 23 uint8_t root[DIST_BLAKE2B_LEN]; 24 uint64_t size; 25 } DistTreeEntry; 26 27 typedef struct DistTree { 28 DistTreeEntry* entries; 29 size_t n_entries; 30 size_t cap_entries; 31 } DistTree; 32 33 int dist_tree_mode_parse(const char* s, uint8_t* out); 34 const char* dist_tree_mode_name(uint8_t mode); 35 int dist_tree_path_valid(const char* path); 36 int dist_tree_sort_validate(DistTree* tree, char* err, size_t errcap); 37 int dist_tree_emit(const DistTree* tree, KitWriter* out); 38 int dist_tree_parse(const uint8_t* data, size_t len, DistTree* out, char* err, 39 size_t errcap); 40 void dist_tree_id(uint8_t out[DIST_BLAKE2B_LEN], const uint8_t* manifest, 41 size_t len); 42 const DistTreeEntry* dist_tree_find(const DistTree* tree, const char* path); 43 44 #endif