diff options
author | Timo Teräs <timo.teras@iki.fi> | 2021-10-25 15:41:08 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2021-10-25 15:48:59 +0300 |
commit | 9bd1e95e5be92e9db3e0f59e3920105c2f578846 (patch) | |
tree | 60957c01482b325c0b71e6ad756a5c10add67516 /src | |
parent | 50ab589e9a5a84592ee4c0ac5a49506bb6c552fc (diff) | |
download | apk-tools-9bd1e95e5be92e9db3e0f59e3920105c2f578846.tar.gz apk-tools-9bd1e95e5be92e9db3e0f59e3920105c2f578846.tar.bz2 apk-tools-9bd1e95e5be92e9db3e0f59e3920105c2f578846.tar.xz apk-tools-9bd1e95e5be92e9db3e0f59e3920105c2f578846.zip |
mkpkg: make unique-id field a blob
Diffstat (limited to 'src')
-rw-r--r-- | src/adb.c | 18 | ||||
-rw-r--r-- | src/adb.h | 1 | ||||
-rw-r--r-- | src/apk_adb.c | 4 | ||||
-rw-r--r-- | src/app_mkpkg.c | 9 |
4 files changed, 30 insertions, 2 deletions
@@ -672,6 +672,18 @@ adb_val_t adb_w_blob(struct adb *db, apk_blob_t b) return ADB_VAL(o, adb_w_data(db, vec, ARRAY_SIZE(vec), vec[0].iov_len)); } +static adb_val_t adb_w_blob_raw(struct adb *db, apk_blob_t b) +{ + adb_val_t val; + size_t num_buckets; + + num_buckets = db->num_buckets; + db->num_buckets = 0; + val = adb_w_blob(db, b); + db->num_buckets = num_buckets; + return val; +} + adb_val_t adb_w_int(struct adb *db, uint32_t val) { if (val >= 0x10000000) @@ -869,6 +881,12 @@ adb_val_t adb_wo_blob(struct adb_obj *o, unsigned i, apk_blob_t b) return adb_wo_val(o, i, adb_w_blob(o->db, b)); } +adb_val_t adb_wo_blob_raw(struct adb_obj *o, unsigned i, apk_blob_t b) +{ + assert(o->schema->kind == ADB_KIND_OBJECT); + return adb_wo_val(o, i, adb_w_blob_raw(o->db, b)); +} + adb_val_t adb_wo_obj(struct adb_obj *o, unsigned i, struct adb_obj *no) { assert(o->schema->kind == ADB_KIND_OBJECT); @@ -218,6 +218,7 @@ adb_val_t adb_wo_val(struct adb_obj *o, unsigned i, adb_val_t); adb_val_t adb_wo_val_fromstring(struct adb_obj *o, unsigned i, apk_blob_t); adb_val_t adb_wo_int(struct adb_obj *o, unsigned i, uint32_t); adb_val_t adb_wo_blob(struct adb_obj *o, unsigned i, apk_blob_t); +adb_val_t adb_wo_blob_raw(struct adb_obj *o, unsigned i, apk_blob_t); adb_val_t adb_wo_obj(struct adb_obj *o, unsigned i, struct adb_obj *); adb_val_t adb_wo_arr(struct adb_obj *o, unsigned i, struct adb_obj *); adb_val_t adb_wa_append(struct adb_obj *o, adb_val_t); diff --git a/src/apk_adb.c b/src/apk_adb.c index 8a887cf..f8b0fe6 100644 --- a/src/apk_adb.c +++ b/src/apk_adb.c @@ -35,7 +35,7 @@ adb_val_t adb_wo_pkginfo(struct adb_obj *obj, unsigned int f, apk_blob_t val) case ADBI_PI_UNIQUE_ID: if (!val.ptr || val.len < 4) break; apk_blob_pull_csum(&val, &csum); - v = adb_w_int(obj->db, get_unaligned32(csum.data) & ADB_VALUE_MASK); + v = adb_w_blob(obj->db, APK_BLOB_CSUM(csum)); break; case ADBI_PI_REPO_COMMIT: if (val.len < 40) break; @@ -386,7 +386,7 @@ const struct adb_object_schema schema_pkginfo = { .fields = { ADB_FIELD(ADBI_PI_NAME, "name", scalar_string), ADB_FIELD(ADBI_PI_VERSION, "version", scalar_version), - ADB_FIELD(ADBI_PI_UNIQUE_ID, "unique-id", scalar_int), + ADB_FIELD(ADBI_PI_UNIQUE_ID, "unique-id", scalar_hexblob), ADB_FIELD(ADBI_PI_DESCRIPTION, "description", scalar_string), ADB_FIELD(ADBI_PI_ARCH, "arch", scalar_string), ADB_FIELD(ADBI_PI_LICENSE, "license", scalar_string), diff --git a/src/app_mkpkg.c b/src/app_mkpkg.c index 6944599..d855999 100644 --- a/src/app_mkpkg.c +++ b/src/app_mkpkg.c @@ -229,7 +229,10 @@ static int mkpkg_main(void *pctx, struct apk_ctx *ac, struct apk_string_array *a int i, j, r; struct mkpkg_ctx *ctx = pctx; struct apk_ostream *os; + struct apk_digest d = {}; char outbuf[PATH_MAX]; + const int uid_len = apk_digest_alg_len(APK_DIGEST_SHA1); + apk_blob_t uid = APK_BLOB_PTR_LEN((char*)d.data, uid_len); ctx->ac = ac; adb_w_init_alloca(&ctx->db, ADB_SCHEMA_PACKAGE, 40); @@ -271,6 +274,7 @@ static int mkpkg_main(void *pctx, struct apk_ctx *ac, struct apk_string_array *a } adb_wo_int(&pkgi, ADBI_PI_INSTALLED_SIZE, ctx->installed_size); + adb_wo_blob(&pkgi, ADBI_PI_UNIQUE_ID, uid); adb_wo_obj(&pkg, ADBI_PKG_PKGINFO, &pkgi); adb_wo_obj(&pkg, ADBI_PKG_PATHS, &ctx->paths); if (ctx->has_scripts) { @@ -294,6 +298,11 @@ static int mkpkg_main(void *pctx, struct apk_ctx *ac, struct apk_string_array *a adb_ro_obj(&pkg, ADBI_PKG_PKGINFO, &pkgi); adb_ro_obj(&pkg, ADBI_PKG_PATHS, &ctx->paths); + // fill in unique id + apk_digest_calc(&d, APK_DIGEST_SHA256, ctx->db.adb.ptr, ctx->db.adb.len); + uid = adb_ro_blob(&pkgi, ADBI_PI_UNIQUE_ID); + memcpy(uid.ptr, d.data, uid.len); + if (!ctx->output) { ctx->output = pkgi_filename(&pkgi, outbuf, sizeof outbuf); } |