@@ -21,44 +21,58 @@ #import "OFData.h" #import "OFString.h" #import "OFInvalidArgumentException.h" -extern intmax_t of_asn1_integer_parse(const unsigned char *buffer, +extern intmax_t of_asn1_der_integer_parse(const unsigned char *buffer, size_t length); @implementation OFASN1Enumerated @synthesize integerValue = _integerValue; -- (instancetype)init ++ (instancetype)enumeratedWithIntegerValue: (intmax_t)integerValue +{ + return [[[self alloc] initWithIntegerValue: integerValue] autorelease]; +} + +- (instancetype)initWithIntegerValue: (intmax_t)integerValue { - OF_INVALID_INIT_METHOD + self = [super init]; + + _integerValue = integerValue; + + return self; } - (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass tagNumber: (of_asn1_tag_number_t)tagNumber constructed: (bool)constructed DEREncodedContents: (OFData *)DEREncodedContents { - self = [super init]; + intmax_t integerValue; @try { if (tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL || tagNumber != OF_ASN1_TAG_NUMBER_ENUMERATED || constructed) @throw [OFInvalidArgumentException exception]; if ([DEREncodedContents itemSize] != 1) @throw [OFInvalidArgumentException exception]; - _integerValue = of_asn1_integer_parse( + integerValue = of_asn1_der_integer_parse( [DEREncodedContents items], [DEREncodedContents count]); } @catch (id e) { [self release]; @throw e; } - return self; + return [self initWithIntegerValue: integerValue]; +} + +- (instancetype)init +{ + OF_INVALID_INIT_METHOD } - (bool)isEqual: (id)object { OFASN1Enumerated *enumerated;