{
int i, subkeys;
int err;
- char dn[1024];
- size_t dn_size;
print_key_revoked (str, cert, -1);
i = 0;
do
{
- dn_size = sizeof (dn);
- err = gnutls_openpgp_crt_get_name (cert, i++, dn, &dn_size);
-
- if (err < 0 && err != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE &&
- err != GNUTLS_E_OPENPGP_UID_REVOKED)
- {
- addf (str, "error: get_name: %s %d\n", gnutls_strerror (err), err);
- break;
- }
-
- if (err >= 0)
- addf (str, _("\tName[%d]: %s\n"), i - 1, dn);
- else if (err == GNUTLS_E_OPENPGP_UID_REVOKED)
+ char *dn;
+ size_t dn_size = 0;
+
+ err = gnutls_openpgp_crt_get_name (cert, i, NULL, &dn_size);
+ if (err != GNUTLS_E_SHORT_MEMORY_BUFFER
+ && err != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
+ && err != GNUTLS_E_OPENPGP_UID_REVOKED)
+ addf (str, "error: get_name: %s\n", gnutls_strerror (err));
+ else
{
- addf (str, _("\tRevoked Name[%d]: %s\n"), i - 1, dn);
+ dn = gnutls_malloc (dn_size);
+ if (!dn)
+ addf (str, "error: malloc (%d): %s\n", (int) dn_size,
+ gnutls_strerror (GNUTLS_E_MEMORY_ERROR));
+ else
+ {
+ err = gnutls_openpgp_crt_get_name (cert, i, dn, &dn_size);
+ if (err < 0 && err != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE &&
+ err != GNUTLS_E_OPENPGP_UID_REVOKED)
+ addf (str, "error: get_name: %s\n", gnutls_strerror (err));
+ else if (err >= 0)
+ addf (str, _("\tName[%d]: %s\n"), i, dn);
+ else if (err == GNUTLS_E_OPENPGP_UID_REVOKED)
+ addf (str, _("\tRevoked Name[%d]: %s\n"), i, dn);
+
+ gnutls_free (dn);
+ }
}
+ i++;
}
while (err >= 0);
{
int err, i;
- /* Names. */
i = 0;
do
{
- size_t dn_size;
- char dn[1024];
-
- dn_size = sizeof (dn);
- err = gnutls_openpgp_crt_get_name (cert, i++, dn, &dn_size);
- if (err < 0 && err != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE &&
- err != GNUTLS_E_OPENPGP_UID_REVOKED)
+ char *dn;
+ size_t dn_size = 0;
+
+ err = gnutls_openpgp_crt_get_name (cert, i, NULL, &dn_size);
+ if (err != GNUTLS_E_SHORT_MEMORY_BUFFER
+ && err != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
+ && err != GNUTLS_E_OPENPGP_UID_REVOKED)
+ addf (str, "unknown name (%s), ", gnutls_strerror (err));
+ else
{
- addf (str, "cannot get_name %d (%s), ", err, gnutls_strerror (err));
- break;
+ dn = gnutls_malloc (dn_size);
+ if (!dn)
+ addf (str, "unknown name (%s), ",
+ gnutls_strerror (GNUTLS_E_MEMORY_ERROR));
+ else
+ {
+ err = gnutls_openpgp_crt_get_name (cert, i, dn, &dn_size);
+ if (err < 0 && err != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE &&
+ err != GNUTLS_E_OPENPGP_UID_REVOKED)
+ addf (str, "unknown name (%s), ", gnutls_strerror (err));
+ else if (err >= 0)
+ addf (str, _("name[%d]: %s, "), i, dn);
+ else if (err == GNUTLS_E_OPENPGP_UID_REVOKED)
+ addf (str, _("revoked name[%d]: %s, "), i, dn);
+
+ gnutls_free (dn);
+ }
}
- if (err >= 0)
- addf (str, _("name[%d]: %s, "), i - 1, dn);
- else if (err == GNUTLS_E_OPENPGP_UID_REVOKED)
- addf (str, _("revoked name[%d]: %s, "), i - 1, dn);
+ i++;
}
while (err >= 0);
* gnutls_openpgp_crt_get_name - Extracts the userID
* @key: the structure that contains the OpenPGP public key.
* @idx: the index of the ID to extract
- * @buf: a pointer to a structure to hold the name
+ * @buf: a pointer to a structure to hold the name, may be %NULL
+ * to only get the @sizeof_buf.
* @sizeof_buf: holds the maximum size of @buf, on return hold the
* actual/required size of @buf.
*
cdk_pkt_userid_t uid = NULL;
int pos = 0;
- if (!key || !buf)
+ if (!key)
{
gnutls_assert ();
return GNUTLS_E_INVALID_REQUEST;
return GNUTLS_E_SHORT_MEMORY_BUFFER;
}
- memcpy (buf, uid->name, uid->len);
- buf[uid->len] = '\0'; /* make sure it's a string */
+ if (buf)
+ {
+ memcpy (buf, uid->name, uid->len);
+ buf[uid->len] = '\0'; /* make sure it's a string */
+ }
*sizeof_buf = uid->len + 1;
if (uid->is_revoked)