commit - c3434cef3dd7dbd62000d244d716b997f98226a5
commit + ab62f2123a6a5e453ab9645daf04cd1f2bd8442d
blob - 1b9a3c7d50834fc34fcac7ff7919ea96d024bf44
blob + a31098e14ec3916c567d922a117d7d74baf597a8
--- lib/got_lib_pack.h
+++ lib/got_lib_pack.h
struct got_packidx {
char *path_packidx; /* actual on-disk path */
int fd;
+ enum got_hash_algorithm algo;
uint8_t *map;
size_t len;
size_t nlargeobj;
const struct got_error *got_packidx_init_hdr(struct got_packidx *, int, off_t);
const struct got_error *got_packidx_open(struct got_packidx **,
- int, const char *, int);
+ int, const char *, int, enum got_hash_algorithm);
const struct got_error *got_packidx_close(struct got_packidx *);
const struct got_error *got_packidx_get_packfile_path(char **, const char *);
off_t got_packidx_get_object_offset(struct got_packidx *, int idx);
blob - a17be0408a103339d10ae1a1e9736deb19fb0b74
blob + 9365381c6d173fbb3fedfb6b7d428db95f6e93f5
--- lib/got_lib_privsep.h
+++ lib/got_lib_privsep.h
struct got_imsg_packidx {
size_t len;
off_t packfile_size;
+ int algo;
/* Additionally, a file desciptor is passed via imsg. */
};
blob - 84302f45b8db014cc23483d23a273c03f7fa077c
blob + 5aabc43dd66acd9a5cb6ffe80627cc59ca257fbf
--- lib/pack.c
+++ lib/pack.c
got_packidx_init_hdr(struct got_packidx *p, int verify, off_t packfile_size)
{
const struct got_error *err = NULL;
- enum got_hash_algorithm algo = GOT_HASH_SHA1;
struct got_packidx_v2_hdr *h;
struct got_hash ctx;
uint8_t hash[GOT_HASH_DIGEST_MAXLEN];
ssize_t n;
int i;
- got_hash_init(&ctx, algo);
+ got_hash_init(&ctx, p->algo);
h = &p->hdr;
offset = 0;
remain -= len_fanout;
nobj = be32toh(h->fanout_table[0xff]);
- len_ids = nobj * sizeof(*h->sorted_ids);
+ len_ids = nobj * got_hash_digest_length(p->algo);
if (len_ids <= nobj || len_ids > remain) {
err = got_error(GOT_ERR_BAD_PACKIDX);
goto done;
}
if (verify) {
got_hash_update(&ctx, h->trailer->packfile_sha1,
- SHA1_DIGEST_LENGTH);
+ got_hash_digest_length(p->algo));
got_hash_final(&ctx, hash);
if (got_hash_cmp(ctx.algo, hash, h->trailer->packidx_sha1) != 0)
err = got_error(GOT_ERR_PACKIDX_CSUM);
const struct got_error *
got_packidx_open(struct got_packidx **packidx,
- int dir_fd, const char *relpath, int verify)
+ int dir_fd, const char *relpath, int verify,
+ enum got_hash_algorithm algo)
{
const struct got_error *err = NULL;
struct got_packidx *p = NULL;
goto done;
}
+ p->algo = algo;
+
p->fd = openat(dir_fd, relpath, O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
if (p->fd == -1) {
err = got_error_from_errno2("openat", relpath);
blob - 8aa0ad08ca44ef4b71ccf60df2cf2b962c13da78
blob + 5d128736fd8cc8b24a9e2f8fd6edd0d243752fcc
--- lib/pack_index.c
+++ lib/pack_index.c
}
if (err)
break;
- got_hash_init(&ctx, GOT_HASH_SHA1);
+ got_hash_init(&ctx, pack->algo);
err = got_object_type_label(&obj_label, obj->type);
if (err) {
free(data);
goto done;
}
headerlen = strlen(header) + 1;
- got_hash_init(&ctx, GOT_HASH_SHA1);
+ got_hash_init(&ctx, pack->algo);
got_hash_update(&ctx, header, headerlen);
if (max_size > GOT_DELTA_RESULT_SIZE_CACHED_MAX) {
err = read_file_digest(&ctx, tmpfile, len);
"bad packfile with zero objects");
/* We compute the SHA1 of pack file contents and verify later on. */
- got_hash_init(&ctx, GOT_HASH_SHA1);
+ got_hash_init(&ctx, pack->algo);
got_hash_update(&ctx, &hdr, sizeof(hdr));
/*
blob - 1edd0153662b01a8fd962579a4b5a7c5af42df69
blob + 9fc1dd22c6d4e2c1868cd493424a0d5b4fe5ed5a
--- lib/privsep.c
+++ lib/privsep.c
ipackidx.len = packidx->len;
ipackidx.packfile_size = pack->filesize;
+ ipackidx.algo = packidx->algo;
fd = dup(packidx->fd);
if (fd == -1)
return got_error_from_errno("dup");
blob - 7323331c86c9085cb6ec9fdad463a7ff32f92518
blob + 47e4642c06e4806292166b184a34bedafab3eb6c
--- lib/repository.c
+++ lib/repository.c
continue; /* already searched */
err = got_packidx_open(packidx, got_repo_get_fd(repo),
- path_packidx, 0);
+ path_packidx, 0, repo->algo);
if (err)
goto done;
/* No luck. Search the filesystem. */
err = got_packidx_open(packidx, got_repo_get_fd(repo),
- path_packidx, 0);
+ path_packidx, 0, repo->algo);
if (err)
return err;
path_packidx = pe->path;
err = got_packidx_open(&packidx, got_repo_get_fd(repo),
- path_packidx, 0);
+ path_packidx, 0, repo->algo);
if (err)
break;
}
err = got_packidx_open(&packidx, got_repo_get_fd(repo),
- path_packidx, 0);
+ path_packidx, 0, repo->algo);
free(path_packidx);
if (err)
goto done;
blob - b0168b3397ef9e155f6ca23c6057126006b3f1f6
blob + da0b3b49fa523700d29c8be5ec7542ae6ecc9c4e
--- lib/repository_admin.c
+++ lib/repository_admin.c
goto done;
}
- err = got_packidx_open(&packidx, got_repo_get_fd(repo), idxpath, 1);
+ err = got_packidx_open(&packidx, got_repo_get_fd(repo), idxpath, 1,
+ repo->algo);
if (err)
goto done;
blob - aec894fa8b4604174f7faf23446d66e16ac0d570
blob + b4ec204772c2f95248eaebb7f4c5d724d535c17b
--- libexec/got-read-pack/got-read-pack.c
+++ libexec/got-read-pack/got-read-pack.c
}
memcpy(&ipackidx, imsg.data, sizeof(ipackidx));
+ p->algo = ipackidx.algo;
p->fd = imsg_get_fd(&imsg);
p->len = ipackidx.len;
if (p->fd == -1) {