- if (keylist) {
- SendDlgItemMessage(keylist, 100, LB_RESETCONTENT, 0, 0);
- for (i = 0; NULL != (rkey = index234(rsakeys, i)); i++) {
- char listentry[512], *p;
- /*
- * Replace two spaces in the fingerprint with tabs, for
- * nice alignment in the box.
- */
- strcpy(listentry, "ssh1\t");
- p = listentry + strlen(listentry);
- rsa_fingerprint(p, sizeof(listentry) - (p - listentry), rkey);
- p = strchr(listentry, ' ');
- if (p)
- *p = '\t';
- p = strchr(listentry, ' ');
- if (p)
- *p = '\t';
- SendDlgItemMessage(keylist, 100, LB_ADDSTRING,
- 0, (LPARAM) listentry);
- }
- for (i = 0; NULL != (skey = index234(ssh2keys, i)); i++) {
- char listentry[512], *p;
- int len;
- /*
- * Replace two spaces in the fingerprint with tabs, for
- * nice alignment in the box.
- */
- p = skey->alg->fingerprint(skey->data);
- strncpy(listentry, p, sizeof(listentry));
- p = strchr(listentry, ' ');
- if (p)
- *p = '\t';
- p = strchr(listentry, ' ');
- if (p)
- *p = '\t';
- len = strlen(listentry);
- if (len < sizeof(listentry) - 2) {
- listentry[len] = '\t';
- strncpy(listentry + len + 1, skey->comment,
- sizeof(listentry) - len - 1);
- }
- SendDlgItemMessage(keylist, 100, LB_ADDSTRING, 0,
- (LPARAM) listentry);
- }
- SendDlgItemMessage(keylist, 100, LB_SETCURSEL, (WPARAM) - 1, 0);
+ /*
+ * Count up the number and length of keys we hold.
+ */
+ len = 4;
+ nkeys = 0;
+ for (i = 0; NULL != (key = index234(rsakeys, i)); i++) {
+ nkeys++;
+ blob = rsa_public_blob(key, &bloblen);
+ len += bloblen;
+ sfree(blob);
+ len += 4 + strlen(key->comment);
+ }
+
+ /* Allocate the buffer. */
+ p = ret = snewn(len, unsigned char);
+ if (length) *length = len;
+
+ PUT_32BIT(p, nkeys);
+ p += 4;
+ for (i = 0; NULL != (key = index234(rsakeys, i)); i++) {
+ blob = rsa_public_blob(key, &bloblen);
+ memcpy(p, blob, bloblen);
+ p += bloblen;
+ sfree(blob);
+ PUT_32BIT(p, strlen(key->comment));
+ memcpy(p + 4, key->comment, strlen(key->comment));
+ p += 4 + strlen(key->comment);