OpenPGP: cleanup pgp_build_tlv()

- get rid of intermediate variable
- clarify check in while() loop
- line breaks for easier reading
This commit is contained in:
Peter Marschall 2015-09-19 18:14:44 +02:00
parent 3d492ae376
commit 2a269c5267
1 changed files with 8 additions and 8 deletions

View File

@ -2169,22 +2169,22 @@ static int
pgp_build_tlv(sc_context_t *ctx, unsigned int tag, u8 *data, size_t len, u8 **out, size_t *outlen)
{
u8 highest_order = 0;
u8 cla;
int r;
r = sc_asn1_write_element(ctx, tag, data, len, out, outlen);
LOG_TEST_RET(ctx, r, "Failed to write ASN.1 element");
/* Restore class bits stripped by sc_asn1_write_element */
/* determine the leftmost byte of tag, which contains class bits */
while (tag >> 8*highest_order) {
while ((tag >> 8*highest_order) != 0) {
highest_order++;
}
highest_order--;
if (highest_order >= 4)
cla = 0x00;
else
cla = tag >> 8*highest_order;
/* restore class bits */
*out[0] |= cla;
/* restore class bits in output */
if (highest_order < 4)
*out[0] |= (tag >> 8*highest_order);
return SC_SUCCESS;
}