smp: Make code that encodes identities more readable

In particular for static code analyzers.  The previous nesting of case
statements inside of a while loop that's inside a switch statement and
a wrapping block with declaration was quite weird and Coverity didn't
like it (it figured that `type` was uninitialized even when it assumed
that get_type() returned a known type for which a case statement
existed).
This commit is contained in:
Tobias Brunner 2024-03-14 13:51:06 +01:00
parent 91f209b878
commit c035e4ca93

View File

@ -76,14 +76,12 @@ static void write_bool(xmlTextWriterPtr writer, char *element, bool val)
*/
static void write_id(xmlTextWriterPtr writer, char *element, identification_t *id)
{
char *type = NULL;
xmlTextWriterStartElement(writer, element);
switch (id->get_type(id))
{
{
char *type;
while (TRUE)
{
case ID_ANY:
type = "any";
break;
@ -105,15 +103,18 @@ static void write_id(xmlTextWriterPtr writer, char *element, identification_t *i
case ID_DER_ASN1_GN:
type = "asn1gn";
break;
default:
break;
}
if (type)
{
xmlTextWriterWriteAttribute(writer, "type", type);
xmlTextWriterWriteFormatString(writer, "%Y", id);
break;
}
default:
else
{
/* TODO: base64 keyid */
xmlTextWriterWriteAttribute(writer, "type", "keyid");
break;
}
xmlTextWriterEndElement(writer);
}