[winpr,asn1] fix writing integers

ASN1 integers are signed.
This commit is contained in:
akallabeth 2024-10-30 16:55:56 +01:00
parent dc76879e0b
commit d232037e18
No known key found for this signature in database
GPG Key ID: A49454A3FC909FD5

View File

@ -538,11 +538,10 @@ static size_t asn1IntegerLen(WinPrAsn1_INTEGER value)
static size_t WinPrAsn1EncIntegerLike(WinPrAsn1Encoder* enc, WinPrAsn1_tag b,
WinPrAsn1_INTEGER value)
{
wStream staticS;
wStream staticS = { 0 };
wStream* s = &staticS;
size_t len = 0;
len = asn1IntegerLen(value);
const size_t len = asn1IntegerLen(value);
if (!asn1_getWriteStream(enc, 1 + len, s))
return 0;
@ -551,15 +550,15 @@ static size_t WinPrAsn1EncIntegerLike(WinPrAsn1Encoder* enc, WinPrAsn1_tag b,
{
case 2:
Stream_Write_UINT8(s, 1);
Stream_Write_UINT8(s, value);
Stream_Write_INT8(s, value);
break;
case 3:
Stream_Write_UINT8(s, 2);
Stream_Write_UINT16_BE(s, value);
Stream_Write_INT16_BE(s, value);
break;
case 5:
Stream_Write_UINT8(s, 4);
Stream_Write_UINT32_BE(s, value);
Stream_Write_INT32_BE(s, value);
break;
}
return 1 + len;
@ -578,17 +577,14 @@ size_t WinPrAsn1EncEnumerated(WinPrAsn1Encoder* enc, WinPrAsn1_ENUMERATED value)
static size_t WinPrAsn1EncContextualIntegerLike(WinPrAsn1Encoder* enc, WinPrAsn1_tag tag,
WinPrAsn1_tagId tagId, WinPrAsn1_INTEGER value)
{
wStream staticS;
wStream staticS = { 0 };
wStream* s = &staticS;
size_t len = 0;
size_t outLen = 0;
WINPR_ASSERT(enc);
WINPR_ASSERT_VALID_TAG(tagId);
len = asn1IntegerLen(value);
outLen = 1 + lenBytes(1 + len) + (1 + len);
const size_t len = asn1IntegerLen(value);
const size_t outLen = 1 + lenBytes(1 + len) + (1 + len);
if (!asn1_getWriteStream(enc, outLen, s))
return 0;
@ -600,15 +596,15 @@ static size_t WinPrAsn1EncContextualIntegerLike(WinPrAsn1Encoder* enc, WinPrAsn1
{
case 2:
Stream_Write_UINT8(s, 1);
Stream_Write_UINT8(s, value);
Stream_Write_INT8(s, value);
break;
case 3:
Stream_Write_UINT8(s, 2);
Stream_Write_UINT16_BE(s, value);
Stream_Write_INT16_BE(s, value);
break;
case 5:
Stream_Write_UINT8(s, 4);
Stream_Write_UINT32_BE(s, value);
Stream_Write_INT32_BE(s, value);
break;
}
return outLen;