Overview
Context
Changes
Modified src/Makefile
from [58eab480cd]
to [fd6e700a0b].
︙ | | |
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
-
|
STATIC_LIB = ${OBJFW_STATIC_LIB}
FRAMEWORK = ${OBJFW_FRAMEWORK}
LIB_MAJOR = ${OBJFW_LIB_MAJOR}
LIB_MINOR = ${OBJFW_LIB_MINOR}
LIB_PATCH = ${OBJFW_LIB_PATCH}
SRCS = OFASN1BitString.m \
OFASN1Boolean.m \
OFASN1Enumerated.m \
OFASN1IA5String.m \
OFASN1Integer.m \
OFASN1NumericString.m \
OFASN1ObjectIdentifier.m \
OFASN1OctetString.m \
OFASN1PrintableString.m \
|
︙ | | |
Deleted src/OFASN1Boolean.h version [b9c65fd898].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
*
* 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.
*/
OF_SUBCLASSING_RESTRICTED
@interface OFASN1Boolean: OFObject <OFASN1DERRepresentation>
{
bool _boolValue;
}
/**
* @brief The value of the Boolean.
*/
@property (readonly, nonatomic) bool boolValue;
/**
* @brief Creates an ASN.1 Boolean with the specified Boolean value.
*
* @param bool_ The value of the Boolean
* @return A new, autoreleased OFASN1Boolean
*/
+ (instancetype)booleanWithBool: (bool)bool_;
- (instancetype)init OF_UNAVAILABLE;
/**
* @brief Initializes an already allocated ASN.1 Boolean with the specified
* Boolean value.
*
* @param bool_ The value of the Boolean
* @return An initialized OFASN1Boolean
*/
- (instancetype)initWithBool: (bool)bool_ 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: (OFASN1TagClass)tagClass
tagNumber: (OFASN1TagNumber)tagNumber
constructed: (bool)constructed
DEREncodedContents: (OFData *)DEREncodedContents;
@end
OF_ASSUME_NONNULL_END
|
Deleted src/OFASN1Boolean.m version [574b738a35].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
*
* 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 boolValue = _boolValue;
+ (instancetype)booleanWithBool: (bool)bool_
{
return [[[self alloc] initWithBool: bool_] autorelease];
}
- (instancetype)initWithBool: (bool)bool_
{
self = [super init];
_boolValue = bool_;
return self;
}
- (instancetype)initWithTagClass: (OFASN1TagClass)tagClass
tagNumber: (OFASN1TagNumber)tagNumber
constructed: (bool)constructed
DEREncodedContents: (OFData *)DEREncodedContents
{
unsigned char value;
@try {
if (tagClass != OFASN1TagClassUniversal ||
tagNumber != OFASN1TagNumberBoolean || 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 initWithBool: !!value];
}
- (instancetype)init
{
OF_INVALID_INIT_METHOD
}
- (OFData *)ASN1DERRepresentation
{
char buffer[] = {
OFASN1TagNumberBoolean,
1,
(_boolValue ? 0xFF : 0x00)
};
return [OFData dataWithItems: buffer count: sizeof(buffer)];
}
- (bool)isEqual: (id)object
{
OFASN1Boolean *boolean;
if (object == self)
return true;
if (![object isKindOfClass: [OFASN1Boolean class]])
return false;
boolean = object;
if (boolean->_boolValue != _boolValue)
return false;
return true;
}
- (unsigned long)hash
{
return _boolValue;
}
- (OFString *)description
{
return (_boolValue
? @"<OFASN1Boolean: true>"
: @"<OFASN1Boolean: false>");
}
@end
|
Modified src/OFData+ASN1DERParsing.m
from [b0aa916c3e]
to [d08f994c7d].
︙ | | |
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
-
+
|
* file.
*/
#include "config.h"
#import "OFData+ASN1DERParsing.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 "OFNumber.h"
#import "OFSet.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
|
︙ | | |
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
@throw [OFTruncatedDataException exception];
contents = [self subdataWithRange:
OFMakeRange(bytesConsumed, contentsLength)];
bytesConsumed += contentsLength;
switch (tag & ~tagConstructedMask) {
case OFASN1TagNumberBoolean:
valueClass = [OFASN1Boolean class];
break;
case OFASN1TagNumberBoolean:;
unsigned char boolValue;
if (tag & tagConstructedMask)
@throw [OFInvalidFormatException exception];
if (contents.count != 1)
@throw [OFInvalidFormatException exception];
boolValue = *(unsigned char *)[contents itemAtIndex: 0];
if (boolValue != 0 && boolValue != 0xFF)
@throw [OFInvalidFormatException exception];
*object = [OFNumber numberWithBool: boolValue];
return bytesConsumed;
case OFASN1TagNumberInteger:
valueClass = [OFASN1Integer class];
break;
case OFASN1TagNumberBitString:
valueClass = [OFASN1BitString class];
break;
case OFASN1TagNumberOctetString:
|
︙ | | |
Modified src/OFNumber.h
from [e8b2d0d74a]
to [bed7e6a8c1].
︙ | | |
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
+
-
-
+
+
|
#include "objfw-defs.h"
#ifdef OF_HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#import "OFASN1DERRepresentation.h"
#import "OFJSONRepresentation.h"
#import "OFMessagePackRepresentation.h"
#import "OFValue.h"
OF_ASSUME_NONNULL_BEGIN
/** @file */
/**
* @class OFNumber OFNumber.h ObjFW/OFNumber.h
*
* @brief Provides a way to store a number in an object.
*/
@interface OFNumber: OFValue <OFComparing, OFJSONRepresentation,
OFMessagePackRepresentation>
@interface OFNumber: OFValue <OFComparing, OFASN1DERRepresentation,
OFJSONRepresentation, OFMessagePackRepresentation>
/**
* @brief The OFNumber as a `bool`.
*/
@property (readonly, nonatomic) bool boolValue;
/**
* @brief The OFNumber as a `signed char`.
|
︙ | | |
Modified src/OFNumber.m
from [e5b90c57f3]
to [f54894ca09].
︙ | | |
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
+
|
#import "OFConcreteNumber.h"
#import "OFData.h"
#import "OFString.h"
#import "OFTaggedPointerNumber.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"
#import "OFOutOfRangeException.h"
@interface OFNumber ()
- (OFString *)
of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options
depth: (size_t)depth;
@end
|
︙ | | |
706
707
708
709
710
711
712
713
714
715
716
717
718
719
|
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
return [OFString stringWithFormat: @"%lld", self.longLongValue];
if (isUnsigned(self))
return [OFString stringWithFormat: @"%llu",
self.unsignedLongLongValue];
@throw [OFInvalidFormatException exception];
}
- (OFData *)ASN1DERRepresentation
{
if (self.objCType[0] == 'B' && self.objCType[1] == '\0') {
char buffer[] = {
OFASN1TagNumberBoolean,
1,
(self.boolValue ? 0xFF : 0x00)
};
return [OFData dataWithItems: buffer count: sizeof(buffer)];
} else
@throw [OFNotImplementedException exceptionWithSelector: _cmd
object: self];
}
- (OFString *)JSONRepresentation
{
return [self of_JSONRepresentationWithOptions: 0 depth: 0];
}
- (OFString *)JSONRepresentationWithOptions:
|
︙ | | |
Modified src/ObjFW.h
from [010bad87c9]
to [72efcf8773].
︙ | | |
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
-
|
#import "OFMatrix4x4.h"
#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"
|
︙ | | |
Modified tests/OFASN1DERRepresentationTests.m
from [08cf18d206]
to [40dae6ed10].
︙ | | |
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
-
-
-
+
+
+
-
+
|
ASN1DERRepresentation] isEqual:
[OFData dataWithItems: "\x03\x0D\x00" "abcdefäöü" count: 15]] &&
(data = [OFData dataWithItems: "" count: 0]) &&
[[[OFASN1BitString bitStringWithBitString: data length: 0]
ASN1DERRepresentation] isEqual:
[OFData dataWithItems: "\x03\x01\x00" count: 3]])
module = @"OFASN1Boolean";
TEST(@"-[ASN1DERRepresentation]",
[[[OFASN1Boolean booleanWithBool: false] ASN1DERRepresentation]
module = @"OFNumber";
TEST(@"-[ASN1DERRepresentation] for bool",
[[[OFNumber numberWithBool: false] ASN1DERRepresentation]
isEqual: [OFData dataWithItems: "\x01\x01\x00" count: 3]] &&
[[[OFASN1Boolean booleanWithBool: true] ASN1DERRepresentation]
[[[OFNumber numberWithBool: true] ASN1DERRepresentation]
isEqual: [OFData dataWithItems: "\x01\x01\xFF" count: 3]])
module = @"OFNull";
TEST(@"-[OFASN1DERRepresentation]",
[[[OFNull null] ASN1DERRepresentation] isEqual:
[OFData dataWithItems: "\x05\x00" count: 2]])
objc_autoreleasePoolPop(pool);
}
@end
|