20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#import "OFString.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFOutOfRangeException.h"
long long
of_asn1_der_integer_parse(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];
|
|
|
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#import "OFString.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFOutOfRangeException.h"
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];
|
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
self = [super init];
_longLongValue = value;
return self;
}
- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass
tagNumber: (of_asn1_tag_number_t)tagNumber
constructed: (bool)constructed
DEREncodedContents: (OFData *)DEREncodedContents
{
long long value;
@try {
if (tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL ||
tagNumber != OF_ASN1_TAG_NUMBER_INTEGER || constructed)
@throw [OFInvalidArgumentException exception];
if (DEREncodedContents.itemSize != 1)
@throw [OFInvalidArgumentException exception];
value = of_asn1_der_integer_parse(
DEREncodedContents.items, DEREncodedContents.count);
} @catch (id e) {
[self release];
@throw e;
}
return [self initWithLongLong: value];
|
|
|
|
|
|
|
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
self = [super init];
_longLongValue = value;
return self;
}
- (instancetype)initWithTagClass: (OFASN1TagClass)tagClass
tagNumber: (OFASN1TagNumber)tagNumber
constructed: (bool)constructed
DEREncodedContents: (OFData *)DEREncodedContents
{
long long value;
@try {
if (tagClass != OFASN1TagClassUniversal ||
tagNumber != OFASN1TagNumberInteger || constructed)
@throw [OFInvalidArgumentException exception];
if (DEREncodedContents.itemSize != 1)
@throw [OFInvalidArgumentException exception];
value = OFASN1DERIntegerParse(
DEREncodedContents.items, DEREncodedContents.count);
} @catch (id e) {
[self release];
@throw e;
}
return [self initWithLongLong: value];
|