mirror of
https://github.com/strongswan/strongswan.git
synced 2025-10-03 00:00:24 -04:00
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:
parent
91f209b878
commit
c035e4ca93
@ -76,45 +76,46 @@ static void write_bool(xmlTextWriterPtr writer, char *element, bool val)
|
|||||||
*/
|
*/
|
||||||
static void write_id(xmlTextWriterPtr writer, char *element, identification_t *id)
|
static void write_id(xmlTextWriterPtr writer, char *element, identification_t *id)
|
||||||
{
|
{
|
||||||
|
char *type = NULL;
|
||||||
|
|
||||||
xmlTextWriterStartElement(writer, element);
|
xmlTextWriterStartElement(writer, element);
|
||||||
switch (id->get_type(id))
|
switch (id->get_type(id))
|
||||||
{
|
{
|
||||||
{
|
|
||||||
char *type;
|
|
||||||
|
|
||||||
while (TRUE)
|
case ID_ANY:
|
||||||
{
|
type = "any";
|
||||||
case ID_ANY:
|
break;
|
||||||
type = "any";
|
case ID_IPV4_ADDR:
|
||||||
break;
|
type = "ipv4";
|
||||||
case ID_IPV4_ADDR:
|
break;
|
||||||
type = "ipv4";
|
case ID_IPV6_ADDR:
|
||||||
break;
|
type = "ipv6";
|
||||||
case ID_IPV6_ADDR:
|
break;
|
||||||
type = "ipv6";
|
case ID_FQDN:
|
||||||
break;
|
type = "fqdn";
|
||||||
case ID_FQDN:
|
break;
|
||||||
type = "fqdn";
|
case ID_RFC822_ADDR:
|
||||||
break;
|
type = "email";
|
||||||
case ID_RFC822_ADDR:
|
break;
|
||||||
type = "email";
|
case ID_DER_ASN1_DN:
|
||||||
break;
|
type = "asn1dn";
|
||||||
case ID_DER_ASN1_DN:
|
break;
|
||||||
type = "asn1dn";
|
case ID_DER_ASN1_GN:
|
||||||
break;
|
type = "asn1gn";
|
||||||
case ID_DER_ASN1_GN:
|
|
||||||
type = "asn1gn";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
xmlTextWriterWriteAttribute(writer, "type", type);
|
|
||||||
xmlTextWriterWriteFormatString(writer, "%Y", id);
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
/* TODO: base64 keyid */
|
|
||||||
xmlTextWriterWriteAttribute(writer, "type", "keyid");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (type)
|
||||||
|
{
|
||||||
|
xmlTextWriterWriteAttribute(writer, "type", type);
|
||||||
|
xmlTextWriterWriteFormatString(writer, "%Y", id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* TODO: base64 keyid */
|
||||||
|
xmlTextWriterWriteAttribute(writer, "type", "keyid");
|
||||||
|
}
|
||||||
xmlTextWriterEndElement(writer);
|
xmlTextWriterEndElement(writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user