Minor tidyups (#232)
* Don't add hash_def when not required
Exit hash_andor_sign_block early if neither hash_value not signature is needed
* Add validation that the partition name is < 128 characters long, as the size is only 7 bits
diff --git a/bintool/bintool.cpp b/bintool/bintool.cpp
index 5df18d2..e75c0b0 100644
--- a/bintool/bintool.cpp
+++ b/bintool/bintool.cpp
@@ -591,6 +591,11 @@
#if HAS_MBEDTLS
void hash_andor_sign_block(block *new_block, const public_t public_key, const private_t private_key, bool hash_value, bool sign, std::vector<uint8_t> to_hash) {
+ if (!(hash_value || sign)) {
+ // Don't need to add anything if not actually hashing or signing
+ return;
+ }
+
std::shared_ptr<hash_def_item> hash_def = std::make_shared<hash_def_item>(PICOBIN_HASH_SHA256);
new_block->items.push_back(hash_def);
diff --git a/bintool/metadata.h b/bintool/metadata.h
index f06fcbe..a01e048 100644
--- a/bintool/metadata.h
+++ b/bintool/metadata.h
@@ -208,6 +208,7 @@
}
if (name.size() > 0) {
char size = name.size();
+ assert(size & 0x7f == size);
std::vector<char> name_vec = {size};
for (char c : name) {
name_vec.push_back(c);
diff --git a/json/schemas/partition-table-schema.json b/json/schemas/partition-table-schema.json
index 92eadcd..2bfa2bf 100644
--- a/json/schemas/partition-table-schema.json
+++ b/json/schemas/partition-table-schema.json
@@ -52,7 +52,8 @@
"properties": {
"name": {
"description": "Partition Name",
- "type": "string"
+ "type": "string",
+ "maxLength": 127
},
"id": {
"description": "Partition ID",
diff --git a/main.cpp b/main.cpp
index 2819a41..7d5df3a 100644
--- a/main.cpp
+++ b/main.cpp
@@ -6607,7 +6607,13 @@
}
new_p.flags |= (link_value << PICOBIN_PARTITION_FLAGS_LINK_VALUE_LSB) & PICOBIN_PARTITION_FLAGS_LINK_VALUE_BITS;
}
- if (p.contains("name")) { new_p.name = p["name"]; new_p.flags |= PICOBIN_PARTITION_FLAGS_HAS_NAME_BITS; }
+ if (p.contains("name")) {
+ new_p.name = p["name"];
+ new_p.flags |= PICOBIN_PARTITION_FLAGS_HAS_NAME_BITS;
+ if (new_p.name.size() > 127) {
+ fail(ERROR_INCOMPATIBLE, "Partition name \"%s\" is %d characters long - max length is 127 characters\n", new_p.name.c_str(), new_p.name.size());
+ }
+ }
if (p.contains("id")) {
if (get_json_int(p["id"], new_p.id)) {new_p.flags |= PICOBIN_PARTITION_FLAGS_HAS_ID_BITS;}
else {string p_id = p["id"]; fail(ERROR_INCOMPATIBLE, "Partition ID \"%s\" is not a valid 64bit integer\n", p_id.c_str());}