@@ -22,39 +22,70 @@ #import "OFString.h" #import "OFInvalidArgumentException.h" @implementation OFASN1OctetString +@synthesize octetStringValue = _octetStringValue; + +- (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 { - if (_tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL || - _tagNumber != OF_ASN1_TAG_NUMBER_OCTET_STRING || - _constructed) + if (tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL || + tagNumber != OF_ASN1_TAG_NUMBER_OCTET_STRING || + constructed) + @throw [OFInvalidArgumentException exception]; + + if ([DEREncodedContents itemSize] != 1) @throw [OFInvalidArgumentException exception]; + + _octetStringValue = [DEREncodedContents copy]; } @catch (id e) { [self release]; @throw e; } return self; } -- (OFData *)octetStringValue +- (void)dealloc +{ + [_octetStringValue release]; + + [super dealloc]; +} + +- (bool)isEqual: (id)object +{ + OFASN1OctetString *octetString; + + if (![object isKindOfClass: [OFASN1OctetString class]]) + return false; + + octetString = object; + + if (![octetString->_octetStringValue isEqual: _octetStringValue]) + return false; + + return true; +} + +- (uint32_t)hash { - return _DEREncodedContents; + return [_octetStringValue hash]; } - (OFString *)description { return [OFString stringWithFormat: @"", - _DEREncodedContents]; + _octetStringValue]; } @end