add representation of hash, decode dependencies

laumann
Sep 10, 2022, 7:44 PM
YG4DZB3AW3Z3LB5CFBZZ4ORJOLZFN3G4CA2YTAMSUOQX3USVNVEAC

Dependencies

  • [2] 2C2EF2GK move blake3 files to vendor/blake3
  • [3] LCEKN25G change: parse authors
  • [4] VKLGQREY change: add base32 decode, initial deconstruction of hashed
  • [5] Y26WT3ZF change: decode message, description and timestamp
  • [6] Q7TKZCJP Add initial support for reading the offsets from a (fixed) change
  • [*] PEUS54XQ
  • [*] OBKF6SII change: decompress the hashed section too
  • [*] B3XLVPNC Add ani.c and initial Makefile
  • [*] X36ICMJN Initial import for blake3

Change contents

  • file addition: hash.h (----------)
    [8.1]
    #ifndef HASH_H
    #define HASH_H
    #define HASH_NONE 0
    #define HASH_BLAKE3 1
    #define BLAKE3_BYTES 32
    struct hash {
    uint8_t variant; /* One of the HASH_* defines */
    uint8_t bytes[BLAKE3_BYTES];
    };
    struct hash_list {
    size_t len;
    struct hash *entries;
    };
    void hash_print(struct hash *);
    #endif
  • file addition: hash.c (----------)
    [8.1]
    #include <stdlib.h>
    #include <stdint.h>
    #include <stdio.h>
    #include "hash.h"
    void
    hash_print(struct hash *hash)
    {
    int i;
    switch (hash->variant) {
    case HASH_NONE:
    printf("(none)\n");
    break;
    case HASH_BLAKE3:
    for (i = 0; i < BLAKE3_BYTES; i++)
    printf("%02x", hash->bytes[i]);
    printf("\n");
    break;
    default:
    abort();
    }
    }
  • replacement in change.h at line 71
    [4.568][4.568:661]()
    void *dependencies; /* array of hashes */
    void *extra_known; /* another array of hashes */
    [4.568]
    [4.661]
    struct hash_list dependencies; /* array of hashes */
    struct hash_list extra_known; /* another array of hashes */
  • edit in change.c at line 13
    [2.285700]
    [4.1192]
    #include "hash.h"
  • edit in change.c at line 250
    [3.1176]
    [3.1176]
    }
    /* Decode dependencies (Vec<Hash>) */
    len = bincode_getu64(&binstat);
    hashed.dependencies.len = len;
    hashed.dependencies.entries = xmalloc(sizeof(struct hash) * len);
  • edit in change.c at line 258
    [3.1177]
    [3.1177]
    printf("[[dependencies]]\n");
    for (i = 0; i < hashed.dependencies.len; i++) {
    hashed.dependencies.entries[i].variant = bincode_getu32(&binstat);
    switch (hashed.dependencies.entries[i].variant) {
    case HASH_BLAKE3:
    memcpy(hashed.dependencies.entries[i].bytes, binstat.buf, BLAKE3_BYTES);
    binstat.buf += BLAKE3_BYTES;
    binstat.avail -= BLAKE3_BYTES;
    break;
    case HASH_NONE:
    /* Do nothing, no bytes to consume */
    break;
    default:
    abort();
    }
    hash_print(&hashed.dependencies.entries[i]);
  • edit in change.c at line 275
    [3.1180][3.1180:1227]()
    dump_buf("buf2", binstat.buf, binstat.avail);
  • edit in change.c at line 276
    [4.1640]
    [4.1640]
    /* Decode extra_known (Vec<Hash> again) */
    len = bincode_getu64(&binstat);
    hashed.extra_known.len = len;
    hashed.extra_known.entries = xmalloc(sizeof(struct hash) * len);
  • edit in change.c at line 281
    [4.1641]
    [9.1373]
    printf("[[extra_known]]\n");
    for (i = 0; i < hashed.extra_known.len; i++) {
    hashed.extra_known.entries[i].variant = bincode_getu32(&binstat);
    switch (hashed.extra_known.entries[i].variant) {
    case HASH_BLAKE3:
    memcpy(hashed.extra_known.entries[i].bytes, binstat.buf, BLAKE3_BYTES);
    binstat.buf += BLAKE3_BYTES;
    binstat.avail -= BLAKE3_BYTES;
    break;
    case HASH_NONE:
    /* Do nothing, no bytes to consume */
    break;
    default:
    abort();
    }
    hash_print(&hashed.extra_known.entries[i]);
    }
  • edit in Makefile at line 26
    [4.3502]
    [11.53469]
    OBJS += hash.o