Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -8,11 +8,12 @@ STATIC_LIB = ${OBJFW_STATIC_LIB} FRAMEWORK = ${OBJFW_FRAMEWORK} LIB_MAJOR = ${OBJFW_LIB_MAJOR} LIB_MINOR = ${OBJFW_LIB_MINOR} -SRCS = OFASN1Boolean.m \ +SRCS = OFASN1BitString.m \ + OFASN1Boolean.m \ OFASN1IA5String.m \ OFASN1Integer.m \ OFASN1Null.m \ OFASN1OctetString.m \ OFASN1UTF8String.m \ ADDED src/OFASN1BitString.h Index: src/OFASN1BitString.h ================================================================== --- src/OFASN1BitString.h +++ src/OFASN1BitString.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#import "OFASN1Value.h" + +OF_ASSUME_NONNULL_BEGIN + +@class OFData; + +/*! + * @brief An ASN.1 bit string. + */ +@interface OFASN1BitString: OFASN1Value +{ + OFData *_bitStringValue; + size_t _bitStringLength; +} + +/*! + * @brief The bit string value. + */ +@property (readonly, nonatomic) OFData *bitStringValue; + +/*! + * @brief The length of the bit string in bits. + */ +@property (readonly, nonatomic) size_t bitStringLength; +@end + +OF_ASSUME_NONNULL_END ADDED src/OFASN1BitString.m Index: src/OFASN1BitString.m ================================================================== --- src/OFASN1BitString.m +++ src/OFASN1BitString.m @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFASN1BitString.h" +#import "OFData.h" +#import "OFString.h" + +#import "OFInvalidArgumentException.h" +#import "OFInvalidFormatException.h" +#import "OFOutOfRangeException.h" + +@implementation OFASN1BitString +@synthesize bitStringValue = _bitStringValue; +@synthesize bitStringLength = _bitStringLength; + +- (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]; + + @try { + void *pool = objc_autoreleasePoolPush(); + unsigned char lastByteBits; + size_t count = [_DEREncodedContents count]; + + if (_tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL || + _tagNumber != OF_ASN1_TAG_NUMBER_BIT_STRING || + _constructed) + @throw [OFInvalidArgumentException exception]; + + if (count == 0) + @throw [OFInvalidFormatException exception]; + + lastByteBits = + *(unsigned char *)[_DEREncodedContents itemAtIndex: 0]; + + if (count == 1 && lastByteBits != 0) + @throw [OFInvalidFormatException exception]; + + if (SIZE_MAX / 8 < count - 1 || + SIZE_MAX - (count - 1) * 8 < lastByteBits) + @throw [OFOutOfRangeException exception]; + + _bitStringLength = (count - 1) * 8 + lastByteBits; + _bitStringValue = [[_DEREncodedContents + subdataWithRange: of_range(1, count - 1)] copy]; + + objc_autoreleasePoolPop(pool); + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [_bitStringValue release]; + + [super dealloc]; +} + +- (OFString *)description +{ + return [OFString stringWithFormat: @"", + _bitStringValue, _bitStringLength]; +} +@end Index: src/OFASN1Value.h ================================================================== --- src/OFASN1Value.h +++ src/OFASN1Value.h @@ -43,10 +43,12 @@ typedef enum { /*! Boolean */ OF_ASN1_TAG_NUMBER_BOOLEAN = 0x01, /*! Integer */ OF_ASN1_TAG_NUMBER_INTEGER = 0x02, + /*! Bit string */ + OF_ASN1_TAG_NUMBER_BIT_STRING = 0x03, /*! Octet string */ OF_ASN1_TAG_NUMBER_OCTET_STRING = 0x04, /*! Null */ OF_ASN1_TAG_NUMBER_NULL = 0x05, /*! UTF-8 string */ Index: src/OFData+ASN1DERValue.m ================================================================== --- src/OFData+ASN1DERValue.m +++ src/OFData+ASN1DERValue.m @@ -16,10 +16,11 @@ */ #include "config.h" #import "OFData+ASN1DERValue.h" +#import "OFASN1BitString.h" #import "OFASN1Boolean.h" #import "OFASN1IA5String.h" #import "OFASN1Integer.h" #import "OFASN1Null.h" #import "OFASN1OctetString.h" @@ -121,10 +122,13 @@ valueClass = [OFASN1Boolean class]; break; case OF_ASN1_TAG_NUMBER_INTEGER: valueClass = [OFASN1Integer class]; break; + case OF_ASN1_TAG_NUMBER_BIT_STRING: + valueClass = [OFASN1BitString class]; + break; case OF_ASN1_TAG_NUMBER_OCTET_STRING: valueClass = [OFASN1OctetString class]; break; case OF_ASN1_TAG_NUMBER_NULL: valueClass = [OFASN1Null class]; Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -8,15 +8,15 @@ ${PROG_NOINST}.nds PROG_NOINST = tests${PROG_SUFFIX} STATIC_LIB_NOINST = ${TESTS_STATIC_LIB} SRCS = ForwardingTests.m \ + OFASN1DERValueTests.m \ OFArrayTests.m \ ${OFBLOCKTESTS_M} \ OFCharacterSetTests.m \ OFDataTests.m \ - OFDataASN1DERValueTests.m \ OFDateTests.m \ OFDictionaryTests.m \ OFInvocationTests.m \ OFJSONTests.m \ OFListTests.m \ ADDED tests/OFASN1DERValueTests.m Index: tests/OFASN1DERValueTests.m ================================================================== --- tests/OFASN1DERValueTests.m +++ tests/OFASN1DERValueTests.m @@ -0,0 +1,275 @@ +/* + * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, + * 2018 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "OFData.h" +#import "OFASN1BitString.h" +#import "OFASN1Boolean.h" +#import "OFASN1IA5String.h" +#import "OFASN1Integer.h" +#import "OFASN1Null.h" +#import "OFASN1OctetString.h" +#import "OFASN1UTF8String.h" +#import "OFArray.h" +#import "OFString.h" +#import "OFAutoreleasePool.h" + +#import "TestsAppDelegate.h" + +#import "OFInvalidEncodingException.h" +#import "OFInvalidFormatException.h" +#import "OFOutOfRangeException.h" +#import "OFTruncatedDataException.h" + +static OFString *module = @"OFData+ASN1DERValue"; + +@implementation TestsAppDelegate (OFASN1DERValueTests) +- (void)ASN1DERValueTests +{ + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFASN1BitString *bitString; + OFArray *array; + + TEST(@"Parsing of boolean", + ![[[OFData dataWithItems: "\x01\x01\x00" + count: 3] ASN1DERValue] booleanValue] && + [[[OFData dataWithItems: "\x01\x01\xFF" + count: 3] ASN1DERValue] booleanValue]) + + EXPECT_EXCEPTION(@"Detection of invalid boolean #1", + OFInvalidFormatException, [[OFData dataWithItems: "\x01\x01\x01" + count: 3] ASN1DERValue]) + + EXPECT_EXCEPTION(@"Detection of invalid boolean #2", + OFInvalidFormatException, [[OFData dataWithItems: "\x01\x02\x00\x00" + count: 4] ASN1DERValue]) + + EXPECT_EXCEPTION(@"Detection of invalid boolean #3", + OFInvalidFormatException, [[OFData dataWithItems: "\x01\x00" + count: 2] ASN1DERValue]) + + EXPECT_EXCEPTION(@"Detection of truncated boolean", + OFTruncatedDataException, [[OFData dataWithItems: "\x01\x01" + count: 2] ASN1DERValue]) + + TEST(@"Parsing of integer", + [[[OFData dataWithItems: "\x02\x00" + count: 2] ASN1DERValue] integerValue] == 0 && + [[[OFData dataWithItems: "\x02\x01\x01" + count: 3] ASN1DERValue] integerValue] == 1 && + [[[OFData dataWithItems: "\x02\x02\x01\x04" + count: 4] ASN1DERValue] integerValue] == 260 && + [[[OFData dataWithItems: "\x02\x01\xFF" + count: 3] ASN1DERValue] integerValue] == -1 && + [[[OFData dataWithItems: "\x02\x03\xFF\x00\x00" + count: 5] ASN1DERValue] integerValue] == -65536 && + (uintmax_t)[[[OFData dataWithItems: "\x02\x09\x00\xFF\xFF\xFF\xFF" + "\xFF\xFF\xFF\xFF" + count: 11] ASN1DERValue] + integerValue] == UINTMAX_MAX) + + EXPECT_EXCEPTION(@"Detecting of invalid integer #1", + OFInvalidFormatException, [[OFData dataWithItems: "\x02\x02\x00\x00" + count: 4] ASN1DERValue]) + + EXPECT_EXCEPTION(@"Detecting of invalid integer #2", + OFInvalidFormatException, [[OFData dataWithItems: "\x02\x02\x00\x7F" + count: 4] ASN1DERValue]) + + EXPECT_EXCEPTION(@"Detecting of invalid integer #3", + OFInvalidFormatException, [[OFData dataWithItems: "\x02\x02\xFF\x80" + count: 4] ASN1DERValue]) + + EXPECT_EXCEPTION(@"Detection of out of range integer", + OFOutOfRangeException, + [[OFData dataWithItems: "\x02\x09\x01" + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" + count: 11] ASN1DERValue]) + + EXPECT_EXCEPTION(@"Detection of truncated integer", + OFTruncatedDataException, [[OFData dataWithItems: "\x02\x02\x00" + count: 3] ASN1DERValue]) + + TEST(@"Parsing of bit string", + (bitString = [[OFData dataWithItems: "\x03\x01\x00" + count: 3] ASN1DERValue]) && + [[bitString bitStringValue] isEqual: [OFData dataWithItems: "" + count: 0]] && + [bitString bitStringLength] == 0 && + (bitString = [[OFData dataWithItems: "\x03\x0D\x01Hello World\x80" + count: 15] ASN1DERValue]) && + [[bitString bitStringValue] + isEqual: [OFData dataWithItems: "Hello World\x80" + count: 12]] && + [bitString bitStringLength] == 97 && + (bitString = [[OFData dataWithItems: "\x03\x81\x80\x00xxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxx" + count: 131] ASN1DERValue]) && + [[bitString bitStringValue] + isEqual: [OFData dataWithItems: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxx" + count: 127]] && + [bitString bitStringLength] == 127 * 8) + + EXPECT_EXCEPTION(@"Detection of invalid bit string #1", + OFInvalidFormatException, [[OFData dataWithItems: "\x03\x00" + count: 2] ASN1DERValue]) + + EXPECT_EXCEPTION(@"Detection of invalid bit string #2", + OFInvalidFormatException, [[OFData dataWithItems: "\x03\x01\x01" + count: 3] ASN1DERValue]) + + EXPECT_EXCEPTION(@"Detection of out of range bit string", + OFOutOfRangeException, + [[OFData dataWithItems: "\x03\x89" + "\x01\x01\x01\x01\x01\x01\x01\x01\x01" + count: 11] ASN1DERValue]) + + EXPECT_EXCEPTION(@"Detection of truncated bit string", + OFTruncatedDataException, [[OFData dataWithItems: "\x03\x01" + count: 2] ASN1DERValue]) + + TEST(@"Parsing of octet string", + [[[[OFData dataWithItems: "\x04\x0CHello World!" + count: 14] ASN1DERValue] octetStringValue] + isEqual: [OFData dataWithItems: "Hello World!" + count: 12]] && + [[[[OFData dataWithItems: "\x04\x81\x80xxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxx" + count: 131] ASN1DERValue] octetStringValue] + isEqual: [OFData dataWithItems: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxx" + count: 128]]) + + EXPECT_EXCEPTION(@"Detection of out of range octet string", + OFOutOfRangeException, + [[OFData dataWithItems: "\x04\x89" + "\x01\x01\x01\x01\x01\x01\x01\x01\x01" + count: 11] ASN1DERValue]) + + EXPECT_EXCEPTION(@"Detection of truncated octet string", + OFTruncatedDataException, [[OFData dataWithItems: "\x04\x01" + count: 2] ASN1DERValue]) + + TEST(@"Parsing of NULL", + [[[OFData dataWithItems: "\x05\x00" + count: 2] ASN1DERValue] + isKindOfClass: [OFASN1Null class]]) + + EXPECT_EXCEPTION(@"Detection of invalid NULL", + OFInvalidFormatException, [[OFData dataWithItems: "\x05\x01\x00" + count: 3] ASN1DERValue]) + + TEST(@"Parsing of UTF-8 string", + [[[[OFData dataWithItems: "\x0C\x0EHällo Wörld!" + count: 16] ASN1DERValue] UTF8StringValue] + isEqual: @"Hällo Wörld!"] && + [[[[OFData dataWithItems: "\x0C\x81\x80xxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxx" + count: 131] ASN1DERValue] UTF8StringValue] + isEqual: @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + @"xxxxxxxxxxxxxxxx"]) + + EXPECT_EXCEPTION(@"Detection of out of range UTF-8 string", + OFOutOfRangeException, + [[OFData dataWithItems: "\x0C\x89" + "\x01\x01\x01\x01\x01\x01\x01\x01\x01" + count: 11] ASN1DERValue]) + + EXPECT_EXCEPTION(@"Detection of truncated UTF-8 string", + OFTruncatedDataException, [[OFData dataWithItems: "\x0C\x01" + count: 2] ASN1DERValue]) + + EXPECT_EXCEPTION(@"Detection of truncated length", + OFTruncatedDataException, [[OFData dataWithItems: "\x0C\x83\x01\x01" + count: 4] ASN1DERValue]) + + EXPECT_EXCEPTION(@"Detection of invalid / inefficient length #1", + OFInvalidFormatException, [[OFData dataWithItems: "\x0C\x81\x7F" + count: 3] ASN1DERValue]) + + EXPECT_EXCEPTION(@"Detection of invalid / inefficient length #2", + OFInvalidFormatException, + [[OFData dataWithItems: "\x0C\x82\x00\x80xxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxx" + count: 132] ASN1DERValue]) + + TEST(@"Parsing of sequence", + (array = [[OFData dataWithItems: "\x30\x00" + count: 2] ASN1DERValue]) && + [array isKindOfClass: [OFArray class]] && [array count] == 0 && + (array = [[OFData dataWithItems: "\x30\x09\x02\x01\x7B\x0C\x04Test" + count: 11] ASN1DERValue]) && + [array isKindOfClass: [OFArray class]] && [array count] == 2 && + [[array objectAtIndex: 0] integerValue] == 123 && + [[[array objectAtIndex: 1] stringValue] isEqual: @"Test"]) + + EXPECT_EXCEPTION(@"Parsing of truncated sequence #1", + OFTruncatedDataException, [[OFData dataWithItems: "\x30\x01" + count: 2] ASN1DERValue]) + + EXPECT_EXCEPTION(@"Parsing of truncated sequence #2", + OFTruncatedDataException, + [[OFData dataWithItems: "\x30\x04\x02\x01\x01\x00\x00" + count: 7] ASN1DERValue]) + + TEST(@"Parsing of IA5String", + [[[[OFData dataWithItems: "\x16\x0CHello World!" + count: 14] ASN1DERValue] IA5StringValue] + isEqual: @"Hello World!"] && + [[[[OFData dataWithItems: "\x16\x81\x80xxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxx" + count: 131] ASN1DERValue] IA5StringValue] + isEqual: @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + @"xxxxxxxxxxxxxxxx"]) + + EXPECT_EXCEPTION(@"Detection of invalid IA5String", + OFInvalidEncodingException, + [[OFData dataWithItems: "\x16\x02ä" + count: 4] ASN1DERValue]) + + EXPECT_EXCEPTION(@"Detection of out of range IA5String", + OFOutOfRangeException, + [[OFData dataWithItems: "\x16\x89" + "\x01\x01\x01\x01\x01\x01\x01\x01\x01" + count: 11] ASN1DERValue]) + + EXPECT_EXCEPTION(@"Detection of truncated IA5String", + OFTruncatedDataException, [[OFData dataWithItems: "\x16\x01" + count: 2] ASN1DERValue]) + + [pool drain]; +} +@end DELETED tests/OFDataASN1DERValueTests.m Index: tests/OFDataASN1DERValueTests.m ================================================================== --- tests/OFDataASN1DERValueTests.m +++ tests/OFDataASN1DERValueTests.m @@ -1,229 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "OFData.h" -#import "OFASN1Boolean.h" -#import "OFASN1IA5String.h" -#import "OFASN1Integer.h" -#import "OFASN1Null.h" -#import "OFASN1OctetString.h" -#import "OFASN1UTF8String.h" -#import "OFArray.h" -#import "OFString.h" -#import "OFAutoreleasePool.h" - -#import "TestsAppDelegate.h" - -#import "OFInvalidEncodingException.h" -#import "OFInvalidFormatException.h" -#import "OFOutOfRangeException.h" -#import "OFTruncatedDataException.h" - -static OFString *module = @"OFData+ASN1DERValue"; - -@implementation TestsAppDelegate (OFDataASN1DERValueTests) -- (void)dataASN1DERValueTests -{ - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFArray *array; - - TEST(@"Parsing of boolean", - ![[[OFData dataWithItems: "\x01\x01\x00" - count: 3] ASN1DERValue] booleanValue] && - [[[OFData dataWithItems: "\x01\x01\xFF" - count: 3] ASN1DERValue] booleanValue]) - - EXPECT_EXCEPTION(@"Detection of invalid boolean #1", - OFInvalidFormatException, [[OFData dataWithItems: "\x01\x01\x01" - count: 3] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of invalid boolean #2", - OFInvalidFormatException, [[OFData dataWithItems: "\x01\x02\x00\x00" - count: 4] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of invalid boolean #3", - OFInvalidFormatException, [[OFData dataWithItems: "\x01\x00" - count: 2] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of truncated boolean", - OFTruncatedDataException, [[OFData dataWithItems: "\x01\x01" - count: 2] ASN1DERValue]) - - TEST(@"Parsing of integer", - [[[OFData dataWithItems: "\x02\x00" - count: 2] ASN1DERValue] integerValue] == 0 && - [[[OFData dataWithItems: "\x02\x01\x01" - count: 3] ASN1DERValue] integerValue] == 1 && - [[[OFData dataWithItems: "\x02\x02\x01\x04" - count: 4] ASN1DERValue] integerValue] == 260 && - [[[OFData dataWithItems: "\x02\x01\xFF" - count: 3] ASN1DERValue] integerValue] == -1 && - [[[OFData dataWithItems: "\x02\x03\xFF\x00\x00" - count: 5] ASN1DERValue] integerValue] == -65536 && - (uintmax_t)[[[OFData dataWithItems: "\x02\x09\x00\xFF\xFF\xFF\xFF" - "\xFF\xFF\xFF\xFF" - count: 11] ASN1DERValue] - integerValue] == UINTMAX_MAX) - - EXPECT_EXCEPTION(@"Detecting of invalid integer #1", - OFInvalidFormatException, [[OFData dataWithItems: "\x02\x02\x00\x00" - count: 4] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detecting of invalid integer #2", - OFInvalidFormatException, [[OFData dataWithItems: "\x02\x02\x00\x7F" - count: 4] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detecting of invalid integer #3", - OFInvalidFormatException, [[OFData dataWithItems: "\x02\x02\xFF\x80" - count: 4] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of out of range integer", - OFOutOfRangeException, - [[OFData dataWithItems: "\x02\x09\x01" - "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" - count: 11] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of truncated integer", - OFTruncatedDataException, [[OFData dataWithItems: "\x02\x02\x00" - count: 3] ASN1DERValue]) - - TEST(@"Parsing of octet string", - [[[[OFData dataWithItems: "\x04\x0CHello World!" - count: 14] ASN1DERValue] octetStringValue] - isEqual: [OFData dataWithItems: "Hello World!" - count: 12]] && - [[[[OFData dataWithItems: "\x04\x81\x80xxxxxxxxxxxxxxxxxxxxxxxxxxxx" - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - "xxxxxxxxxxxxxxxxxxxx" - count: 131] ASN1DERValue] octetStringValue] - isEqual: [OFData dataWithItems: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - "xxxxxxxxxxxxxxxxxxxxxxxxxx" - count: 128]]) - - EXPECT_EXCEPTION(@"Detection of out of range octet string", - OFOutOfRangeException, - [[OFData dataWithItems: "\x16\x89" - "\x01\x01\x01\x01\x01\x01\x01\x01\x01" - count: 11] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of truncated octet string", - OFTruncatedDataException, [[OFData dataWithItems: "\x16\x01" - count: 2] ASN1DERValue]) - - TEST(@"Parsing of NULL", - [[[OFData dataWithItems: "\x05\x00" - count: 2] ASN1DERValue] - isKindOfClass: [OFASN1Null class]]) - - EXPECT_EXCEPTION(@"Detection of invalid NULL", - OFInvalidFormatException, [[OFData dataWithItems: "\x05\x01\x00" - count: 3] ASN1DERValue]) - - TEST(@"Parsing of UTF-8 string", - [[[[OFData dataWithItems: "\x0C\x0EHällo Wörld!" - count: 16] ASN1DERValue] UTF8StringValue] - isEqual: @"Hällo Wörld!"] && - [[[[OFData dataWithItems: "\x0C\x81\x80xxxxxxxxxxxxxxxxxxxxxxxxxxxx" - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - "xxxxxxxxxxxxxxxxxxxx" - count: 131] ASN1DERValue] UTF8StringValue] - isEqual: @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - @"xxxxxxxxxxxxxxxx"]) - - EXPECT_EXCEPTION(@"Detection of out of range UTF-8 string", - OFOutOfRangeException, - [[OFData dataWithItems: "\x0C\x89" - "\x01\x01\x01\x01\x01\x01\x01\x01\x01" - count: 11] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of truncated UTF-8 string", - OFTruncatedDataException, [[OFData dataWithItems: "\x0C\x01" - count: 2] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of truncated length", - OFTruncatedDataException, [[OFData dataWithItems: "\x0C\x83\x01\x01" - count: 4] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of invalid / inefficient length #1", - OFInvalidFormatException, [[OFData dataWithItems: "\x0C\x81\x7F" - count: 3] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of invalid / inefficient length #2", - OFInvalidFormatException, - [[OFData dataWithItems: "\x0C\x82\x00\x80xxxxxxxxxxxxxxxxxxxxxxxxxx" - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - "xxxxxxxxxxxxxxxxxx" - count: 132] ASN1DERValue]) - - TEST(@"Parsing of sequence", - (array = [[OFData dataWithItems: "\x30\x00" - count: 2] ASN1DERValue]) && - [array isKindOfClass: [OFArray class]] && [array count] == 0 && - (array = [[OFData dataWithItems: "\x30\x09\x02\x01\x7B\x0C\x04Test" - count: 11] ASN1DERValue]) && - [array isKindOfClass: [OFArray class]] && [array count] == 2 && - [[array objectAtIndex: 0] integerValue] == 123 && - [[[array objectAtIndex: 1] stringValue] isEqual: @"Test"]) - - EXPECT_EXCEPTION(@"Parsing of truncated sequence #1", - OFTruncatedDataException, [[OFData dataWithItems: "\x30\x01" - count: 2] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Parsing of truncated sequence #2", - OFTruncatedDataException, - [[OFData dataWithItems: "\x30\x04\x02\x01\x01\x00\x00" - count: 7] ASN1DERValue]) - - TEST(@"Parsing of IA5String", - [[[[OFData dataWithItems: "\x16\x0CHello World!" - count: 14] ASN1DERValue] IA5StringValue] - isEqual: @"Hello World!"] && - [[[[OFData dataWithItems: "\x16\x81\x80xxxxxxxxxxxxxxxxxxxxxxxxxxxx" - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - "xxxxxxxxxxxxxxxxxxxx" - count: 131] ASN1DERValue] IA5StringValue] - isEqual: @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - @"xxxxxxxxxxxxxxxx"]) - - EXPECT_EXCEPTION(@"Detection of invalid IA5String", - OFInvalidEncodingException, - [[OFData dataWithItems: "\x16\x02ä" - count: 4] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of out of range IA5String", - OFOutOfRangeException, - [[OFData dataWithItems: "\x16\x89" - "\x01\x01\x01\x01\x01\x01\x01\x01\x01" - count: 11] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of truncated IA5String", - OFTruncatedDataException, [[OFData dataWithItems: "\x16\x01" - count: 2] ASN1DERValue]) - - [pool drain]; -} -@end Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -84,10 +84,14 @@ - (void)outputSuccess: (OFString *)test inModule: (OFString *)module; - (void)outputFailure: (OFString *)test inModule: (OFString *)module; @end + +@interface TestsAppDelegate (OFASN1DERValueTests) +- (void)ASN1DERValueTests; +@end @interface TestsAppDelegate (OFArrayTests) - (void)arrayTests; @end @@ -105,14 +109,10 @@ @interface TestsAppDelegate (OFDataTests) - (void)dataTests; @end -@interface TestsAppDelegate (OFDataASN1DERValueTests) -- (void)dataASN1DERValueTests; -@end - @interface TestsAppDelegate (OFDateTests) - (void)dateTests; @end @interface TestsAppDelegate (OFDictionaryTests) Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -388,11 +388,10 @@ [self blockTests]; #endif [self stringTests]; [self characterSetTests]; [self dataTests]; - [self dataASN1DERValueTests]; [self arrayTests]; [self dictionaryTests]; [self listTests]; [self setTests]; [self dateTests]; @@ -437,10 +436,11 @@ #ifdef OF_HAVE_FILES [self serializationTests]; #endif [self JSONTests]; [self propertyListTests]; + [self ASN1DERValueTests]; #if defined(OF_HAVE_PLUGINS) [self pluginTests]; #endif #ifdef OF_HAVE_SOCKETS