@@ -24,38 +24,43 @@ #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" @implementation OFASN1NumericString @synthesize numericStringValue = _numericStringValue; + +- (instancetype)init +{ + OF_INVALID_INIT_METHOD +} - (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass tagNumber: (of_asn1_tag_number_t)tagNumber constructed: (bool)constructed DEREncodedContents: (OFData *)DEREncodedContents { - self = [super initWithTagClass: tagClass - tagNumber: tagNumber - constructed: constructed - DEREncodedContents: DEREncodedContents]; + self = [super init]; @try { - const unsigned char *items = [_DEREncodedContents items]; - size_t count = [_DEREncodedContents count]; + const unsigned char *items = [DEREncodedContents items]; + size_t count = [DEREncodedContents count]; + + if (tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL || + tagNumber != OF_ASN1_TAG_NUMBER_NUMERIC_STRING || + constructed) + @throw [OFInvalidArgumentException exception]; - if (_tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL || - _tagNumber != OF_ASN1_TAG_NUMBER_NUMERIC_STRING || - _constructed) + if ([DEREncodedContents itemSize] != 1) @throw [OFInvalidArgumentException exception]; for (size_t i = 0; i < count; i++) if (!of_ascii_isdigit(items[i]) && items[i] != ' ') @throw [OFInvalidEncodingException exception]; _numericStringValue = [[OFString alloc] - initWithCString: [_DEREncodedContents items] + initWithCString: [DEREncodedContents items] encoding: OF_STRING_ENCODING_ASCII - length: [_DEREncodedContents count]]; + length: [DEREncodedContents count]]; } @catch (id e) { [self release]; @throw e; } @@ -71,12 +76,32 @@ - (OFString *)stringValue { return [self numericStringValue]; } + +- (bool)isEqual: (id)object +{ + OFASN1NumericString *numericString; + + if (![object isKindOfClass: [OFASN1NumericString class]]) + return false; + + numericString = object; + + if (![numericString->_numericStringValue isEqual: _numericStringValue]) + return false; + + return true; +} + +- (uint32_t)hash +{ + return [_numericStringValue hash]; +} - (OFString *)description { return [OFString stringWithFormat: @"", _numericStringValue]; } @end