From b0330d62e5bd5ecbcba742e4349c984139c4c2f8 Mon Sep 17 00:00:00 2001 From: Ondrej Kozina Date: Mon, 18 Feb 2019 15:59:44 +0100 Subject: [PATCH] Add id member in volume_key structure. Also adds set/get helper routines. --- lib/internal.h | 3 +++ lib/volumekey.c | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/internal.h b/lib/internal.h index 7267d51b..8ca50164 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -75,6 +75,7 @@ struct crypt_device; struct volume_key { + int id; size_t keylength; const char *key_description; char key[]; @@ -84,6 +85,8 @@ struct volume_key *crypt_alloc_volume_key(size_t keylength, const char *key); struct volume_key *crypt_generate_volume_key(struct crypt_device *cd, size_t keylength); void crypt_free_volume_key(struct volume_key *vk); int crypt_volume_key_set_description(struct volume_key *key, const char *key_description); +void crypt_volume_key_set_id(struct volume_key *vk, int id); +int crypt_volume_key_get_id(const struct volume_key *vk); struct crypt_pbkdf_type *crypt_get_pbkdf(struct crypt_device *cd); int init_pbkdf_type(struct crypt_device *cd, diff --git a/lib/volumekey.c b/lib/volumekey.c index bb771039..b84cd7da 100644 --- a/lib/volumekey.c +++ b/lib/volumekey.c @@ -39,6 +39,7 @@ struct volume_key *crypt_alloc_volume_key(size_t keylength, const char *key) vk->key_description = NULL; vk->keylength = keylength; + vk->id = -1; /* keylength 0 is valid => no key */ if (vk->keylength) { @@ -64,6 +65,17 @@ int crypt_volume_key_set_description(struct volume_key *vk, const char *key_desc return 0; } +void crypt_volume_key_set_id(struct volume_key *vk, int id) +{ + if (vk && id >= 0) + vk->id = id; +} + +int crypt_volume_key_get_id(const struct volume_key *vk) +{ + return vk ? vk->id : -1; +} + void crypt_free_volume_key(struct volume_key *vk) { if (vk) {