Index: src/Makefile ================================================================== --- src/Makefile +++ src/Makefile @@ -8,31 +8,19 @@ STATIC_LIB = ${OBJFW_STATIC_LIB} FRAMEWORK = ${OBJFW_FRAMEWORK} LIB_MAJOR = ${OBJFW_LIB_MAJOR} LIB_MINOR = ${OBJFW_LIB_MINOR} -SRCS = OFASN1BitString.m \ - OFASN1Boolean.m \ - OFASN1Enumerated.m \ - OFASN1IA5String.m \ - OFASN1Integer.m \ - OFASN1NumericString.m \ - OFASN1ObjectIdentifier.m \ - OFASN1OctetString.m \ - OFASN1PrintableString.m \ - OFASN1UTF8String.m \ - OFASN1Value.m \ - OFApplication.m \ +SRCS = OFApplication.m \ OFArray.m \ OFAutoreleasePool.m \ OFBlock.m \ OFCharacterSet.m \ OFColor.m \ OFConstantString.m \ OFCountedSet.m \ OFData.m \ - OFData+ASN1DERValue.m \ OFData+CryptoHashing.m \ OFData+MessagePackValue.m \ OFDate.m \ OFDictionary.m \ OFEnumerator.m \ @@ -165,11 +153,10 @@ atomic_osatomic.h \ atomic_powerpc.h \ atomic_sync_builtins.h \ atomic_x86.h INCLUDES := ${SRCS:.m=.h} \ - OFASN1DERRepresentation.h \ OFCollection.h \ OFCryptoHash.h \ OFJSONRepresentation.h \ OFKernelEventObserver.h \ OFKeyValueCoding.h \ DELETED src/OFASN1BitString.h Index: src/OFASN1BitString.h ================================================================== --- src/OFASN1BitString.h +++ src/OFASN1BitString.h @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "OFObject.h" -#import "OFASN1DERRepresentation.h" -#import "OFASN1Value.h" - -OF_ASSUME_NONNULL_BEGIN - -@class OFData; - -/*! - * @brief An ASN.1 BitString. - */ -@interface OFASN1BitString: OFObject -{ - OFData *_bitStringValue; - size_t _bitStringLength; -} - -/*! - * @brief The BitString value. - */ -@property (readonly, nonatomic) OFData *bitStringValue; - -/*! - * @brief The length of the BitString in bits. - */ -@property (readonly, nonatomic) size_t bitStringLength; - -/*! - * @brief Creates an ASN.1 BitString with the specified BitString value and - * length. - * - * @param bitStringValue The value of the BitString - * @param bitStringLength The length of the BitString in bits - * @return A new, autoreleased OFASN1BitString - */ -+ (instancetype)bitStringWithBitStringValue: (OFData *)bitStringValue - bitStringLength: (size_t)bitStringLength; - -- (instancetype)init OF_UNAVAILABLE; - -/*! - * @brief Initializes an already allocated ASN.1 BitString with the specified - * BitString value and length. - * - * @param bitStringValue The value of the BitString - * @param bitStringLength The length of the BitString in bits - * @return An initialized OFASN1BitString - */ -- (instancetype)initWithBitStringValue: (OFData *)bitStringValue - bitStringLength: (size_t)bitStringLength - OF_DESIGNATED_INITIALIZER; - -/*! - * @brief Initializes an already allocated ASN.1 BitString with the specified - * arguments. - * - * @param tagClass The tag class of the value's type - * @param tagNumber The tag number of the value's type - * @param constructed Whether the value if of a constructed type - * @param DEREncodedContents The DER-encoded contents octets of the value. - * @return An initialized OFASN1BitString - */ -- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass - tagNumber: (of_asn1_tag_number_t)tagNumber - constructed: (bool)constructed - DEREncodedContents: (OFData *)DEREncodedContents; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFASN1BitString.m Index: src/OFASN1BitString.m ================================================================== --- src/OFASN1BitString.m +++ src/OFASN1BitString.m @@ -1,182 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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)bitStringWithBitStringValue: (OFData *)bitStringValue - bitStringLength: (size_t)bitStringLength -{ - return [[[self alloc] - initWithBitStringValue: bitStringValue - bitStringLength: bitStringLength] autorelease]; -} - -- (instancetype)initWithBitStringValue: (OFData *)bitStringValue - bitStringLength: (size_t)bitStringLength -{ - self = [super init]; - - @try { - if (bitStringValue.count * bitStringValue.itemSize != - OF_ROUND_UP_POW2(8, bitStringLength) / 8) - @throw [OFInvalidFormatException exception]; - - _bitStringValue = [bitStringValue copy]; - _bitStringLength = bitStringLength; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass - tagNumber: (of_asn1_tag_number_t)tagNumber - constructed: (bool)constructed - DEREncodedContents: (OFData *)DEREncodedContents -{ - void *pool = objc_autoreleasePoolPush(); - OFData *bitStringValue; - size_t bitStringLength; - - @try { - unsigned char unusedBits; - size_t count = DEREncodedContents.count; - - if (tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL || - tagNumber != OF_ASN1_TAG_NUMBER_BIT_STRING || constructed) - @throw [OFInvalidArgumentException exception]; - - if (DEREncodedContents.itemSize != 1 || count == 0) - @throw [OFInvalidFormatException exception]; - - unusedBits = - *(unsigned char *)[DEREncodedContents itemAtIndex: 0]; - - if (unusedBits > 7) - @throw [OFInvalidFormatException exception]; - - /* - * Can't have any bits of the last byte unused if we have no - * byte. - */ - if (count == 1 && unusedBits != 0) - @throw [OFInvalidFormatException exception]; - - if (SIZE_MAX / 8 < count - 1) - @throw [OFOutOfRangeException exception]; - - bitStringLength = (count - 1) * 8; - bitStringValue = [[DEREncodedContents - subdataWithRange: of_range(1, count - 1)] copy]; - - if (unusedBits != 0) - bitStringLength -= unusedBits; - } @catch (id e) { - [self release]; - @throw e; - } - - self = [self initWithBitStringValue: bitStringValue - bitStringLength: bitStringLength]; - - objc_autoreleasePoolPop(pool); - - return self; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (void)dealloc -{ - [_bitStringValue release]; - - [super dealloc]; -} - -- (OFData *)ASN1DERRepresentation -{ - size_t bitStringValueCount = [_bitStringValue count]; - size_t roundedUpLength = OF_ROUND_UP_POW2(8, _bitStringLength); - unsigned char unusedBits = roundedUpLength - _bitStringLength; - unsigned char header[] = { - OF_ASN1_TAG_NUMBER_BIT_STRING, - bitStringValueCount + 1, - unusedBits - }; - OFMutableData *data; - - if (bitStringValueCount + 1 > UINT8_MAX || - bitStringValueCount != roundedUpLength / 8) - @throw [OFInvalidFormatException exception]; - - data = [OFMutableData - dataWithCapacity: sizeof(header) + bitStringValueCount]; - [data addItems: header - count: sizeof(header)]; - [data addItems: [_bitStringValue items] - count: bitStringValueCount]; - - [data makeImmutable]; - - return data; -} - -- (bool)isEqual: (id)object -{ - OFASN1BitString *bitString; - - if (![object isKindOfClass: [OFASN1BitString class]]) - return false; - - bitString = object; - - if (![bitString->_bitStringValue isEqual: _bitStringValue]) - return false; - if (bitString->_bitStringLength != _bitStringLength) - return false; - - return true; -} - -- (uint32_t)hash -{ - return _bitStringValue.hash + (uint32_t)_bitStringLength; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: @"", - _bitStringValue, _bitStringLength]; -} -@end DELETED src/OFASN1Boolean.h Index: src/OFASN1Boolean.h ================================================================== --- src/OFASN1Boolean.h +++ src/OFASN1Boolean.h @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "OFObject.h" -#import "OFASN1DERRepresentation.h" -#import "OFASN1Value.h" - -OF_ASSUME_NONNULL_BEGIN - -/*! - * @brief An ASN.1 Boolean. - */ -@interface OFASN1Boolean: OFObject -{ - bool _booleanValue; -} - -/*! - * @brief The Boolean value. - */ -@property (readonly, nonatomic) bool booleanValue; - -/*! - * @brief Creates an ASN.1 Boolean with the specified Boolean value. - * - * @param booleanValue The value of the Boolean - * @return A new, autoreleased OFASN1Boolean - */ -+ (instancetype)booleanWithBooleanValue: (bool)booleanValue; - -- (instancetype)init OF_UNAVAILABLE; - -/*! - * @brief Initializes an already allocated ASN.1 Boolean with the specified - * Boolean value. - * - * @param booleanValue The value of the Boolean - * @return An initialized OFASN1Boolean - */ -- (instancetype)initWithBooleanValue: (bool)booleanValue - OF_DESIGNATED_INITIALIZER; - -/*! - * @brief Initializes an already allocated ASN.1 Boolean with the specified - * arguments. - * - * @param tagClass The tag class of the value's type - * @param tagNumber The tag number of the value's type - * @param constructed Whether the value if of a constructed type - * @param DEREncodedContents The DER-encoded contents octets of the value. - * @return An initialized OFASN1Boolean - */ -- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass - tagNumber: (of_asn1_tag_number_t)tagNumber - constructed: (bool)constructed - DEREncodedContents: (OFData *)DEREncodedContents; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFASN1Boolean.m Index: src/OFASN1Boolean.m ================================================================== --- src/OFASN1Boolean.m +++ src/OFASN1Boolean.m @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "OFASN1Boolean.h" -#import "OFData.h" -#import "OFString.h" - -#import "OFInvalidArgumentException.h" -#import "OFInvalidFormatException.h" - -@implementation OFASN1Boolean -@synthesize booleanValue = _booleanValue; - -+ (instancetype)booleanWithBooleanValue: (bool)booleanValue -{ - return [[[self alloc] initWithBooleanValue: booleanValue] autorelease]; -} - -- (instancetype)initWithBooleanValue: (bool)booleanValue -{ - self = [super init]; - - _booleanValue = booleanValue; - - return self; -} - -- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass - tagNumber: (of_asn1_tag_number_t)tagNumber - constructed: (bool)constructed - DEREncodedContents: (OFData *)DEREncodedContents -{ - unsigned char value; - - @try { - if (tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL || - tagNumber != OF_ASN1_TAG_NUMBER_BOOLEAN || constructed) - @throw [OFInvalidArgumentException exception]; - - if (DEREncodedContents.itemSize != 1 || - DEREncodedContents.count != 1) - @throw [OFInvalidFormatException exception]; - - value = *(unsigned char *)[DEREncodedContents itemAtIndex: 0]; - - if (value != 0 && value != 0xFF) - @throw [OFInvalidFormatException exception]; - } @catch (id e) { - [self release]; - @throw e; - } - - return [self initWithBooleanValue: !!value]; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (OFData *)ASN1DERRepresentation -{ - char buffer[] = { - OF_ASN1_TAG_NUMBER_BOOLEAN, - 1, - (_booleanValue ? 0xFF : 0x00) - }; - - return [OFData dataWithItems: buffer - count: sizeof(buffer)]; -} - -- (bool)isEqual: (id)object -{ - OFASN1Boolean *boolean; - - if (![object isKindOfClass: [OFASN1Boolean class]]) - return false; - - boolean = object; - - if (boolean->_booleanValue != _booleanValue) - return false; - - return true; -} - -- (uint32_t)hash -{ - return (uint32_t)_booleanValue; -} - -- (OFString *)description -{ - return (_booleanValue - ? @"" - : @""); -} -@end DELETED src/OFASN1DERRepresentation.h Index: src/OFASN1DERRepresentation.h ================================================================== --- src/OFASN1DERRepresentation.h +++ src/OFASN1DERRepresentation.h @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "OFObject.h" - -OF_ASSUME_NONNULL_BEGIN - -@class OFData; - -/*! - * @protocol OFASN1DERRepresentation \ - * OFASN1DERRepresentation.h ObjFW/OFASN1DERRepresentation.h - * - * @brief A protocol implemented by classes that support encoding to ASN.1 DER - * representation. - */ -@protocol OFASN1DERRepresentation -/*! - * @brief The object in ASN.1 DER representation. - */ -@property (readonly, nonatomic) OFData *ASN1DERRepresentation; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFASN1Enumerated.h Index: src/OFASN1Enumerated.h ================================================================== --- src/OFASN1Enumerated.h +++ src/OFASN1Enumerated.h @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "OFObject.h" -#import "OFASN1Value.h" - -OF_ASSUME_NONNULL_BEGIN - -/*! - * @brief An ASN.1 Enumerated. - */ -@interface OFASN1Enumerated: OFObject -{ - intmax_t _integerValue; -} - -/*! - * @brief The integer value. - */ -@property (readonly, nonatomic) intmax_t integerValue; - -/*! - * @brief Creates an ASN.1 Enumerated with the specified integer value. - * - * @param integerValue The integer value of the Enumerated - * @return A new, autoreleased OFASN1Enumerated - */ -+ (instancetype)enumeratedWithIntegerValue: (intmax_t)integerValue; - -- (instancetype)init OF_UNAVAILABLE; - -/*! - * @brief Initializes an already allocated ASN.1 Enumerated with the specified - * integer value. - * - * @param integerValue The integer value of the Enumerated - * @return An initialized OFASN1Enumerated - */ -- (instancetype)initWithIntegerValue: (intmax_t)integerValue - OF_DESIGNATED_INITIALIZER; - -/*! - * @brief Initializes an already allocated ASN.1 Enumerated with the specified - * arguments. - * - * @param tagClass The tag class of the value's type - * @param tagNumber The tag number of the value's type - * @param constructed Whether the value if of a constructed type - * @param DEREncodedContents The DER-encoded contents octets of the value. - * @return An initialized OFASN1Enumerated - */ -- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass - tagNumber: (of_asn1_tag_number_t)tagNumber - constructed: (bool)constructed - DEREncodedContents: (OFData *)DEREncodedContents; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFASN1Enumerated.m Index: src/OFASN1Enumerated.m ================================================================== --- src/OFASN1Enumerated.m +++ src/OFASN1Enumerated.m @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "OFASN1Enumerated.h" -#import "OFData.h" -#import "OFString.h" - -#import "OFInvalidArgumentException.h" - -extern intmax_t of_asn1_der_integer_parse(const unsigned char *buffer, - size_t length); - -@implementation OFASN1Enumerated -@synthesize integerValue = _integerValue; - -+ (instancetype)enumeratedWithIntegerValue: (intmax_t)integerValue -{ - return [[[self alloc] initWithIntegerValue: integerValue] autorelease]; -} - -- (instancetype)initWithIntegerValue: (intmax_t)integerValue -{ - 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 -{ - 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_der_integer_parse( - DEREncodedContents.items, DEREncodedContents.count); - } @catch (id e) { - [self release]; - @throw e; - } - - return [self initWithIntegerValue: integerValue]; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (bool)isEqual: (id)object -{ - OFASN1Enumerated *enumerated; - - if (![object isKindOfClass: [OFASN1Enumerated class]]) - return false; - - enumerated = object; - - if (enumerated->_integerValue != _integerValue) - return false; - - return true; -} - -- (uint32_t)hash -{ - return (uint32_t)_integerValue; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: @"", - _integerValue]; -} -@end DELETED src/OFASN1IA5String.h Index: src/OFASN1IA5String.h ================================================================== --- src/OFASN1IA5String.h +++ src/OFASN1IA5String.h @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "OFObject.h" -#import "OFASN1Value.h" - -OF_ASSUME_NONNULL_BEGIN - -@class OFString; - -/*! - * @brief An ASN.1 IA5String. - */ -@interface OFASN1IA5String: OFObject -{ - OFString *_IA5StringValue; -} - -/*! - * @brief The IA5String value. - */ -@property (readonly, nonatomic) OFString *IA5StringValue; - -/*! - * @brief The string value. - */ -@property (readonly, nonatomic) OFString *stringValue; - -/*! - * @brief Creates an IA5String with the specified string value. - * - * @param stringValue The string value of the IA5String - * @return A new, autoreleased OFASN1IA5String - */ -+ (instancetype)stringWithStringValue: (OFString *)stringValue; - -- (instancetype)init OF_UNAVAILABLE; - -/*! - * @brief Initializes an already allocated IA5String with the specified string - * value. - * - * @param stringValue The string value of the IA5String - * @return An initialized OFASN1IA5String - */ -- (instancetype)initWithStringValue: (OFString *)stringValue - OF_DESIGNATED_INITIALIZER; - -/*! - * @brief Initializes an already allocated ASN.1 IA5String with the specified - * arguments. - * - * @param tagClass The tag class of the value's type - * @param tagNumber The tag number of the value's type - * @param constructed Whether the value if of a constructed type - * @param DEREncodedContents The DER-encoded contents octets of the value. - * @return An initialized OFASN1IA5String - */ -- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass - tagNumber: (of_asn1_tag_number_t)tagNumber - constructed: (bool)constructed - DEREncodedContents: (OFData *)DEREncodedContents; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFASN1IA5String.m Index: src/OFASN1IA5String.m ================================================================== --- src/OFASN1IA5String.m +++ src/OFASN1IA5String.m @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "OFASN1IA5String.h" -#import "OFData.h" -#import "OFString.h" - -#import "OFInvalidArgumentException.h" - -@implementation OFASN1IA5String -@synthesize IA5StringValue = _IA5StringValue; - -+ (instancetype)stringWithStringValue: (OFString *)stringValue -{ - return [[[self alloc] initWithStringValue: stringValue] autorelease]; -} - -- (instancetype)initWithStringValue: (OFString *)stringValue -{ - self = [super init]; - - @try { - _IA5StringValue = [stringValue copy]; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass - tagNumber: (of_asn1_tag_number_t)tagNumber - constructed: (bool)constructed - DEREncodedContents: (OFData *)DEREncodedContents -{ - void *pool = objc_autoreleasePoolPush(); - OFString *IA5StringValue; - - @try { - if (tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL || - tagNumber != OF_ASN1_TAG_NUMBER_IA5_STRING || constructed) - @throw [OFInvalidArgumentException exception]; - - if (DEREncodedContents.itemSize != 1) - @throw [OFInvalidArgumentException exception]; - - IA5StringValue = [OFString - stringWithCString: DEREncodedContents.items - encoding: OF_STRING_ENCODING_ASCII - length: DEREncodedContents.count]; - } @catch (id e) { - [self release]; - @throw e; - } - - self = [self initWithStringValue: IA5StringValue]; - - objc_autoreleasePoolPop(pool); - - return self; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (void)dealloc -{ - [_IA5StringValue release]; - - [super dealloc]; -} - -- (OFString *)stringValue -{ - return self.IA5StringValue; -} - -- (bool)isEqual: (id)object -{ - OFASN1IA5String *IA5String; - - if (![object isKindOfClass: [OFASN1IA5String class]]) - return false; - - IA5String = object; - - if (![IA5String->_IA5StringValue isEqual: _IA5StringValue]) - return false; - - return true; -} - -- (uint32_t)hash -{ - return _IA5StringValue.hash; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: @"", - _IA5StringValue]; -} -@end DELETED src/OFASN1Integer.h Index: src/OFASN1Integer.h ================================================================== --- src/OFASN1Integer.h +++ src/OFASN1Integer.h @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "OFObject.h" -#import "OFASN1Value.h" - -OF_ASSUME_NONNULL_BEGIN - -/*! - * @brief An ASN.1 Integer. - */ -@interface OFASN1Integer: OFObject -{ - intmax_t _integerValue; -} - -/*! - * @brief The Integer value. - */ -@property (readonly, nonatomic) intmax_t integerValue; - -/*! - * @brief Creates an ASN.1 Integer with the specified integer value. - * - * @param integerValue The integer value of the Integer - * @return A new, autoreleased OFASN1Integer - */ -+ (instancetype)integerWithIntegerValue: (intmax_t)integerValue; - -- (instancetype)init OF_UNAVAILABLE; - -/*! - * @brief Initializes an already allocated ASN.1 Integer with the specified - * integer value. - * - * @param integerValue The integer value of the Integer - * @return An initialized OFASN1Integer - */ -- (instancetype)initWithIntegerValue: (intmax_t)integerValue - OF_DESIGNATED_INITIALIZER; - -/*! - * @brief Initializes an already allocated ASN.1 Integer with the specified - * arguments. - * - * @param tagClass The tag class of the value's type - * @param tagNumber The tag number of the value's type - * @param constructed Whether the value if of a constructed type - * @param DEREncodedContents The DER-encoded contents octets of the value. - * @return An initialized OFASN1Integer - */ -- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass - tagNumber: (of_asn1_tag_number_t)tagNumber - constructed: (bool)constructed - DEREncodedContents: (OFData *)DEREncodedContents; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFASN1Integer.m Index: src/OFASN1Integer.m ================================================================== --- src/OFASN1Integer.m +++ src/OFASN1Integer.m @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "OFASN1Integer.h" -#import "OFData.h" -#import "OFString.h" - -#import "OFInvalidArgumentException.h" -#import "OFInvalidFormatException.h" -#import "OFOutOfRangeException.h" - -intmax_t -of_asn1_der_integer_parse(const unsigned char *buffer, size_t length) -{ - uintmax_t value = 0; - - /* TODO: Support for big numbers */ - if (length > sizeof(uintmax_t) && - (length != sizeof(uintmax_t) + 1 || buffer[0] != 0)) - @throw [OFOutOfRangeException exception]; - - if (length >= 2 && ((buffer[0] == 0 && !(buffer[1] & 0x80)) || - (buffer[0] == 0xFF && buffer[1] & 0x80))) - @throw [OFInvalidFormatException exception]; - - if (length >= 1 && buffer[0] & 0x80) - value = ~(uintmax_t)0; - - while (length--) - value = (value << 8) | *buffer++; - - return value; -} - -@implementation OFASN1Integer -@synthesize integerValue = _integerValue; - -+ (instancetype)integerWithIntegerValue: (intmax_t)integerValue -{ - return [[[self alloc] initWithIntegerValue: integerValue] autorelease]; -} - -- (instancetype)initWithIntegerValue: (intmax_t)integerValue -{ - 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 -{ - intmax_t integerValue; - - @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]; - - integerValue = of_asn1_der_integer_parse( - DEREncodedContents.items, DEREncodedContents.count); - } @catch (id e) { - [self release]; - @throw e; - } - - return [self initWithIntegerValue: integerValue]; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (bool)isEqual: (id)object -{ - OFASN1Integer *integer; - - if (![object isKindOfClass: [OFASN1Integer class]]) - return false; - - integer = object; - - if (integer->_integerValue != _integerValue) - return false; - - return true; -} - -- (uint32_t)hash -{ - return (uint32_t)_integerValue; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: @"", - _integerValue]; -} -@end DELETED src/OFASN1NumericString.h Index: src/OFASN1NumericString.h ================================================================== --- src/OFASN1NumericString.h +++ src/OFASN1NumericString.h @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "OFObject.h" -#import "OFASN1Value.h" - -OF_ASSUME_NONNULL_BEGIN - -@class OFString; - -/*! - * @brief An ASN.1 NumericString. - */ -@interface OFASN1NumericString: OFObject -{ - OFString *_numericStringValue; -} - -/*! - * @brief The NumericString value. - */ -@property (readonly, nonatomic) OFString *numericStringValue; - -/*! - * @brief The string value. - */ -@property (readonly, nonatomic) OFString *stringValue; - -/*! - * @brief Creates an NumericString with the specified string value. - * - * @param stringValue The string value of the NumericString - * @return A new, autoreleased OFASN1NumericString - */ -+ (instancetype)stringWithStringValue: (OFString *)stringValue; - -- (instancetype)init OF_UNAVAILABLE; - -/*! - * @brief Initializes an already allocated NumericString with the specified - * string value. - * - * @param stringValue The string value of the NumericString - * @return An initialized OFASN1NumericString - */ -- (instancetype)initWithStringValue: (OFString *)stringValue - OF_DESIGNATED_INITIALIZER; - -/*! - * @brief Initializes an already allocated ASN.1 NumericString with the - * specified arguments. - * - * @param tagClass The tag class of the value's type - * @param tagNumber The tag number of the value's type - * @param constructed Whether the value if of a constructed type - * @param DEREncodedContents The DER-encoded contents octets of the value. - * @return An initialized ASN.1 NumericString - */ -- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass - tagNumber: (of_asn1_tag_number_t)tagNumber - constructed: (bool)constructed - DEREncodedContents: (OFData *)DEREncodedContents; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFASN1NumericString.m Index: src/OFASN1NumericString.m ================================================================== --- src/OFASN1NumericString.m +++ src/OFASN1NumericString.m @@ -1,134 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "OFASN1NumericString.h" -#import "OFData.h" -#import "OFString.h" - -#import "OFInvalidArgumentException.h" -#import "OFInvalidEncodingException.h" - -@implementation OFASN1NumericString -@synthesize numericStringValue = _numericStringValue; - -+ (instancetype)stringWithStringValue: (OFString *)stringValue -{ - return [[[self alloc] initWithStringValue: stringValue] autorelease]; -} - -- (instancetype)initWithStringValue: (OFString *)stringValue -{ - self = [super init]; - - @try { - void *pool = objc_autoreleasePoolPush(); - const char *cString = stringValue.UTF8String; - size_t length = stringValue.UTF8StringLength; - - for (size_t i = 0; i < length; i++) - if (!of_ascii_isdigit(cString[i]) && cString[i] != ' ') - @throw [OFInvalidEncodingException exception]; - - _numericStringValue = [stringValue copy]; - - objc_autoreleasePoolPop(pool); - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass - tagNumber: (of_asn1_tag_number_t)tagNumber - constructed: (bool)constructed - DEREncodedContents: (OFData *)DEREncodedContents -{ - void *pool = objc_autoreleasePoolPush(); - OFString *numericStringValue; - - @try { - if (tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL || - tagNumber != OF_ASN1_TAG_NUMBER_NUMERIC_STRING || - constructed) - @throw [OFInvalidArgumentException exception]; - - if (DEREncodedContents.itemSize != 1) - @throw [OFInvalidArgumentException exception]; - - numericStringValue = [OFString - stringWithCString: DEREncodedContents.items - encoding: OF_STRING_ENCODING_ASCII - length: DEREncodedContents.count]; - } @catch (id e) { - [self release]; - @throw e; - } - - self = [self initWithStringValue: numericStringValue]; - - objc_autoreleasePoolPop(pool); - - return self; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (void)dealloc -{ - [_numericStringValue release]; - - [super dealloc]; -} - -- (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 DELETED src/OFASN1ObjectIdentifier.h Index: src/OFASN1ObjectIdentifier.h ================================================================== --- src/OFASN1ObjectIdentifier.h +++ src/OFASN1ObjectIdentifier.h @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "OFObject.h" -#import "OFASN1Value.h" - -OF_ASSUME_NONNULL_BEGIN - -@class OFArray OF_GENERIC(ObjetType); -@class OFNumber; - -/*! - * @brief An ASN.1 ObjectIdentifier. - */ -@interface OFASN1ObjectIdentifier: OFObject -{ - OFArray OF_GENERIC(OFNumber *) *_subidentifiers; -} - -/*! - * @brief The subidentifiers of the ObjectIdentifier. - */ -@property (readonly, nonatomic) OFArray OF_GENERIC(OFNumber *) *subidentifiers; - -/*! - * @brief Creates an ASN.1 ObjectIdentifier with the specified subidentifiers. - * - * @param subidentifiers The subidentifiers of the ASN.1 ObjectIdentifier - * @return A new, autoreleased OFASN1ObjectIdentifier - */ -+ (instancetype)objectIdentifierWithSubidentifiers: - (OFArray OF_GENERIC(OFNumber *) *)subidentifiers; - -- (instancetype)init OF_UNAVAILABLE; - -/*! - * @brief Initializes an already allocated ASN.1 ObjectIdentifier with the - * specified subidentifiers. - * - * @param subidentifiers The subidentifiers of the ASN.1 ObjectIdentifier - * @return An initialized OFASN1ObjectIdentifier - */ -- (instancetype)initWithSubidentifiers: - (OFArray OF_GENERIC(OFNumber *) *)subidentifiers OF_DESIGNATED_INITIALIZER; - -/*! - * @brief Initializes an already allocated ASN.1 ObjectIdentifier with the - * specified arguments. - * - * @param tagClass The tag class of the value's type - * @param tagNumber The tag number of the value's type - * @param constructed Whether the value if of a constructed type - * @param DEREncodedContents The DER-encoded contents octets of the value. - * @return An initialized OFASN1ObjectIdentifier - */ -- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass - tagNumber: (of_asn1_tag_number_t)tagNumber - constructed: (bool)constructed - DEREncodedContents: (OFData *)DEREncodedContents; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFASN1ObjectIdentifier.m Index: src/OFASN1ObjectIdentifier.m ================================================================== --- src/OFASN1ObjectIdentifier.m +++ src/OFASN1ObjectIdentifier.m @@ -1,180 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "OFASN1ObjectIdentifier.h" -#import "OFArray.h" -#import "OFData.h" -#import "OFNumber.h" -#import "OFString.h" - -#import "OFInvalidArgumentException.h" -#import "OFInvalidFormatException.h" -#import "OFOutOfRangeException.h" - -@implementation OFASN1ObjectIdentifier -@synthesize subidentifiers = _subidentifiers; - -+ (instancetype)objectIdentifierWithSubidentifiers: - (OFArray OF_GENERIC(OFNumber *) *)subidentifiers -{ - return [[[self alloc] - initWithSubidentifiers: subidentifiers] autorelease]; -} - -- (instancetype)initWithSubidentifiers: - (OFArray OF_GENERIC(OFNumber *) *)subidentifiers -{ - self = [super init]; - - @try { - if (subidentifiers.count < 1) - @throw [OFInvalidFormatException exception]; - - switch ([[subidentifiers objectAtIndex: 0] intMaxValue]) { - case 0: - case 1: - case 2: - break; - default: - @throw [OFInvalidFormatException exception]; - } - - _subidentifiers = [subidentifiers copy]; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass - tagNumber: (of_asn1_tag_number_t)tagNumber - constructed: (bool)constructed - DEREncodedContents: (OFData *)DEREncodedContents -{ - void *pool = objc_autoreleasePoolPush(); - OFMutableArray OF_GENERIC(OFNumber *) *subidentifiers; - - @try { - const unsigned char *items = DEREncodedContents.items; - size_t count = DEREncodedContents.count; - uintmax_t value = 0; - uint_fast8_t bits = 0; - - if (tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL || - tagNumber != OF_ASN1_TAG_NUMBER_OBJECT_IDENTIFIER || - constructed) - @throw [OFInvalidArgumentException exception]; - - if (DEREncodedContents.itemSize != 1 || count == 0) - @throw [OFInvalidArgumentException exception]; - - subidentifiers = [OFMutableArray array]; - - for (size_t i = 0; i < count; i++) { - if (bits == 0 && items[i] == 0x80) - @throw [OFInvalidFormatException exception]; - - value = (value << 7) | (items[i] & 0x7F); - bits += 7; - - if (bits > sizeof(uintmax_t) * 8) - @throw [OFOutOfRangeException exception]; - - if (items[i] & 0x80) - continue; - - if (subidentifiers.count == 0) { - if (value < 40) - [subidentifiers addObject: - [OFNumber numberWithUIntMax: 0]]; - else if (value < 80) { - [subidentifiers addObject: - [OFNumber numberWithUIntMax: 1]]; - value -= 40; - } else { - [subidentifiers addObject: - [OFNumber numberWithUIntMax: 2]]; - value -= 80; - } - } - - [subidentifiers addObject: - [OFNumber numberWithUIntMax: value]]; - - value = 0; - bits = 0; - } - - if (items[count - 1] & 0x80) - @throw [OFInvalidFormatException exception]; - - [subidentifiers makeImmutable]; - } @catch (id e) { - [self release]; - @throw e; - } - - self = [self initWithSubidentifiers: subidentifiers]; - - objc_autoreleasePoolPop(pool); - - return self; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (void)dealloc -{ - [_subidentifiers release]; - - [super dealloc]; -} - -- (bool)isEqual: (id)object -{ - OFASN1ObjectIdentifier *objectIdentifier; - - if (![object isKindOfClass: [OFASN1ObjectIdentifier class]]) - return false; - - objectIdentifier = object; - - if (![objectIdentifier->_subidentifiers isEqual: _subidentifiers]) - return false; - - return true; -} - -- (uint32_t)hash -{ - return _subidentifiers.hash; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"", - [_subidentifiers componentsJoinedByString: @"."]]; -} -@end DELETED src/OFASN1OctetString.h Index: src/OFASN1OctetString.h ================================================================== --- src/OFASN1OctetString.h +++ src/OFASN1OctetString.h @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "OFObject.h" -#import "OFASN1Value.h" - -OF_ASSUME_NONNULL_BEGIN - -@class OFData; - -/*! - * @brief An ASN.1 OctetString. - */ -@interface OFASN1OctetString: OFObject -{ - OFData *_octetStringValue; -} - -/*! - * @brief The OctetString value. - */ -@property (readonly, nonatomic) OFData *octetStringValue; - -/*! - * @brief Creates an OctetString with the specified value. - * - * @param octetStringValue The OctetString value - * @return A new, autoreleased OFASN1OctetString - */ -+ (instancetype)octetStringWithOctetStringValue: (OFData *)octetStringValue; - -- (instancetype)init OF_UNAVAILABLE; - -/*! - * @brief Initializes an already allocated OctetString with the specified - * value. - * - * @param octetStringValue The OctetString value - * @return An initialized OFASN1OctetString - */ -- (instancetype)initWithOctetStringValue: (OFData *)octetStringValue - OF_DESIGNATED_INITIALIZER; - -/*! - * @brief Initializes an already allocated ASN.1 OctetString with the specified - * arguments. - * - * @param tagClass The tag class of the value's type - * @param tagNumber The tag number of the value's type - * @param constructed Whether the value if of a constructed type - * @param DEREncodedContents The DER-encoded contents octets of the value. - * @return An initialized ASN.1 OctetString - */ -- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass - tagNumber: (of_asn1_tag_number_t)tagNumber - constructed: (bool)constructed - DEREncodedContents: (OFData *)DEREncodedContents; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFASN1OctetString.m Index: src/OFASN1OctetString.m ================================================================== --- src/OFASN1OctetString.m +++ src/OFASN1OctetString.m @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "OFASN1OctetString.h" -#import "OFData.h" -#import "OFString.h" - -#import "OFInvalidArgumentException.h" - -@implementation OFASN1OctetString -@synthesize octetStringValue = _octetStringValue; - -+ (instancetype)octetStringWithOctetStringValue: (OFData *)octetStringValue -{ - return [[[self alloc] - initWithOctetStringValue: octetStringValue] autorelease]; -} - -- (instancetype)initWithOctetStringValue: (OFData *)octetStringValue -{ - self = [super init]; - - @try { - _octetStringValue = [octetStringValue copy]; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass - tagNumber: (of_asn1_tag_number_t)tagNumber - constructed: (bool)constructed - DEREncodedContents: (OFData *)DEREncodedContents -{ - @try { - 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]; - } @catch (id e) { - [self release]; - @throw e; - } - - return [self initWithOctetStringValue: DEREncodedContents]; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (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 _octetStringValue.hash; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: @"", - _octetStringValue]; -} -@end DELETED src/OFASN1PrintableString.h Index: src/OFASN1PrintableString.h ================================================================== --- src/OFASN1PrintableString.h +++ src/OFASN1PrintableString.h @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "OFObject.h" -#import "OFASN1Value.h" - -OF_ASSUME_NONNULL_BEGIN - -@class OFString; - -/*! - * @brief An ASN.1 PrintableString. - */ -@interface OFASN1PrintableString: OFObject -{ - OFString *_printableStringValue; -} - -/*! - * @brief The PrintableString value. - */ -@property (readonly, nonatomic) OFString *printableStringValue; - -/*! - * @brief The string value. - */ -@property (readonly, nonatomic) OFString *stringValue; - -/*! - * @brief Creates a PrintableString with the specified string value. - * - * @param stringValue The string value of the PrintableString - * @return A new, autoreleased OFASN1PrintableString - */ -+ (instancetype)stringWithStringValue: (OFString *)stringValue; - -- (instancetype)init OF_UNAVAILABLE; - -/*! - * @brief Initializes an already allocated PrintableString with the specified - * string value. - * - * @param stringValue The string value of the PrintableString - * @return An initialized OFASN1PrintableString - */ -- (instancetype)initWithStringValue: (OFString *)stringValue - OF_DESIGNATED_INITIALIZER; - -/*! - * @brief Initializes an already allocated ASN.1 PrintableString with the - * specified arguments. - * - * @param tagClass The tag class of the value's type - * @param tagNumber The tag number of the value's type - * @param constructed Whether the value if of a constructed type - * @param DEREncodedContents The DER-encoded contents octets of the value. - * @return An initialized OFASN1PrintableString - */ -- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass - tagNumber: (of_asn1_tag_number_t)tagNumber - constructed: (bool)constructed - DEREncodedContents: (OFData *)DEREncodedContents; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFASN1PrintableString.m Index: src/OFASN1PrintableString.m ================================================================== --- src/OFASN1PrintableString.m +++ src/OFASN1PrintableString.m @@ -1,154 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "OFASN1PrintableString.h" -#import "OFData.h" -#import "OFString.h" - -#import "OFInvalidArgumentException.h" -#import "OFInvalidEncodingException.h" - -@implementation OFASN1PrintableString -@synthesize printableStringValue = _printableStringValue; - -+ (instancetype)stringWithStringValue: (OFString *)stringValue -{ - return [[[self alloc] initWithStringValue: stringValue] autorelease]; -} - -- (instancetype)initWithStringValue: (OFString *)stringValue -{ - self = [super init]; - - @try { - void *pool = objc_autoreleasePoolPush(); - const char *cString = stringValue.UTF8String; - size_t length = stringValue.UTF8StringLength; - - for (size_t i = 0; i < length; i++) { - if (of_ascii_isalnum(cString[i])) - continue; - - switch (cString[i]) { - case ' ': - case '\'': - case '(': - case ')': - case '+': - case ',': - case '-': - case '.': - case '/': - case ':': - case '=': - case '?': - continue; - default: - @throw [OFInvalidEncodingException exception]; - } - } - - _printableStringValue = [stringValue copy]; - - objc_autoreleasePoolPop(pool); - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass - tagNumber: (of_asn1_tag_number_t)tagNumber - constructed: (bool)constructed - DEREncodedContents: (OFData *)DEREncodedContents -{ - void *pool = objc_autoreleasePoolPush(); - OFString *printableStringValue; - - @try { - if (tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL || - tagNumber != OF_ASN1_TAG_NUMBER_PRINTABLE_STRING || - constructed) - @throw [OFInvalidArgumentException exception]; - - if (DEREncodedContents.itemSize != 1) - @throw [OFInvalidArgumentException exception]; - - printableStringValue = [OFString - stringWithCString: DEREncodedContents.items - encoding: OF_STRING_ENCODING_ASCII - length: DEREncodedContents.count]; - } @catch (id e) { - [self release]; - @throw e; - } - - self = [self initWithStringValue: printableStringValue]; - - objc_autoreleasePoolPop(pool); - - return self; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (void)dealloc -{ - [_printableStringValue release]; - - [super dealloc]; -} - -- (OFString *)stringValue -{ - return self.printableStringValue; -} - -- (bool)isEqual: (id)object -{ - OFASN1PrintableString *printableString; - - if (![object isKindOfClass: [OFASN1PrintableString class]]) - return false; - - printableString = object; - - if (![printableString->_printableStringValue isEqual: - _printableStringValue]) - return false; - - return true; -} - -- (uint32_t)hash -{ - return _printableStringValue.hash; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: @"", - _printableStringValue]; -} -@end DELETED src/OFASN1UTF8String.h Index: src/OFASN1UTF8String.h ================================================================== --- src/OFASN1UTF8String.h +++ src/OFASN1UTF8String.h @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "OFObject.h" -#import "OFASN1Value.h" - -OF_ASSUME_NONNULL_BEGIN - -@class OFString; - -/*! - * @brief An ASN.1 UTF8String. - */ -@interface OFASN1UTF8String: OFObject -{ - OFString *_UTF8StringValue; -} - -/*! - * @brief The UTF8String value. - */ -@property (readonly, nonatomic) OFString *UTF8StringValue; - -/*! - * @brief The string value. - */ -@property (readonly, nonatomic) OFString *stringValue; - -/*! - * @brief Creates a UTF8String with the specified string value. - * - * @param stringValue The string value of the UTF8String - * @return A new, autoreleased OFASN1UTF8String - */ -+ (instancetype)stringWithStringValue: (OFString *)stringValue; - -- (instancetype)init OF_UNAVAILABLE; - -/*! - * @brief Initializes an already allocated UTF8String with the specified - * string value. - * - * @param stringValue The string value of the UTF8String - * @return An initialized OFASN1UTF8String - */ -- (instancetype)initWithStringValue: (OFString *)stringValue - OF_DESIGNATED_INITIALIZER; - -/*! - * @brief Initializes an already allocated ASN.1 UTF8String with the specified - * arguments. - * - * @param tagClass The tag class of the value's type - * @param tagNumber The tag number of the value's type - * @param constructed Whether the value if of a constructed type - * @param DEREncodedContents The DER-encoded contents octets of the value. - * @return An initialized OFASN1UTF8String - */ -- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass - tagNumber: (of_asn1_tag_number_t)tagNumber - constructed: (bool)constructed - DEREncodedContents: (OFData *)DEREncodedContents; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFASN1UTF8String.m Index: src/OFASN1UTF8String.m ================================================================== --- src/OFASN1UTF8String.m +++ src/OFASN1UTF8String.m @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "OFASN1UTF8String.h" -#import "OFData.h" -#import "OFString.h" - -#import "OFInvalidArgumentException.h" - -@implementation OFASN1UTF8String -@synthesize UTF8StringValue = _UTF8StringValue; - -+ (instancetype)stringWithStringValue: (OFString *)stringValue -{ - return [[[self alloc] initWithStringValue: stringValue] autorelease]; -} - -- (instancetype)initWithStringValue: (OFString *)stringValue -{ - self = [super init]; - - @try { - _UTF8StringValue = [stringValue copy]; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass - tagNumber: (of_asn1_tag_number_t)tagNumber - constructed: (bool)constructed - DEREncodedContents: (OFData *)DEREncodedContents -{ - void *pool = objc_autoreleasePoolPush(); - OFString *UTF8StringValue; - - @try { - if (tagClass != OF_ASN1_TAG_CLASS_UNIVERSAL || - tagNumber != OF_ASN1_TAG_NUMBER_UTF8_STRING || constructed) - @throw [OFInvalidArgumentException exception]; - - if (DEREncodedContents.itemSize != 1) - @throw [OFInvalidArgumentException exception]; - - UTF8StringValue = [OFString - stringWithUTF8String: DEREncodedContents.items - length: DEREncodedContents.count]; - } @catch (id e) { - [self release]; - @throw e; - } - - self = [self initWithStringValue: UTF8StringValue]; - - objc_autoreleasePoolPop(pool); - - return self; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (void)dealloc -{ - [_UTF8StringValue release]; - - [super dealloc]; -} - -- (OFString *)stringValue -{ - return self.UTF8StringValue; -} - -- (bool)isEqual: (id)object -{ - OFASN1UTF8String *UTF8String; - - if (![object isKindOfClass: [OFASN1UTF8String class]]) - return false; - - UTF8String = object; - - if (![UTF8String->_UTF8StringValue isEqual: _UTF8StringValue]) - return false; - - return true; -} - -- (uint32_t)hash -{ - return _UTF8StringValue.hash; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: @"", - _UTF8StringValue]; -} -@end DELETED src/OFASN1Value.h Index: src/OFASN1Value.h ================================================================== --- src/OFASN1Value.h +++ src/OFASN1Value.h @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "OFObject.h" - -OF_ASSUME_NONNULL_BEGIN - -/*! @file */ - -@class OFData; - -/*! - * @brief ASN.1 tag class. - */ -typedef enum { - /*! Universal */ - OF_ASN1_TAG_CLASS_UNIVERSAL = 0x0, - /*! Application */ - OF_ASN1_TAG_CLASS_APPLICATION = 0x1, - /*! Context specific */ - OF_ASN1_TAG_CLASS_CONTEXT_SPECIFIC = 0x2, - /*! Private */ - OF_ASN1_TAG_CLASS_PRIVATE = 0x3 -} of_asn1_tag_class_t; - -/*! - * @brief ASN.1 tag number. - */ -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, - /*! Object Identifier */ - OF_ASN1_TAG_NUMBER_OBJECT_IDENTIFIER = 0x06, - /*! Enumerated */ - OF_ASN1_TAG_NUMBER_ENUMERATED = 0x0A, - /*! UTF-8 string */ - OF_ASN1_TAG_NUMBER_UTF8_STRING = 0x0C, - /*! Sequence */ - OF_ASN1_TAG_NUMBER_SEQUENCE = 0x10, - /*! Set */ - OF_ASN1_TAG_NUMBER_SET = 0x11, - /*! NumericString */ - OF_ASN1_TAG_NUMBER_NUMERIC_STRING = 0x12, - /*! PrintableString */ - OF_ASN1_TAG_NUMBER_PRINTABLE_STRING = 0x13, - /*! IA5String */ - OF_ASN1_TAG_NUMBER_IA5_STRING = 0x16 -} of_asn1_tag_number_t; - -/*! - * @brief A class representing an ASN.1 value. - */ -@interface OFASN1Value: OFObject -{ - of_asn1_tag_class_t _tagClass; - of_asn1_tag_number_t _tagNumber; - bool _constructed; - OFData *_DEREncodedContents; -} - -/*! - * @brief The tag class of the value's type. - */ -@property (readonly, nonatomic) of_asn1_tag_class_t tagClass; - -/*! - * @brief The tag number of the value's type. - */ -@property (readonly, nonatomic) of_asn1_tag_number_t tagNumber; - -/*! - * @brief Whether the value if of a constructed type. - */ -@property (readonly, nonatomic, getter=isConstructed) bool constructed; - -/*! - * @brief The DER-encoded contents octets of the value. - */ -@property (readonly, nonatomic) OFData *DEREncodedContents; - -/*! - * @brief Creates a new ASN.1 value with the specified arguments. - * - * @param tagClass The tag class of the value's type - * @param tagNumber The tag number of the value's type - * @param constructed Whether the value if of a constructed type - * @param DEREncodedContents The DER-encoded contents octets of the value. - * @return A new ASN.1 value - */ -+ (instancetype)valueWithTagClass: (of_asn1_tag_class_t)tagClass - tagNumber: (of_asn1_tag_number_t)tagNumber - constructed: (bool)constructed - DEREncodedContents: (OFData *)DEREncodedContents; - -- (instancetype)init OF_UNAVAILABLE; - -/*! - * @brief Initializes an already allocated ASN.1 value with the specified - * arguments. - * - * @param tagClass The tag class of the value's type - * @param tagNumber The tag number of the value's type - * @param constructed Whether the value if of a constructed type - * @param DEREncodedContents The DER-encoded contents octets of the value. - * @return An initialized ASN.1 value - */ -- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass - tagNumber: (of_asn1_tag_number_t)tagNumber - constructed: (bool)constructed - DEREncodedContents: (OFData *)DEREncodedContents - OF_DESIGNATED_INITIALIZER; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFASN1Value.m Index: src/OFASN1Value.m ================================================================== --- src/OFASN1Value.m +++ src/OFASN1Value.m @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "OFASN1Value.h" -#import "OFData.h" -#import "OFString.h" - -#import "OFInvalidFormatException.h" - -@implementation OFASN1Value -@synthesize tagClass = _tagClass, tagNumber = _tagNumber; -@synthesize constructed = _constructed; -@synthesize DEREncodedContents = _DEREncodedContents; - -+ (instancetype)valueWithTagClass: (of_asn1_tag_class_t)tagClass - tagNumber: (of_asn1_tag_number_t)tagNumber - constructed: (bool)constructed - DEREncodedContents: (OFData *)DEREncodedContents -{ - return [[[self alloc] - initWithTagClass: tagClass - tagNumber: tagNumber - constructed: constructed - DEREncodedContents: DEREncodedContents] autorelease]; -} - -- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass - tagNumber: (of_asn1_tag_number_t)tagNumber - constructed: (bool)constructed - DEREncodedContents: (OFData *)DEREncodedContents -{ - self = [super init]; - - @try { - if (DEREncodedContents.itemSize != 1) - @throw [OFInvalidFormatException exception]; - - _tagClass = tagClass; - _tagNumber = tagNumber; - _constructed = constructed; - _DEREncodedContents = [DEREncodedContents copy]; - } @catch (id e) { - [self release]; - @throw e; - } - - return self; -} - -- (instancetype)init -{ - OF_INVALID_INIT_METHOD -} - -- (void)dealloc -{ - [_DEREncodedContents release]; - - [super dealloc]; -} - -- (bool)isEqual: (id)object -{ - OFASN1Value *value; - - if (![object isKindOfClass: [OFASN1Value class]]) - return false; - - value = object; - - if (value->_tagClass != _tagClass) - return false; - if (value->_tagNumber != _tagNumber) - return false; - if (value->_constructed != _constructed) - return false; - if (![value->_DEREncodedContents isEqual: _DEREncodedContents]) - return false; - - return true; -} - -- (uint32_t)hash -{ - uint32_t hash; - - OF_HASH_INIT(hash); - - OF_HASH_ADD(hash, _tagClass & 0xFF); - OF_HASH_ADD(hash, _tagNumber & 0xFF); - OF_HASH_ADD(hash, _constructed); - OF_HASH_ADD_HASH(hash, _DEREncodedContents.hash); - - OF_HASH_FINALIZE(hash); - - return hash; -} - -- (OFString *)description -{ - return [OFString stringWithFormat: - @"", - _tagClass, _tagNumber, _constructed, - _DEREncodedContents.description]; -} -@end DELETED src/OFData+ASN1DERValue.h Index: src/OFData+ASN1DERValue.h ================================================================== --- src/OFData+ASN1DERValue.h +++ src/OFData+ASN1DERValue.h @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "OFData.h" -#import "OFASN1Value.h" - -OF_ASSUME_NONNULL_BEGIN - -#ifdef __cplusplus -extern "C" { -#endif -extern int _OFData_ASN1DERValue_reference; -#ifdef __cplusplus -} -#endif - -@interface OFData (ASN1DERValue) -/*! - * @brief The data interpreted as ASN.1 in DER representation and parsed as an - * object. - * - * This is either an OFArray (for a sequence), an OFSet (for a set) or an - * OFASN1Value. - */ -@property (readonly, nonatomic) id ASN1DERValue; - -/*! - * @brief Parses the ASN.1 DER representation and returns it as an object. - * - * This is either an OFArray (for a sequence), an OFSet (for a set) or an - * OFASN1Value. - * - * @param depthLimit The maximum depth the parser should accept (defaults to 32 - * if not specified, 0 means no limit (insecure!)) - * @return The ASN.1 DER representation as an object - */ -- (id)ASN1DERValueWithDepthLimit: (size_t)depthLimit; -@end - -OF_ASSUME_NONNULL_END DELETED src/OFData+ASN1DERValue.m Index: src/OFData+ASN1DERValue.m ================================================================== --- src/OFData+ASN1DERValue.m +++ src/OFData+ASN1DERValue.m @@ -1,251 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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+ASN1DERValue.h" -#import "OFASN1BitString.h" -#import "OFASN1Boolean.h" -#import "OFASN1Enumerated.h" -#import "OFASN1IA5String.h" -#import "OFASN1Integer.h" -#import "OFASN1NumericString.h" -#import "OFASN1ObjectIdentifier.h" -#import "OFASN1OctetString.h" -#import "OFASN1PrintableString.h" -#import "OFASN1UTF8String.h" -#import "OFASN1Value.h" -#import "OFArray.h" -#import "OFNull.h" -#import "OFSet.h" - -#import "OFInvalidArgumentException.h" -#import "OFInvalidFormatException.h" -#import "OFOutOfRangeException.h" -#import "OFTruncatedDataException.h" - -enum { - ASN1_TAG_CONSTRUCTED_MASK = 0x20 -}; - -int _OFData_ASN1DERValue_reference; - -static size_t parseObject(OFData *self, id *object, size_t depthLimit); - -static OFArray * -parseSequence(OFData *contents, size_t depthLimit) -{ - OFMutableArray *ret = [OFMutableArray array]; - size_t count = contents.count; - - if (depthLimit == 0) - @throw [OFOutOfRangeException exception]; - - while (count > 0) { - id object; - size_t objectLength; - - objectLength = parseObject(contents, &object, depthLimit); - - count -= objectLength; - contents = [contents subdataWithRange: - of_range(objectLength, count)]; - - [ret addObject: object]; - } - - [ret makeImmutable]; - - return ret; -} - -static OFSet * -parseSet(OFData *contents, size_t depthLimit) -{ - OFMutableSet *ret = [OFMutableSet set]; - size_t count = contents.count; - OFData *previousObjectData = nil; - - if (depthLimit == 0) - @throw [OFOutOfRangeException exception]; - - while (count > 0) { - id object; - size_t objectLength; - OFData *objectData; - - objectLength = parseObject(contents, &object, depthLimit); - objectData = [contents subdataWithRange: - of_range(0, objectLength)]; - - if (previousObjectData != nil && - [objectData compare: previousObjectData] != - OF_ORDERED_DESCENDING) - @throw [OFInvalidFormatException exception]; - - count -= objectLength; - contents = [contents subdataWithRange: - of_range(objectLength, count)]; - - [ret addObject: object]; - - previousObjectData = objectData; - } - - [ret makeImmutable]; - - return ret; -} - -static size_t -parseObject(OFData *self, id *object, size_t depthLimit) -{ - const unsigned char *items = self.items; - size_t count = self.count; - unsigned char tag; - size_t contentsLength, bytesConsumed = 0; - Class valueClass; - OFData *contents; - - if (count < 2) - @throw [OFTruncatedDataException exception]; - - tag = *items++; - contentsLength = *items++; - bytesConsumed += 2; - - if (contentsLength > 127) { - uint_fast8_t lengthLength = contentsLength & 0x7F; - - if (lengthLength > sizeof(size_t)) - @throw [OFOutOfRangeException exception]; - - if (count - bytesConsumed < lengthLength) - @throw [OFTruncatedDataException exception]; - - if (lengthLength == 0 || - (lengthLength == 1 && items[0] < 0x80) || - (lengthLength >= 2 && items[0] == 0)) - @throw [OFInvalidFormatException exception]; - - contentsLength = 0; - - for (uint_fast8_t i = 0; i < lengthLength; i++) - contentsLength = (contentsLength << 8) | *items++; - - bytesConsumed += lengthLength; - - if (contentsLength <= 127) - @throw [OFInvalidFormatException exception]; - } - - if (count - bytesConsumed < contentsLength) - @throw [OFTruncatedDataException exception]; - - contents = [self subdataWithRange: - of_range(bytesConsumed, contentsLength)]; - bytesConsumed += contentsLength; - - switch (tag & ~ASN1_TAG_CONSTRUCTED_MASK) { - case OF_ASN1_TAG_NUMBER_BOOLEAN: - 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: - if (tag & ASN1_TAG_CONSTRUCTED_MASK) - @throw [OFInvalidFormatException exception]; - - if (contents.count != 0) - @throw [OFInvalidFormatException exception]; - - *object = [OFNull null]; - return bytesConsumed; - case OF_ASN1_TAG_NUMBER_OBJECT_IDENTIFIER: - valueClass = [OFASN1ObjectIdentifier class]; - break; - case OF_ASN1_TAG_NUMBER_ENUMERATED: - valueClass = [OFASN1Enumerated class]; - break; - case OF_ASN1_TAG_NUMBER_UTF8_STRING: - valueClass = [OFASN1UTF8String class]; - break; - case OF_ASN1_TAG_NUMBER_SEQUENCE: - if (!(tag & ASN1_TAG_CONSTRUCTED_MASK)) - @throw [OFInvalidFormatException exception]; - - *object = parseSequence(contents, depthLimit - 1); - return bytesConsumed; - case OF_ASN1_TAG_NUMBER_SET: - if (!(tag & ASN1_TAG_CONSTRUCTED_MASK)) - @throw [OFInvalidFormatException exception]; - - *object = parseSet(contents, depthLimit - 1); - return bytesConsumed; - case OF_ASN1_TAG_NUMBER_NUMERIC_STRING: - valueClass = [OFASN1NumericString class]; - break; - case OF_ASN1_TAG_NUMBER_PRINTABLE_STRING: - valueClass = [OFASN1PrintableString class]; - break; - case OF_ASN1_TAG_NUMBER_IA5_STRING: - valueClass = [OFASN1IA5String class]; - break; - default: - valueClass = [OFASN1Value class]; - break; - } - - *object = [[[valueClass alloc] - initWithTagClass: tag >> 6 - tagNumber: tag & 0x1F - constructed: tag & ASN1_TAG_CONSTRUCTED_MASK - DEREncodedContents: contents] autorelease]; - return bytesConsumed; -} - -@implementation OFData (ASN1DERValue) -- (id)ASN1DERValue -{ - return [self ASN1DERValueWithDepthLimit: 32]; -} - -- (id)ASN1DERValueWithDepthLimit: (size_t)depthLimit -{ - void *pool = objc_autoreleasePoolPush(); - id object; - - if (self.itemSize != 1) - @throw [OFInvalidArgumentException exception]; - - if (parseObject(self, &object, depthLimit) != self.count) - @throw [OFInvalidFormatException exception]; - - [object retain]; - - objc_autoreleasePoolPop(pool); - - return [object autorelease]; -} -@end Index: src/OFData.h ================================================================== --- src/OFData.h +++ src/OFData.h @@ -323,8 +323,7 @@ @end OF_ASSUME_NONNULL_END #import "OFMutableData.h" -#import "OFData+ASN1DERValue.h" #import "OFData+CryptoHashing.h" #import "OFData+MessagePackValue.h" Index: src/OFData.m ================================================================== --- src/OFData.m +++ src/OFData.m @@ -46,11 +46,10 @@ /* References for static linking */ void _references_to_categories_of_OFData(void) { - _OFData_ASN1DERValue_reference = 1; _OFData_CryptoHashing_reference = 1; _OFData_MessagePackValue_reference = 1; } @implementation OFData Index: src/OFNull.h ================================================================== --- src/OFNull.h +++ src/OFNull.h @@ -14,11 +14,10 @@ * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" -#import "OFASN1DERRepresentation.h" #import "OFJSONRepresentation.h" #import "OFMessagePackRepresentation.h" #import "OFSerialization.h" OF_ASSUME_NONNULL_BEGIN @@ -28,15 +27,15 @@ * * @brief A class for representing null values in collections. */ OF_SUBCLASSING_RESTRICTED @interface OFNull: OFObject + OFMessagePackRepresentation> /*! * @brief Returns an OFNull singleton. * * @return An OFNull singleton */ + (OFNull *)null; @end OF_ASSUME_NONNULL_END Index: src/OFNull.m ================================================================== --- src/OFNull.m +++ src/OFNull.m @@ -108,18 +108,10 @@ return [OFData dataWithItems: &type count: 1]; } -- (OFData *)ASN1DERRepresentation -{ - const unsigned char bytes[] = { OF_ASN1_TAG_NUMBER_NULL, 0 }; - - return [OFData dataWithItems: bytes - count: sizeof(bytes)]; -} - - (instancetype)autorelease { return self; } Index: src/ObjFW.h ================================================================== --- src/ObjFW.h +++ src/ObjFW.h @@ -127,22 +127,10 @@ #ifdef OF_WINDOWS # import "OFWindowsRegistryKey.h" #endif -#import "OFASN1BitString.h" -#import "OFASN1Boolean.h" -#import "OFASN1Enumerated.h" -#import "OFASN1IA5String.h" -#import "OFASN1Integer.h" -#import "OFASN1NumericString.h" -#import "OFASN1ObjectIdentifier.h" -#import "OFASN1OctetString.h" -#import "OFASN1PrintableString.h" -#import "OFASN1UTF8String.h" -#import "OFASN1Value.h" - #import "OFAllocFailedException.h" #import "OFException.h" #ifdef OF_HAVE_SOCKETS # import "OFAcceptFailedException.h" # import "OFAlreadyConnectedException.h" Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -8,12 +8,10 @@ ${PROG_NOINST}.nds PROG_NOINST = tests${PROG_SUFFIX} STATIC_LIB_NOINST = ${TESTS_STATIC_LIB} SRCS = ForwardingTests.m \ - OFASN1DERRepresentationTests.m \ - OFASN1DERValueTests.m \ OFArrayTests.m \ ${OFBLOCKTESTS_M} \ OFCharacterSetTests.m \ OFDataTests.m \ OFDateTests.m \ DELETED tests/OFASN1DERRepresentationTests.m Index: tests/OFASN1DERRepresentationTests.m ================================================================== --- tests/OFASN1DERRepresentationTests.m +++ tests/OFASN1DERRepresentationTests.m @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "TestsAppDelegate.h" - -static OFString *module; - -@implementation TestsAppDelegate (OFASN1DERRepresentationTests) -- (void)ASN1DERRepresentationTests -{ - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFData *data; - - module = @"OFASN1BitString"; - TEST(@"-[ASN1DERRepresentation]", - (data = [OFData dataWithItems: "\xFF\x00\xF8" - count: 3]) && - [[[OFASN1BitString bitStringWithBitStringValue: data - bitStringLength: 21] - ASN1DERRepresentation] isEqual: - [OFData dataWithItems: "\x03\x04\x03\xFF\x00\xF8" - count: 6]] && - (data = [OFData dataWithItems: "abcdefäöü" - count: 12]) && - [[[OFASN1BitString bitStringWithBitStringValue: data - bitStringLength: 12 * 8] - ASN1DERRepresentation] isEqual: - [OFData dataWithItems: "\x03\x0D\x00" "abcdefäöü" - count: 15]] && - (data = [OFData dataWithItems: "" - count: 0]) && - [[[OFASN1BitString bitStringWithBitStringValue: data - bitStringLength: 0] - ASN1DERRepresentation] isEqual: - [OFData dataWithItems: "\x03\x01\x00" - count: 3]]) - - module = @"OFASN1Boolean"; - TEST(@"-[ASN1DERRepresentation]", - [[[OFASN1Boolean booleanWithBooleanValue: false] - ASN1DERRepresentation] isEqual: - [OFData dataWithItems: "\x01\x01\x00" - count: 3]] && - [[[OFASN1Boolean booleanWithBooleanValue: true] - ASN1DERRepresentation] isEqual: - [OFData dataWithItems: "\x01\x01\xFF" - count: 3]]) - - module = @"OFNull"; - TEST(@"-[OFASN1DERRepresentation]", - [[[OFNull null] ASN1DERRepresentation] isEqual: - [OFData dataWithItems: "\x05\x00" - count: 2]]) - - [pool drain]; -} -@end DELETED tests/OFASN1DERValueTests.m Index: tests/OFASN1DERValueTests.m ================================================================== --- tests/OFASN1DERValueTests.m +++ tests/OFASN1DERValueTests.m @@ -1,437 +0,0 @@ -/* - * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, - * 2018, 2019 - * 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 "TestsAppDelegate.h" - -static OFString *module = @"OFData+ASN1DERValue"; - -@implementation TestsAppDelegate (OFASN1DERValueTests) -- (void)ASN1DERValueTests -{ - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFASN1BitString *bitString; - OFArray *array; - OFSet *set; - OFEnumerator *enumerator; - - /* Boolean */ - 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]) - - /* Integer */ - 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(@"Detection of invalid integer #1", - OFInvalidFormatException, [[OFData dataWithItems: "\x02\x02\x00\x00" - count: 4] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of invalid integer #2", - OFInvalidFormatException, [[OFData dataWithItems: "\x02\x02\x00\x7F" - count: 4] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection 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]) - - /* Bit string */ - 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 == 95 && - (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]) - - /* Octet string */ - 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]) - - /* Null */ - TEST(@"Parsing of null", - [[[OFData dataWithItems: "\x05\x00" - count: 2] ASN1DERValue] isEqual: [OFNull null]]) - - EXPECT_EXCEPTION(@"Detection of invalid null", - OFInvalidFormatException, [[OFData dataWithItems: "\x05\x01\x00" - count: 3] ASN1DERValue]) - - /* Object Identifier */ - TEST(@"Parsing of Object Identifier", - (array = [[[OFData dataWithItems: "\x06\x01\x27" - count: 3] ASN1DERValue] - subidentifiers]) && array.count == 2 && - [[array objectAtIndex: 0] uIntMaxValue] == 0 && - [[array objectAtIndex: 1] uIntMaxValue] == 39 && - (array = [[[OFData dataWithItems: "\x06\x01\x4F" - count: 3] ASN1DERValue] - subidentifiers]) && array.count == 2 && - [[array objectAtIndex: 0] uIntMaxValue] == 1 && - [[array objectAtIndex: 1] uIntMaxValue] == 39 && - (array = [[[OFData dataWithItems: "\x06\x02\x88\x37" - count: 4] ASN1DERValue] - subidentifiers]) && array.count == 2 && - [[array objectAtIndex: 0] uIntMaxValue] == 2 && - [[array objectAtIndex: 1] uIntMaxValue] == 999 && - (array = [[[OFData dataWithItems: "\x06\x09\x2A\x86\x48\x86\xF7\x0D" - "\x01\x01\x0B" - count: 11] ASN1DERValue] - subidentifiers]) && array.count == 7 && - [[array objectAtIndex: 0] uIntMaxValue] == 1 && - [[array objectAtIndex: 1] uIntMaxValue] == 2 && - [[array objectAtIndex: 2] uIntMaxValue] == 840 && - [[array objectAtIndex: 3] uIntMaxValue] == 113549 && - [[array objectAtIndex: 4] uIntMaxValue] == 1 && - [[array objectAtIndex: 5] uIntMaxValue] == 1 && - [[array objectAtIndex: 6] uIntMaxValue] == 11) - - EXPECT_EXCEPTION(@"Detection of invalid Object Identifier #1", - OFInvalidFormatException, [[OFData dataWithItems: "\x06\x01\x81" - count: 3] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of invalid Object Identifier #2", - OFInvalidFormatException, [[OFData dataWithItems: "\x06\x02\x80\x01" - count: 4] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of out of range Object Identifier", - OFOutOfRangeException, - [[OFData dataWithItems: "\x06\x0A\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" - "\xFF\x7F" - count: 12] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of truncated Object Identifier", - OFTruncatedDataException, [[OFData dataWithItems: "\x06\x02\x00" - count: 3] ASN1DERValue]) - - /* Enumerated */ - TEST(@"Parsing of enumerated", - [[[OFData dataWithItems: "\x0A\x00" - count: 2] ASN1DERValue] integerValue] == 0 && - [[[OFData dataWithItems: "\x0A\x01\x01" - count: 3] ASN1DERValue] integerValue] == 1 && - [[[OFData dataWithItems: "\x0A\x02\x01\x04" - count: 4] ASN1DERValue] integerValue] == 260 && - [[[OFData dataWithItems: "\x0A\x01\xFF" - count: 3] ASN1DERValue] integerValue] == -1 && - [[[OFData dataWithItems: "\x0A\x03\xFF\x00\x00" - count: 5] ASN1DERValue] integerValue] == -65536 && - (uintmax_t)[[[OFData dataWithItems: "\x0A\x09\x00\xFF\xFF\xFF\xFF" - "\xFF\xFF\xFF\xFF" - count: 11] ASN1DERValue] - integerValue] == UINTMAX_MAX) - - EXPECT_EXCEPTION(@"Detection of invalid enumerated #1", - OFInvalidFormatException, [[OFData dataWithItems: "\x0A\x02\x00\x00" - count: 4] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of invalid enumerated #2", - OFInvalidFormatException, [[OFData dataWithItems: "\x0A\x02\x00\x7F" - count: 4] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of invalid enumerated #3", - OFInvalidFormatException, [[OFData dataWithItems: "\x0A\x02\xFF\x80" - count: 4] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of out of range enumerated", - OFOutOfRangeException, - [[OFData dataWithItems: "\x0A\x09\x01" - "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" - count: 11] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of truncated enumerated", - OFTruncatedDataException, [[OFData dataWithItems: "\x0A\x02\x00" - count: 3] ASN1DERValue]) - - /* UTF-8 string */ - 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]) - - /* Sequence */ - 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(@"Detection of truncated sequence #1", - OFTruncatedDataException, [[OFData dataWithItems: "\x30\x01" - count: 2] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of truncated sequence #2", - OFTruncatedDataException, - [[OFData dataWithItems: "\x30\x04\x02\x01\x01\x00\x00" - count: 7] ASN1DERValue]) - - /* Set */ - TEST(@"Parsing of set", - (set = [[OFData dataWithItems: "\x31\x00" - count: 2] ASN1DERValue]) && - [set isKindOfClass: [OFSet class]] && set.count == 0 && - (set = [[OFData dataWithItems: "\x31\x09\x02\x01\x7B\x0C\x04Test" - count: 11] ASN1DERValue]) && - [set isKindOfClass: [OFSet class]] && set.count == 2 && - (enumerator = [set objectEnumerator]) && - [[enumerator nextObject] integerValue] == 123 && - [[[enumerator nextObject] stringValue] isEqual: @"Test"]) - - EXPECT_EXCEPTION(@"Detection of invalid set", - OFInvalidFormatException, - [[OFData dataWithItems: "\x31\x06\x02\x01\x02\x02\x01\x01" - count: 8] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of truncated set #1", - OFTruncatedDataException, [[OFData dataWithItems: "\x31\x01" - count: 2] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of truncated set #2", - OFTruncatedDataException, - [[OFData dataWithItems: "\x31\x04\x02\x01\x01\x00\x00" - count: 7] ASN1DERValue]) - - /* NumericString */ - TEST(@"Parsing of NumericString", - [[[[OFData dataWithItems: "\x12\x0B" "12345 67890" - count: 13] ASN1DERValue] numericStringValue] - isEqual: @"12345 67890"] && - [[[[OFData dataWithItems: "\x12\x81\x80" "0000000000000000000000000" - "0000000000000000000000000000000000000000" - "0000000000000000000000000000000000000000" - "00000000000000000000000" - count: 131] ASN1DERValue] numericStringValue] - isEqual: @"00000000000000000000000000000000000000000000000000000000" - @"00000000000000000000000000000000000000000000000000000000" - @"0000000000000000"]) - - EXPECT_EXCEPTION(@"Detection of invalid NumericString", - OFInvalidEncodingException, - [[OFData dataWithItems: "\x12\x02." - count: 4] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of out of range NumericString", - OFOutOfRangeException, - [[OFData dataWithItems: "\x12\x89" - "\x01\x01\x01\x01\x01\x01\x01\x01\x01" - count: 11] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of truncated NumericString", - OFTruncatedDataException, [[OFData dataWithItems: "\x12\x01" - count: 2] ASN1DERValue]) - - /* PrintableString */ - TEST(@"Parsing of PrintableString", - [[[[OFData dataWithItems: "\x13\x0CHello World." - count: 14] ASN1DERValue] printableStringValue] - isEqual: @"Hello World."] && - [[[[OFData dataWithItems: "\x13\x81\x80 '()+,-./:=?abcdefghijklmnop" - "qrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '()" - "+,-./:=?abcdefghijklmnopqrstuvwxyzABCDEF" - "GHIJKLMNOPQRSTUVWXYZ" - count: 131] ASN1DERValue] printableStringValue] - isEqual: @" '()+,-./:=?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQR" - @"STUVWXYZ '()+,-./:=?abcdefghijklmnopqrstuvwxyzABCDEFGHIJ" - @"KLMNOPQRSTUVWXYZ"]) - - EXPECT_EXCEPTION(@"Detection of invalid PrintableString", - OFInvalidEncodingException, - [[OFData dataWithItems: "\x13\x02;" - count: 4] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of out of range PrintableString", - OFOutOfRangeException, - [[OFData dataWithItems: "\x13\x89" - "\x01\x01\x01\x01\x01\x01\x01\x01\x01" - count: 11] ASN1DERValue]) - - EXPECT_EXCEPTION(@"Detection of truncated PrintableString", - OFTruncatedDataException, [[OFData dataWithItems: "\x13\x01" - count: 2] ASN1DERValue]) - - /* IA5String */ - 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,18 +84,10 @@ inModule: (OFString *)module; - (void)outputFailure: (OFString *)test inModule: (OFString *)module; @end -@interface TestsAppDelegate (OFASN1DERValueTests) -- (void)ASN1DERValueTests; -@end - -@interface TestsAppDelegate (OFASN1DERRepresentationTests) -- (void)ASN1DERRepresentationTests; -@end - @interface TestsAppDelegate (OFArrayTests) - (void)arrayTests; @end @interface TestsAppDelegate (OFBlockTests) Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -434,12 +434,10 @@ #ifdef OF_HAVE_FILES [self serializationTests]; #endif [self JSONTests]; [self propertyListTests]; - [self ASN1DERValueTests]; - [self ASN1DERRepresentationTests]; #if defined(OF_HAVE_PLUGINS) [self pluginTests]; #endif #ifdef OF_WINDOWS [self windowsRegistryKeyTests];