kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

kpkg.h (3336B)


      1 #ifndef KIT_DIST_KPKG_H
      2 #define KIT_DIST_KPKG_H
      3 
      4 #include <kit/core.h>
      5 #include <stddef.h>
      6 #include <stdint.h>
      7 
      8 #include "dist.h"
      9 
     10 #define DIST_KPKG_ALIGNMENT 16u
     11 #define DIST_KPKG_CHUNK_SIZE_DEFAULT 65536u
     12 
     13 #define DIST_KPKG3_MAGIC "kpkg3\0"
     14 #define DIST_KPKG3_VERSION 3u
     15 #define DIST_KPKG3_HEADER_SIZE 96u
     16 #define DIST_KPKG3_ALIGNMENT 16u
     17 #define DIST_KPKG3_CHUNK_SIZE_DEFAULT 65536u
     18 #define DIST_KPKG3_INDEX_RECORD_SIZE 168u
     19 #define DIST_KPKG3_HASH "blake2b-256"
     20 #define DIST_KPKG3_TREE_FORMAT "kit-tree-v1"
     21 #define DIST_KPKG3_BLOB_FORMAT "kit-blob-v1"
     22 
     23 typedef enum DistKpkgCompression {
     24   DIST_KPKG_COMP_NONE = 0,
     25   DIST_KPKG_COMP_LZ4_BLOCK_V1 = 1,
     26 } DistKpkgCompression;
     27 
     28 typedef struct DistKpkg3Header {
     29   uint64_t manifest_offset, manifest_size;
     30   uint64_t signature_offset, signature_size;
     31   uint64_t descriptor_offset, descriptor_size;
     32   uint64_t descriptor_signature_offset, descriptor_signature_size;
     33   uint64_t pubkey_offset, pubkey_size;
     34 } DistKpkg3Header;
     35 
     36 typedef struct DistKpkg3IndexRecord {
     37   uint8_t blob_id[DIST_BLAKE2B_LEN];
     38   uint64_t chunk_index;
     39   uint64_t content_offset; /* relative to embedded content region */
     40   uint64_t stored_size;
     41   uint64_t raw_size;
     42   uint32_t compression;
     43   uint8_t stored_hash[DIST_BLAKE2B_LEN];
     44   uint8_t raw_hash[DIST_BLAKE2B_LEN];
     45   uint8_t leaf_hash[DIST_BLAKE2B_LEN];
     46 } DistKpkg3IndexRecord;
     47 
     48 typedef struct DistKpkg3TreeObject {
     49   uint8_t tree[DIST_BLAKE2B_LEN];
     50   uint64_t offset, size;
     51   int embedded;
     52   uint8_t blake2b[DIST_BLAKE2B_LEN];
     53   char url[DIST_PATH_MAX + 1];
     54 } DistKpkg3TreeObject;
     55 
     56 typedef enum DistKpkg3ChunkSourceKind {
     57   DIST_KPKG3_CHUNK_SOURCE_EMBEDDED = 1,
     58   DIST_KPKG3_CHUNK_SOURCE_URL_TEMPLATE = 2,
     59 } DistKpkg3ChunkSourceKind;
     60 
     61 typedef struct DistKpkg3ChunkSource {
     62   uint32_t kind;
     63   char tmpl[DIST_PATH_MAX + 1];
     64 } DistKpkg3ChunkSource;
     65 
     66 typedef struct DistKpkg3Descriptor {
     67   uint8_t package_id[DIST_BLAKE2B_LEN];
     68   uint64_t chunk_size, alignment;
     69   uint64_t tree_offset, tree_size;
     70   uint8_t tree_root[DIST_BLAKE2B_LEN];
     71   uint64_t index_offset, index_size, index_bytes;
     72   uint8_t index_root[DIST_BLAKE2B_LEN];
     73   char index_url[DIST_PATH_MAX + 1];
     74   uint64_t content_offset, content_size;
     75   uint8_t content_root[DIST_BLAKE2B_LEN];
     76   DistKpkg3TreeObject trees[DIST_MAX_OUTPUTS];
     77   size_t n_trees;
     78   DistKpkg3ChunkSource chunk_sources[DIST_MAX_OUTPUTS];
     79   size_t n_chunk_sources;
     80 } DistKpkg3Descriptor;
     81 
     82 void dist_kpkg3_region_root(uint8_t out[DIST_BLAKE2B_LEN], const char* kind,
     83                             const uint8_t* data, size_t len);
     84 int dist_kpkg3_write_header(KitWriter* out, const DistKpkg3Header* h);
     85 int dist_kpkg3_read_header(const uint8_t* data, size_t len, DistKpkg3Header* h);
     86 void dist_kpkg3_encode_index_record(uint8_t out[DIST_KPKG3_INDEX_RECORD_SIZE],
     87                                     const DistKpkg3IndexRecord* r);
     88 int dist_kpkg3_decode_index_record(const uint8_t* data, size_t len,
     89                                    DistKpkg3IndexRecord* r);
     90 int dist_kpkg3_descriptor_emit(KitWriter* out, const DistKpkg3Descriptor* d);
     91 int dist_kpkg3_descriptor_parse(const uint8_t* data, size_t len,
     92                                 DistKpkg3Descriptor* d, char* err,
     93                                 size_t errcap);
     94 
     95 const char* dist_kpkg_compression_name(uint32_t c);
     96 int dist_kpkg_compression_parse(const char* s, uint32_t* out);
     97 
     98 #endif