[riot-notifications] [RIOT-OS/RIOT] sys/credman: add key load functions (#16263)

benpicco notifications at github.com
Thu Sep 16 13:48:51 CEST 2021


@benpicco commented on this pull request.



> @@ -90,6 +105,247 @@ int credman_add(const credman_credential_t *credential)
     return ret;
 }
 
+#if IS_USED(MODULE_CREDMAN_LOAD)
+int credman_load_public_key(const uint8_t *buf, size_t buf_len, ecdsa_public_key_t *out)
+{
+    assert(buf);
+    assert(out);
+
+    int obj_count = der_object_count((uint8_t *)buf, buf_len);
+    if (obj_count <= 0) {
+        DEBUG("credman: could not calculate the number of elements within the key\n");
+        return CREDMAN_INVALID;
+    }
+
+    asn1_tree objects[obj_count];

Is there an alternative to using VLA here?

> +
+    return _parse_ecc_point(algorithm_id->next, &out->x, &out->y);
+}
+
+int credman_load_private_key(const uint8_t *buf, size_t buf_len, credman_credential_t *cred)
+{
+    assert(buf);
+    assert(cred);
+
+    int obj_count = der_object_count((uint8_t *)buf, buf_len);
+    if (obj_count <= 0) {
+        DEBUG("credman: could not calculate the number of elements within the key\n");
+        return CREDMAN_INVALID;
+    }
+
+    asn1_tree objects[obj_count];

same here

> +        DEBUG("credman: invalid private key\n");
+        return CREDMAN_INVALID;
+    }
+
+    cred->type = CREDMAN_TYPE_ECDSA;
+    cred->params.ecdsa.public_key.x = NULL;
+    cred->params.ecdsa.public_key.y = NULL;
+
+    cred->params.ecdsa.private_key = node->data;
+
+    /* try to find a publicKey by tag */
+    while (node && node->type != ASN1_CONTEXT_TAG(1)) {
+        node = node->next;
+    }
+
+    if(!node) {

```suggestion
    if (!node) {
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/16263#pullrequestreview-756182851
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210916/2ffb68ab/attachment-0001.htm>


More information about the notifications mailing list