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:
parent
3d492ae376
commit
2a269c5267
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue