ObjFW  Diff

Differences From Artifact [d08f994c7d]:

To Artifact [45ee836bae]:


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

#include "config.h"

#import "OFData+ASN1DERParsing.h"
#import "OFASN1BitString.h"
#import "OFASN1Enumerated.h"
#import "OFASN1IA5String.h"
#import "OFASN1Integer.h"
#import "OFASN1NumericString.h"
#import "OFASN1ObjectIdentifier.h"
#import "OFASN1OctetString.h"
#import "OFASN1PrintableString.h"
#import "OFASN1UTF8String.h"
#import "OFASN1Value.h"
#import "OFArray.h"







<







15
16
17
18
19
20
21

22
23
24
25
26
27
28

#include "config.h"

#import "OFData+ASN1DERParsing.h"
#import "OFASN1BitString.h"
#import "OFASN1Enumerated.h"
#import "OFASN1IA5String.h"

#import "OFASN1NumericString.h"
#import "OFASN1ObjectIdentifier.h"
#import "OFASN1OctetString.h"
#import "OFASN1PrintableString.h"
#import "OFASN1UTF8String.h"
#import "OFASN1Value.h"
#import "OFArray.h"
39
40
41
42
43
44
45























46
47
48
49
50
51
52
enum {
	tagConstructedMask = 0x20
};

int _OFData_ASN1DERParsing_reference;

static size_t parseObject(OFData *self, id *object, size_t depthLimit);
























static OFArray *
parseSequence(OFData *contents, size_t depthLimit)
{
	OFMutableArray *ret = [OFMutableArray array];
	size_t count = contents.count;








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
enum {
	tagConstructedMask = 0x20
};

int _OFData_ASN1DERParsing_reference;

static size_t parseObject(OFData *self, id *object, size_t depthLimit);

long long
OFASN1DERIntegerParse(const unsigned char *buffer, size_t length)
{
	unsigned long long value = 0;

	/* TODO: Support for big numbers */
	if (length > sizeof(unsigned long long) &&
	    (length != sizeof(unsigned long long) + 1 || buffer[0] != 0))
		@throw [OFOutOfRangeException exception];

	if (length >= 2 && ((buffer[0] == 0 && !(buffer[1] & 0x80)) ||
	    (buffer[0] == 0xFF && buffer[1] & 0x80)))
		@throw [OFInvalidFormatException exception];

	if (length >= 1 && buffer[0] & 0x80)
		value = ~0ull;

	while (length--)
		value = (value << 8) | *buffer++;

	return value;
}

static OFArray *
parseSequence(OFData *contents, size_t depthLimit)
{
	OFMutableArray *ret = [OFMutableArray array];
	size_t count = contents.count;

172
173
174
175
176
177
178


179


180
181
182
183
184
185
186
187

		if (boolValue != 0 && boolValue != 0xFF)
			@throw [OFInvalidFormatException exception];

		*object = [OFNumber numberWithBool: boolValue];
		return bytesConsumed;
	case OFASN1TagNumberInteger:


		valueClass = [OFASN1Integer class];


		break;
	case OFASN1TagNumberBitString:
		valueClass = [OFASN1BitString class];
		break;
	case OFASN1TagNumberOctetString:
		valueClass = [OFASN1OctetString class];
		break;
	case OFASN1TagNumberNull:







>
>
|
>
>
|







194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213

		if (boolValue != 0 && boolValue != 0xFF)
			@throw [OFInvalidFormatException exception];

		*object = [OFNumber numberWithBool: boolValue];
		return bytesConsumed;
	case OFASN1TagNumberInteger:
		if (tag & tagConstructedMask)
			@throw [OFInvalidFormatException exception];

		*object = [OFNumber numberWithLongLong:
		    OFASN1DERIntegerParse(contents.items, contents.count)];
		return bytesConsumed;
	case OFASN1TagNumberBitString:
		valueClass = [OFASN1BitString class];
		break;
	case OFASN1TagNumberOctetString:
		valueClass = [OFASN1OctetString class];
		break;
	case OFASN1TagNumberNull: