Changes In Branch 1.0
Through [98c3748090]
Excluding Merge-Ins
This is equivalent to a diff from
28eda87705
to 98c3748090
Modified .fossil-settings/clean-glob
from [8cc139c114]
to [31e6970fe4].
︙ | | |
42
43
44
45
46
47
48
49
|
42
43
44
45
46
47
48
|
-
|
tests/tests.arm9
tests/tests.nds
utils/objfw-config
utils/ofarc/ofarc
utils/ofdns/ofdns
utils/ofhash/ofhash
utils/ofhttp/ofhttp
utils/ofsock/ofsock
|
Modified .fossil-settings/ignore-glob
from [9af6ddf1c8]
to [8164021017].
︙ | | |
47
48
49
50
51
52
53
54
|
47
48
49
50
51
52
53
|
-
|
tests/tests.arm9
tests/tests.nds
utils/objfw-config
utils/ofarc/ofarc
utils/ofdns/ofdns
utils/ofhash/ofhash
utils/ofhttp/ofhttp
utils/ofsock/ofsock
|
Modified .gitignore
from [1a9a1a32ef]
to [2065cc018e].
︙ | | |
47
48
49
50
51
52
53
54
|
47
48
49
50
51
52
53
|
-
|
tests/tests.arm9
tests/tests.nds
utils/objfw-config
utils/ofarc/ofarc
utils/ofdns/ofdns
utils/ofhash/ofhash
utils/ofhttp/ofhttp
utils/ofsock/ofsock
|
Modified .travis.yml
from [0619e15749]
to [3f182f2f77].
︙ | | |
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
|
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
-
-
-
|
# macOS
- os: osx
osx_image: xcode11.2
language: objective-c
env:
- no32bit=1
- noruntime=1 # Broken compiler in this version of Xcode
- os: osx
osx_image: xcode11.1
language: objective-c
env:
- no32bit=1
- noruntime=1 # Broken compiler in this version of Xcode
- os: osx
osx_image: xcode11
language: objective-c
env:
- no32bit=1
- noruntime=1 # Broken compiler in this version of Xcode
- os: osx
osx_image: xcode10.3
language: objective-c
env:
- no32bit=1
- os: osx
osx_image: xcode10.2
|
︙ | | |
Modified .travis/before_install.sh
from [479fa2374a]
to [305e68ec8c].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
-
-
|
#!/bin/sh
if [ "$TRAVIS_OS_NAME" = "linux" -a -z "$config" ]; then
case "$TRAVIS_CPU_ARCH" in
amd64 | s390x)
pkgs="gobjc-multilib"
;;
*)
pkgs="gobjc"
;;
esac
pkgs="$pkgs libsctp-dev"
if grep precise /etc/lsb-release >/dev/null; then
pkgs="$pkgs ipx"
fi
# We don't need any of them and they're often broken.
sudo rm -f /etc/apt/sources.list.d/*
|
︙ | | |
Modified .travis/script.sh
from [6432052d0a]
to [1407ed37b4].
︙ | | |
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
|
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
build_mac_32_64 --disable-threads --disable-sockets
build_mac_32_64 --disable-threads --disable-files
build_mac_32_64 --disable-threads --disable-sockets --disable-files
build_mac_32_64 --disable-sockets
build_mac_32_64 --disable-sockets --disable-files
build_mac_32_64 --disable-files
build_mac_32_64 --disable-shared
if [ -z "$noruntime" ]; then
build_mac_32_64 --enable-runtime
build_mac_32_64 --enable-runtime --enable-seluid24
build_mac_32_64 --enable-runtime --disable-threads
build_mac_32_64 --enable-runtime --disable-threads \
--disable-sockets
build_mac_32_64 --enable-runtime --disable-threads \
--disable-files
build_mac_32_64 --enable-runtime --disable-threads \
--disable-sockets --disable-files
build_mac_32_64 --enable-runtime --disable-sockets
build_mac_32_64 --enable-runtime --disable-sockets \
--disable-files
build_mac_32_64 --enable-runtime --disable-files
build_mac_32_64 --enable-runtime --disable-shared
build_mac_32_64 --enable-runtime --disable-shared \
--enable-seluid24
fi
fi
if [ "$config" = "ios" ]; then
if xcodebuild -version | grep 'Xcode 6' >/dev/null; then
export CPPFLAGS="-D_Null_unspecified=__null_unspecified"
export CPPFLAGS="$CPPFLAGS -D_Nullable=__nullable"
export CPPFLAGS="$CPPFLAGS -D_Nonnull=__nonnull"
|
︙ | | |
Modified configure.ac
from [6622324a1c]
to [d8967fc2a8].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
-
+
-
+
-
|
AC_INIT(ObjFW, 1.1-dev, js@nil.im)
AC_INIT(ObjFW, 1.0, js@nil.im)
AC_CONFIG_SRCDIR(src)
AC_CONFIG_AUX_DIR(build-aux)
AC_CONFIG_MACRO_DIR(build-aux/m4)
AC_DEFINE(OBJFW_VERSION_MAJOR, 1, [The major version of ObjFW])
AC_DEFINE(OBJFW_VERSION_MINOR, 1, [The minor version of ObjFW])
AC_DEFINE(OBJFW_VERSION_MINOR, 0, [The minor version of ObjFW])
dnl This may only be set to 1.1 once 1.1 is released
AC_SUBST(BUNDLE_VERSION, 1.0.0)
AC_SUBST(BUNDLE_SHORT_VERSION, 1.0)
for i in configure.ac build-aux/m4/*; do
AS_IF([test $i -nt configure], [
AC_MSG_ERROR([$i is newer than configure! Run ./autogen.sh!])
])
|
︙ | | |
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
|
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
-
|
AC_ARG_ENABLE(shared,
AS_HELP_STRING([--disable-shared], [do not build shared library]))
AS_IF([test x"$enable_shared" != x"no"], [
BUILDSYS_SHARED_LIB
AC_SUBST(OBJFW_SHARED_LIB, "${LIB_PREFIX}objfw${LIB_SUFFIX}")
AC_SUBST(EXCEPTIONS_LIB_A, "exceptions.lib.a")
AC_SUBST(FORWARDING_LIB_A, "forwarding.lib.a")
AC_SUBST(INVOCATION_LIB_A, "invocation.lib.a")
AC_SUBST(LOOKUP_ASM_LIB_A, "lookup-asm.lib.a")
BUILDSYS_FRAMEWORK([
AC_SUBST(OBJFW_FRAMEWORK, "ObjFW.framework")
build_framework="yes"
])
], [
|
︙ | | |
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
|
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
|
-
-
|
AC_ARG_ENABLE(amiga-lib,
AS_HELP_STRING([--disable-amiga-lib], [do not build Amiga library]))
AS_IF([test x"$supports_amiga_lib" != x"yes"], [enable_amiga_lib="no"])
AS_IF([test x"$enable_amiga_lib" != x"no"], [
AC_SUBST(OBJFW_STATIC_LIB, "libobjfw.a")
AC_SUBST(EXCEPTIONS_A, "exceptions.a")
AC_SUBST(FORWARDING_A, "forwarding.a")
AC_SUBST(INVOCATION_A, "invocation.a")
AC_SUBST(LOOKUP_ASM_AMIGALIB_A, "lookup-asm.amigalib.a")
])
AC_ARG_ENABLE(static, AS_HELP_STRING([--enable-static], [build static library]))
AS_IF([test x"$enable_shared" = x"no" -a x"$enable_amiga_lib" = x"no"], [
enable_static="yes"
])
AS_IF([test x"$enable_static" = x"yes"], [
AC_SUBST(OBJFW_STATIC_LIB, "libobjfw.a")
AC_SUBST(EXCEPTIONS_A, "exceptions.a")
AC_SUBST(FORWARDING_A, "forwarding.a")
AC_SUBST(INVOCATION_A, "invocation.a")
AC_SUBST(LOOKUP_ASM_A, "lookup-asm.a")
])
AC_DEFINE_UNQUOTED(PLUGIN_SUFFIX, "$PLUGIN_SUFFIX", [Suffix for plugins])
AS_IF([test x"$enable_files" != x"no" -a x"$PLUGIN_SUFFIX" != x""], [
AC_SUBST(USE_SRCS_PLUGINS, '${SRCS_PLUGINS}')
AC_SUBST(TESTPLUGIN, "plugin")
|
︙ | | |
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
|
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
|
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
|
CPPFLAGS="-D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS $CPPFLAGS"
;;
esac
objc_runtime="ObjFW runtime"
AC_CHECK_HEADER(objc/objc.h)
AC_MSG_CHECKING(which Objective C runtime to use)
AC_ARG_ENABLE(runtime,
AS_HELP_STRING([--enable-runtime], [use the included runtime]))
AC_ARG_ENABLE(seluid24,
AS_HELP_STRING([--enable-seluid24],
[use 24 bit instead of 16 bit for selector UIDs]))
AS_IF([test x"$enable_runtime" != x"yes"], [
AS_IF([test x"$ac_cv_header_objc_objc_h" = x"yes"], [
AC_EGREP_CPP(egrep_cpp_yes, [
#import <objc/objc.h>
AS_IF([test x"$ac_cv_header_objc_objc_h" = x"yes"], [
AC_EGREP_CPP(egrep_cpp_yes, [
#import <objc/objc.h>
#ifdef OBJC_BOOL_DEFINED
egrep_cpp_yes
#endif
], [
objc_runtime="Apple runtime"
], [
dnl We don't want the GNU runtime
:
#ifdef OBJC_BOOL_DEFINED
egrep_cpp_yes
#endif
], [
objc_runtime="Apple runtime"
], [
dnl We don't want the GNU runtime
:
])
])
])
AC_MSG_RESULT($objc_runtime)
case "$objc_runtime" in
"ObjFW runtime")
AC_DEFINE(OF_OBJFW_RUNTIME, 1,
|
︙ | | |
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
|
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
|
-
-
-
-
-
-
|
AC_DEFINE(OF_HAVE_NETINET_IN_H, 1,
[Whether we have netinet/in.h])
])
AC_CHECK_HEADER(netinet/tcp.h, [
AC_DEFINE(OF_HAVE_NETINET_TCP_H, 1,
[Whether we have netinet/tcp.h])
])
AC_CHECK_HEADER(netinet/sctp.h, [
AC_DEFINE(OF_HAVE_SCTP, 1, [Whether we have SCTP])
AC_DEFINE(OF_HAVE_NETINET_SCTP_H, 1,
[Whether we have netinet/sctp.h])
AC_SUBST(USE_SRCS_SCTP, '${SRCS_SCTP}')
])
AC_CHECK_HEADERS([arpa/inet.h netdb.h])
AC_CHECK_HEADER(netipx/ipx.h, [
AC_DEFINE(OF_HAVE_NETIPX_IPX_H, 1,
[Whether we have netipx/ipx.h])
])
AC_CHECK_MEMBER([struct sockaddr_in6.sin6_addr], [
|
︙ | | |
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
|
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
|
-
|
AC_SUBST(OF_HTTP_CLIENT_TESTS_M, "OFHTTPClientTests.m")
])
AC_SUBST(OFDNS, "ofdns")
AS_IF([test x"$enable_files" != x"no"], [
AC_SUBST(OFHTTP, "ofhttp")
])
AC_SUBST(OFSOCK, "ofsock")
])
AC_DEFUN([CHECK_BUILTIN_BSWAP], [
AC_MSG_CHECKING(for __builtin_bswap$1)
AC_LINK_IFELSE([
AC_LANG_PROGRAM([
#include <stdint.h>
|
︙ | | |
Modified extra.mk.in
from [104b6a10da]
to [661bc83acc].
1
2
3
4
5
6
7
8
9
10
11
12
|
1
2
3
4
5
6
7
8
9
10
11
12
|
-
+
|
OBJFW_SHARED_LIB = @OBJFW_SHARED_LIB@
OBJFW_STATIC_LIB = @OBJFW_STATIC_LIB@
OBJFW_FRAMEWORK = @OBJFW_FRAMEWORK@
OBJFW_LIB_MAJOR = 9
OBJFW_LIB_MINOR = 1
OBJFW_LIB_MINOR = 0
OBJFW_LIB_MAJOR_MINOR = ${OBJFW_LIB_MAJOR}.${OBJFW_LIB_MINOR}
OBJFWRT_SHARED_LIB = @OBJFWRT_SHARED_LIB@
OBJFWRT_STATIC_LIB = @OBJFWRT_STATIC_LIB@
OBJFWRT_FRAMEWORK = @OBJFWRT_FRAMEWORK@
OBJFWRT_AMIGA_LIB = @OBJFWRT_AMIGA_LIB@
OBJFWRT_LIB_MAJOR = 1
|
︙ | | |
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
-
-
|
LOOKUP_ASM_LIB_A = @LOOKUP_ASM_LIB_A@
LOOKUP_ASM_AMIGALIB_A = @LOOKUP_ASM_AMIGALIB_A@
MAP_LDFLAGS = @MAP_LDFLAGS@
OFARC = @OFARC@
OFDNS = @OFDNS@
OFHASH = @OFHASH@
OFHTTP = @OFHTTP@
OFSOCK = @OFSOCK@
OF_BLOCK_TESTS_M = @OF_BLOCK_TESTS_M@
OF_EPOLL_KERNEL_EVENT_OBSERVER_M = @OF_EPOLL_KERNEL_EVENT_OBSERVER_M@
OF_HTTP_CLIENT_TESTS_M = @OF_HTTP_CLIENT_TESTS_M@
OF_KQUEUE_KERNEL_EVENT_OBSERVER_M = @OF_KQUEUE_KERNEL_EVENT_OBSERVER_M@
OF_POLL_KERNEL_EVENT_OBSERVER_M = @OF_POLL_KERNEL_EVENT_OBSERVER_M@
OF_PROCESS_M = @OF_PROCESS_M@
OF_SCTP_SOCKET_M = @OF_SCTP_SOCKET_M@
OF_SELECT_KERNEL_EVENT_OBSERVER_M = @OF_SELECT_KERNEL_EVENT_OBSERVER_M@
REEXPORT_RUNTIME = @REEXPORT_RUNTIME@
REEXPORT_RUNTIME_FRAMEWORK = @REEXPORT_RUNTIME_FRAMEWORK@
RUNTIME = @RUNTIME@
RUNTIME_ARC_TESTS_M = @RUNTIME_ARC_TESTS_M@
RUNTIME_AUTORELEASE_M = @RUNTIME_AUTORELEASE_M@
RUNTIME_FRAMEWORK_LIBS = @RUNTIME_FRAMEWORK_LIBS@
|
︙ | | |
70
71
72
73
74
75
76
77
78
79
80
81
|
68
69
70
71
72
73
74
75
76
77
78
|
-
|
TESTS_LIBS = @TESTS_LIBS@
TESTS_STATIC_LIB = @TESTS_STATIC_LIB@
UNICODE_M = @UNICODE_M@
USE_INCLUDES_ATOMIC = @USE_INCLUDES_ATOMIC@
USE_SRCS_FILES = @USE_SRCS_FILES@
USE_SRCS_IPX = @USE_SRCS_IPX@
USE_SRCS_PLUGINS = @USE_SRCS_PLUGINS@
USE_SRCS_SCTP = @USE_SRCS_SCTP@
USE_SRCS_SOCKETS = @USE_SRCS_SOCKETS@
USE_SRCS_THREADS = @USE_SRCS_THREADS@
USE_SRCS_WINDOWS = @USE_SRCS_WINDOWS@
WRAPPER = @WRAPPER@
|
Modified src/Makefile
from [cec3ab337b]
to [f75f17d137].
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
|
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
|
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
|
include ../extra.mk
SUBDIRS = ${RUNTIME} exceptions encodings forwarding invocation
SUBDIRS = ${RUNTIME} exceptions encodings forwarding
SUBDIRS_AFTER = ${BRIDGE}
DISTCLEAN = Info.plist objfw-defs.h
SHARED_LIB = ${OBJFW_SHARED_LIB}
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 \
OFBlock.m \
OFCharacterSet.m \
OFColor.m \
OFConstantString.m \
OFCountedSet.m \
OFData.m \
OFData+ASN1DERParsing.m \
OFData+CryptoHashing.m \
OFData+MessagePackParsing.m \
OFDate.m \
OFDictionary.m \
OFEnumerator.m \
OFFileManager.m \
OFGZIPStream.m \
|
︙ | | |
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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
185
|
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
-
-
+
-
-
-
|
OFINIFile.m \
OFSettings.m \
OFString+PathAdditions.m
SRCS_IPX = OFIPXSocket.m \
OFSPXSocket.m \
OFSPXStreamSocket.m
SRCS_PLUGINS = OFPlugin.m
SRCS_SCTP = OFSCTPSocket.m
SRCS_SOCKETS = OFDNSQuery.m \
OFDNSResolver.m \
OFDNSResourceRecord.m \
OFDNSResponse.m \
OFDatagramSocket.m \
OFHTTPClient.m \
OFHTTPCookie.m \
OFHTTPCookieManager.m \
OFHTTPRequest.m \
OFHTTPResponse.m \
OFHTTPServer.m \
OFSequencedPacketSocket.m \
OFStreamSocket.m \
OFTCPSocket.m \
OFUDPSocket.m \
socket.m \
${USE_SRCS_IPX} \
${USE_SRCS_IPX}
${USE_SRCS_SCTP}
SRCS_THREADS = OFCondition.m \
OFMutex.m \
OFRecursiveMutex.m \
OFThreadPool.m \
condition.m \
mutex.m \
thread.m \
tlskey.m
SRCS_WINDOWS = OFWin32ConsoleStdIOStream.m \
OFWindowsRegistryKey.m
INCLUDES_ATOMIC = atomic.h \
atomic_builtins.h \
atomic_no_threads.h \
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 \
OFLocking.h \
OFMessagePackRepresentation.h \
|
︙ | | |
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
-
+
-
-
+
-
|
${OF_KQUEUE_KERNEL_EVENT_OBSERVER_M} \
${OF_POLL_KERNEL_EVENT_OBSERVER_M} \
${OF_SELECT_KERNEL_EVENT_OBSERVER_M} \
OFTCPSocketSOCKS5Connector.m
OBJS_EXTRA = exceptions/exceptions.a \
encodings/encodings.a \
forwarding/forwarding.a \
forwarding/forwarding.a
invocation/invocation.a
LIB_OBJS_EXTRA = exceptions/exceptions.lib.a \
encodings/encodings.lib.a \
forwarding/forwarding.lib.a \
forwarding/forwarding.lib.a
invocation/invocation.lib.a
include ../buildsys.mk
CPPFLAGS += -I. -I.. -Iexceptions -Iruntime
LD = ${OBJC}
FRAMEWORK_LIBS := -Fruntime \
${RUNTIME_FRAMEWORK_LIBS} \
${REEXPORT_RUNTIME_FRAMEWORK} \
${LIBS}
LIBS := -Lruntime ${RUNTIME_LIBS} ${REEXPORT_RUNTIME} ${LIBS}
|
Deleted src/OFASN1BitString.h version [dd9e3e424b].
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
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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
@class OFData;
/**
* @brief An ASN.1 BitString.
*/
OF_SUBCLASSING_RESTRICTED
@interface OFASN1BitString: OFObject <OFASN1DERRepresentation>
{
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 version [58adebf4a8].
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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
185
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "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)];
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 == self)
return true;
if (![object isKindOfClass: [OFASN1BitString class]])
return false;
bitString = object;
if (![bitString->_bitStringValue isEqual: _bitStringValue])
return false;
if (bitString->_bitStringLength != _bitStringLength)
return false;
return true;
}
- (unsigned long)hash
{
return _bitStringValue.hash + (unsigned long)_bitStringLength;
}
- (OFString *)description
{
return [OFString stringWithFormat: @"<OFASN1BitString: %@ (%zu bits)>",
_bitStringValue, _bitStringLength];
}
@end
|
Deleted src/OFASN1Boolean.h version [f9c4678a9e].
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
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 _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 version [ab43e337d1].
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
116
117
118
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 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 == self)
return true;
if (![object isKindOfClass: [OFASN1Boolean class]])
return false;
boolean = object;
if (boolean->_booleanValue != _booleanValue)
return false;
return true;
}
- (unsigned long)hash
{
return _booleanValue;
}
- (OFString *)description
{
return (_booleanValue
? @"<OFASN1Boolean: true>"
: @"<OFASN1Boolean: false>");
}
@end
|
Deleted src/OFASN1DERRepresentation.h version [878337daf1].
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
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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"
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 version [5baa4a294f].
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
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "OFASN1Value.h"
OF_ASSUME_NONNULL_BEGIN
/**
* @brief An ASN.1 Enumerated.
*/
OF_SUBCLASSING_RESTRICTED
@interface OFASN1Enumerated: OFObject
{
long long _longLongValue;
}
/**
* @brief The integer value.
*/
@property (readonly, nonatomic) long long longLongValue;
/**
* @brief Creates an ASN.1 Enumerated with the specified integer value.
*
* @param value The `long long` value of the Enumerated
* @return A new, autoreleased OFASN1Enumerated
*/
+ (instancetype)enumeratedWithLongLong: (long long)value;
- (instancetype)init OF_UNAVAILABLE;
/**
* @brief Initializes an already allocated ASN.1 Enumerated with the specified
* integer value.
*
* @param value The `long long` value of the Enumerated
* @return An initialized OFASN1Enumerated
*/
- (instancetype)initWithLongLong: (long long)value 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 version [ba2cabe5ff].
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
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "OFASN1Enumerated.h"
#import "OFData.h"
#import "OFString.h"
#import "OFInvalidArgumentException.h"
extern long long of_asn1_der_integer_parse(const unsigned char *buffer,
size_t length);
@implementation OFASN1Enumerated
@synthesize longLongValue = _longLongValue;
+ (instancetype)enumeratedWithLongLong: (long long)value
{
return [[[self alloc] initWithLongLong: value] autorelease];
}
- (instancetype)initWithLongLong: (long long)value
{
self = [super init];
_longLongValue = value;
return self;
}
- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass
tagNumber: (of_asn1_tag_number_t)tagNumber
constructed: (bool)constructed
DEREncodedContents: (OFData *)DEREncodedContents
{
long long value;
@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];
value = of_asn1_der_integer_parse(
DEREncodedContents.items, DEREncodedContents.count);
} @catch (id e) {
[self release];
@throw e;
}
return [self initWithLongLong: value];
}
- (instancetype)init
{
OF_INVALID_INIT_METHOD
}
- (bool)isEqual: (id)object
{
OFASN1Enumerated *enumerated;
if (object == self)
return true;
if (![object isKindOfClass: [OFASN1Enumerated class]])
return false;
enumerated = object;
if (enumerated->_longLongValue != _longLongValue)
return false;
return true;
}
- (unsigned long)hash
{
return (unsigned long)_longLongValue;
}
- (OFString *)description
{
return [OFString stringWithFormat: @"<OFASN1Enumerated: %lld>",
_longLongValue];
}
@end
|
Deleted src/OFASN1IA5String.h version [c414c3313c].
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
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "OFASN1Value.h"
OF_ASSUME_NONNULL_BEGIN
@class OFString;
/**
* @brief An ASN.1 IA5String.
*/
OF_SUBCLASSING_RESTRICTED
@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 version [6816147795].
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
116
117
118
119
120
121
122
123
124
125
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "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 == self)
return true;
if (![object isKindOfClass: [OFASN1IA5String class]])
return false;
IA5String = object;
if (![IA5String->_IA5StringValue isEqual: _IA5StringValue])
return false;
return true;
}
- (unsigned long)hash
{
return _IA5StringValue.hash;
}
- (OFString *)description
{
return [OFString stringWithFormat: @"<OFASN1IA5String: %@>",
_IA5StringValue];
}
@end
|
Deleted src/OFASN1Integer.h version [a73f7cf242].
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
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "OFASN1Value.h"
OF_ASSUME_NONNULL_BEGIN
/**
* @brief An ASN.1 Integer.
*/
OF_SUBCLASSING_RESTRICTED
@interface OFASN1Integer: OFObject
{
long long _longLongValue;
}
/**
* @brief The Integer value.
*/
@property (readonly, nonatomic) long long longLongValue;
/**
* @brief Creates an ASN.1 Integer with the specified integer value.
*
* @param value The `long long` value of the Integer
* @return A new, autoreleased OFASN1Integer
*/
+ (instancetype)integerWithLongLong: (long long)value;
- (instancetype)init OF_UNAVAILABLE;
/**
* @brief Initializes an already allocated ASN.1 Integer with the specified
* integer value.
*
* @param value The `long long` value of the Integer
* @return An initialized OFASN1Integer
*/
- (instancetype)initWithLongLong: (long long)value 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 version [e6486b0fce].
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
116
117
118
119
120
121
122
123
124
125
126
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "OFASN1Integer.h"
#import "OFData.h"
#import "OFString.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFOutOfRangeException.h"
long long
of_asn1_der_integer_parse(const unsigned char *buffer, size_t length)
{
unsigned long long value = 0;
/* TODO: Support for big numbers */
if (length > sizeof(unsigned long long) &&
(length != sizeof(unsigned long long) + 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 = ~0ull;
while (length--)
value = (value << 8) | *buffer++;
return value;
}
@implementation OFASN1Integer
@synthesize longLongValue = _longLongValue;
+ (instancetype)integerWithLongLong: (long long)value
{
return [[[self alloc] initWithLongLong: value] autorelease];
}
- (instancetype)initWithLongLong: (long long)value
{
self = [super init];
_longLongValue = value;
return self;
}
- (instancetype)initWithTagClass: (of_asn1_tag_class_t)tagClass
tagNumber: (of_asn1_tag_number_t)tagNumber
constructed: (bool)constructed
DEREncodedContents: (OFData *)DEREncodedContents
{
long long value;
@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];
value = of_asn1_der_integer_parse(
DEREncodedContents.items, DEREncodedContents.count);
} @catch (id e) {
[self release];
@throw e;
}
return [self initWithLongLong: value];
}
- (instancetype)init
{
OF_INVALID_INIT_METHOD
}
- (bool)isEqual: (id)object
{
OFASN1Integer *integer;
if (object == self)
return true;
if (![object isKindOfClass: [OFASN1Integer class]])
return false;
integer = object;
if (integer->_longLongValue != _longLongValue)
return false;
return true;
}
- (unsigned long)hash
{
return (unsigned long)_longLongValue;
}
- (OFString *)description
{
return [OFString stringWithFormat: @"<OFASN1Integer: %lld>",
_longLongValue];
}
@end
|
Deleted src/OFASN1NumericString.h version [3a5c85e7cd].
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
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "OFASN1Value.h"
OF_ASSUME_NONNULL_BEGIN
@class OFString;
/**
* @brief An ASN.1 NumericString.
*/
OF_SUBCLASSING_RESTRICTED
@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 version [1f3277f085].
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "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 == self)
return true;
if (![object isKindOfClass: [OFASN1NumericString class]])
return false;
numericString = object;
if (![numericString->_numericStringValue isEqual: _numericStringValue])
return false;
return true;
}
- (unsigned long)hash
{
return _numericStringValue.hash;
}
- (OFString *)description
{
return [OFString stringWithFormat: @"<OFASN1NumericString: %@>",
_numericStringValue];
}
@end
|
Deleted src/OFASN1ObjectIdentifier.h version [4f0a319e02].
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
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "OFASN1Value.h"
OF_ASSUME_NONNULL_BEGIN
@class OFArray OF_GENERIC(ObjetType);
@class OFNumber;
/**
* @brief An ASN.1 ObjectIdentifier.
*/
OF_SUBCLASSING_RESTRICTED
@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 version [0496bf5735].
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "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] longLongValue]) {
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;
unsigned long long 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(unsigned long long) * 8)
@throw [OFOutOfRangeException exception];
if (items[i] & 0x80)
continue;
if (subidentifiers.count == 0) {
if (value < 40)
[subidentifiers addObject:
[OFNumber numberWithInt: 0]];
else if (value < 80) {
[subidentifiers addObject:
[OFNumber numberWithInt: 1]];
value -= 40;
} else {
[subidentifiers addObject:
[OFNumber numberWithInt: 2]];
value -= 80;
}
}
[subidentifiers addObject:
[OFNumber numberWithUnsignedLongLong: 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 == self)
return true;
if (![object isKindOfClass: [OFASN1ObjectIdentifier class]])
return false;
objectIdentifier = object;
if (![objectIdentifier->_subidentifiers isEqual: _subidentifiers])
return false;
return true;
}
- (unsigned long)hash
{
return _subidentifiers.hash;
}
- (OFString *)description
{
return [OFString stringWithFormat:
@"<OFASN1ObjectIdentifier: %@>",
[_subidentifiers componentsJoinedByString: @"."]];
}
@end
|
Deleted src/OFASN1OctetString.h version [6d83ed8333].
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
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "OFASN1Value.h"
OF_ASSUME_NONNULL_BEGIN
@class OFData;
/**
* @brief An ASN.1 OctetString.
*/
OF_SUBCLASSING_RESTRICTED
@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 version [3d5ad35b08].
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
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "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 == self)
return true;
if (![object isKindOfClass: [OFASN1OctetString class]])
return false;
octetString = object;
if (![octetString->_octetStringValue isEqual: _octetStringValue])
return false;
return true;
}
- (unsigned long)hash
{
return _octetStringValue.hash;
}
- (OFString *)description
{
return [OFString stringWithFormat: @"<OFASN1OctetString: %@>",
_octetStringValue];
}
@end
|
Deleted src/OFASN1PrintableString.h version [302daaf706].
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
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "OFASN1Value.h"
OF_ASSUME_NONNULL_BEGIN
@class OFString;
/**
* @brief An ASN.1 PrintableString.
*/
OF_SUBCLASSING_RESTRICTED
@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 version [d326d7d84e].
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "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 == self)
return true;
if (![object isKindOfClass: [OFASN1PrintableString class]])
return false;
printableString = object;
if (![printableString->_printableStringValue isEqual:
_printableStringValue])
return false;
return true;
}
- (unsigned long)hash
{
return _printableStringValue.hash;
}
- (OFString *)description
{
return [OFString stringWithFormat: @"<OFASN1PrintableString: %@>",
_printableStringValue];
}
@end
|
Deleted src/OFASN1UTF8String.h version [8f256e2e35].
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
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "OFASN1Value.h"
OF_ASSUME_NONNULL_BEGIN
@class OFString;
/**
* @brief An ASN.1 UTF8String.
*/
OF_SUBCLASSING_RESTRICTED
@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 version [fe525c2cd3].
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
116
117
118
119
120
121
122
123
124
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "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 == self)
return true;
if (![object isKindOfClass: [OFASN1UTF8String class]])
return false;
UTF8String = object;
if (![UTF8String->_UTF8StringValue isEqual: _UTF8StringValue])
return false;
return true;
}
- (unsigned long)hash
{
return _UTF8StringValue.hash;
}
- (OFString *)description
{
return [OFString stringWithFormat: @"<OFASN1UTF8String: %@>",
_UTF8StringValue];
}
@end
|
Deleted src/OFASN1Value.h version [80070a2f85].
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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"
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.
*/
OF_SUBCLASSING_RESTRICTED
@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 version [e6d6355cac].
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "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 == self)
return true;
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;
}
- (unsigned long)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:
@"<OFASN1Value:\n"
@"\tTag class = %x\n"
@"\tTag number = %x\n"
@"\tConstructed = %u\n"
@"\tDER-encoded contents = %@\n"
@">",
_tagClass, _tagNumber, _constructed,
_DEREncodedContents.description];
}
@end
|
Deleted src/OFData+ASN1DERParsing.h version [7ece1a8d4e].
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
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "OFData.h"
#import "OFASN1Value.h"
OF_ASSUME_NONNULL_BEGIN
#ifdef __cplusplus
extern "C" {
#endif
extern int _OFData_ASN1DERParsing_reference;
#ifdef __cplusplus
}
#endif
@interface OFData (ASN1DERParsing)
/**
* @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 objectByParsingASN1DER;
/**
* @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)objectByParsingASN1DERWithDepthLimit: (size_t)depthLimit;
@end
OF_ASSUME_NONNULL_END
|
Deleted src/OFData+ASN1DERParsing.m version [31638813f3].
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "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 "OFSet.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
enum {
ASN1_TAG_CONSTRUCTED_MASK = 0x20
};
int _OFData_ASN1DERParsing_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 (ASN1DERParsing)
- (id)objectByParsingASN1DER
{
return [self objectByParsingASN1DERWithDepthLimit: 32];
}
- (id)objectByParsingASN1DERWithDepthLimit: (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
|
Modified src/OFData.h
from [7785f4eec7]
to [665f32e2d6].
︙ | | |
323
324
325
326
327
328
329
330
331
332
|
323
324
325
326
327
328
329
330
331
|
-
|
*/
- (void)writeToURL: (OFURL *)URL;
@end
OF_ASSUME_NONNULL_END
#import "OFMutableData.h"
#import "OFData+ASN1DERParsing.h"
#import "OFData+CryptoHashing.h"
#import "OFData+MessagePackParsing.h"
|
Modified src/OFData.m
from [7ddb882b03]
to [86e2a3f40f].
︙ | | |
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
-
|
#import "base64.h"
/* References for static linking */
void
_references_to_categories_of_OFData(void)
{
_OFData_ASN1DERParsing_reference = 1;
_OFData_CryptoHashing_reference = 1;
_OFData_MessagePackParsing_reference = 1;
}
@implementation OFData
@synthesize itemSize = _itemSize;
|
︙ | | |
Modified src/OFIPSocketAsyncConnector.m
from [35ca21ecbd]
to [a2237d54c6].
︙ | | |
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
-
-
-
|
#include "config.h"
#include <errno.h>
#import "OFIPSocketAsyncConnector.h"
#import "OFData.h"
#ifdef OF_HAVE_SCTP
# import "OFSCTPSocket.h"
#endif
#import "OFTCPSocket.h"
#import "OFThread.h"
#import "OFTimer.h"
#import "OFConnectionFailedException.h"
#import "OFInvalidFormatException.h"
|
︙ | | |
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
-
-
-
-
-
|
[_socket setCanBlock: true];
#ifdef OF_HAVE_BLOCKS
if (_block != NULL) {
if ([_socket isKindOfClass: [OFTCPSocket class]])
((of_tcp_socket_async_connect_block_t)_block)(
_exception);
# ifdef OF_HAVE_SCTP
else if ([_socket isKindOfClass: [OFSCTPSocket class]])
((of_sctp_socket_async_connect_block_t)_block)(
_exception);
# endif
else
OF_ENSURE(0);
} else {
#endif
if ([_delegate respondsToSelector:
@selector(socket:didConnectToHost:port:exception:)])
[_delegate socket: _socket
|
︙ | | |
Modified src/OFInvocation.h
from [86507cef33]
to [eaf0bab701].
︙ | | |
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
|
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
-
-
-
-
-
-
-
-
-
-
-
-
|
* file.
*/
#import "OFObject.h"
OF_ASSUME_NONNULL_BEGIN
#ifdef OF_APPLE_RUNTIME
# ifdef OF_X86_64
# define OF_INVOCATION_CAN_INVOKE
# endif
#else
# ifdef OF_ELF
# ifdef OF_X86_64
# define OF_INVOCATION_CAN_INVOKE
# endif
# endif
#endif
@class OFMethodSignature;
@class OFMutableArray OF_GENERIC(ObjectType);
@class OFMutableData;
/**
* @class OFInvocation OFInvocation.h ObjFW/OFInvocation.h
*
|
︙ | | |
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
85
86
87
88
89
90
91
92
93
94
|
-
-
-
-
-
-
-
|
/**
* @brief Gets the return value.
*
* @param buffer The buffer in which the return value is stored
*/
- (void)getReturnValue: (void *)buffer;
#ifdef OF_INVOCATION_CAN_INVOKE
/**
* @brief Invokes the method.
*/
- (void)invoke;
#endif
@end
OF_ASSUME_NONNULL_END
|
Modified src/OFInvocation.m
from [f9deea1e14]
to [4b44ca7411].
︙ | | |
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
-
-
-
-
|
#include <string.h>
#import "OFInvocation.h"
#import "OFArray.h"
#import "OFData.h"
#import "OFMethodSignature.h"
#ifdef OF_INVOCATION_CAN_INVOKE
extern void of_invocation_invoke(OFInvocation *);
#endif
@implementation OFInvocation
@synthesize methodSignature = _methodSignature;
+ (instancetype)invocationWithMethodSignature: (OFMethodSignature *)signature
{
return [[[self alloc] initWithMethodSignature: signature] autorelease];
}
|
︙ | | |
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
107
108
109
110
111
112
113
114
|
-
-
-
-
-
-
-
|
memcpy(_returnValue.mutableItems, buffer, _returnValue.itemSize);
}
- (void)getReturnValue: (void *)buffer
{
memcpy(buffer, _returnValue.items, _returnValue.itemSize);
}
#ifdef OF_INVOCATION_CAN_INVOKE
- (void)invoke
{
of_invocation_invoke(self);
}
#endif
@end
|
Modified src/OFNull.h
from [8747bb1b27]
to [9925492cef].
︙ | | |
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
|
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
|
-
-
+
|
* 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 "OFJSONRepresentation.h"
#import "OFMessagePackRepresentation.h"
#import "OFSerialization.h"
OF_ASSUME_NONNULL_BEGIN
/**
* @class OFNull OFNull.h ObjFW/OFNull.h
*
* @brief A class for representing null values in collections.
*/
OF_SUBCLASSING_RESTRICTED
@interface OFNull: OFObject <OFCopying, OFSerialization, OFJSONRepresentation,
OFMessagePackRepresentation, OFASN1DERRepresentation>
OFMessagePackRepresentation>
/**
* @brief Returns an OFNull singleton.
*
* @return An OFNull singleton
*/
+ (OFNull *)null;
@end
|
︙ | | |
Modified src/OFNull.m
from [43e1244281]
to [d8979da0de].
︙ | | |
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
-
-
-
-
-
-
-
-
|
{
uint8_t type = 0xC0;
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;
}
- (instancetype)retain
{
|
︙ | | |
Deleted src/OFSCTPSocket.h version [5b42b1dc48].
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "OFSequencedPacketSocket.h"
#import "OFRunLoop.h"
OF_ASSUME_NONNULL_BEGIN
/** @file */
@class OFSCTPSocket;
@class OFString;
#ifdef OF_HAVE_BLOCKS
/**
* @brief A block which is called when the socket connected.
*
* @param exception An exception which occurred while connecting the socket or
* `nil` on success
*/
typedef void (^of_sctp_socket_async_connect_block_t)(id _Nullable exception);
#endif
/**
* @protocol OFSCTPSocketDelegate OFSCTPSocket.h ObjFW/OFSCTPSocket.h
*
* A delegate for OFSCTPSocket.
*/
@protocol OFSCTPSocketDelegate <OFSequencedPacketSocketDelegate>
@optional
/**
* @brief A method which is called when a socket connected.
*
* @param socket The socket which connected
* @param host The host connected to
* @param port The port on the host connected to
* @param exception An exception that occurred while connecting, or nil on
* success
*/
- (void)socket: (OFSCTPSocket *)socket
didConnectToHost: (OFString *)host
port: (uint16_t)port
exception: (nullable id)exception;
@end
/**
* @class OFSCTPSocket OFSCTPSocket.h ObjFW/OFSCTPSocket.h
*
* @brief A class which provides methods to create and use SCTP sockets in
* one-to-one mode.
*
* To connect to a server, create a socket and connect it.
* To create a server, create a socket, bind it and listen on it.
*/
@interface OFSCTPSocket: OFSequencedPacketSocket
{
OF_RESERVE_IVARS(OFSCTPSocket, 4)
}
/**
* @brief Whether sending packets can be delayed. Setting this to NO sets
* SCTP_NODELAY on the socket.
*/
@property (nonatomic) bool canDelaySendingPackets;
/**
* @brief The delegate for asynchronous operations on the socket.
*
* @note The delegate is retained for as long as asynchronous operations are
* still ongoing.
*/
@property OF_NULLABLE_PROPERTY (assign, nonatomic)
id <OFSCTPSocketDelegate> delegate;
/**
* @brief Connect the OFSCTPSocket to the specified destination.
*
* @param host The host to connect to
* @param port The port on the host to connect to
*/
- (void)connectToHost: (OFString *)host
port: (uint16_t)port;
/**
* @brief Asynchronously connect the OFSCTPSocket to the specified destination.
*
* @param host The host to connect to
* @param port The port on the host to connect to
*/
- (void)asyncConnectToHost: (OFString *)host
port: (uint16_t)port;
/**
* @brief Asynchronously connect the OFSCTPSocket to the specified destination.
*
* @param host The host to connect to
* @param port The port on the host to connect to
* @param runLoopMode The run loop mode in which to perform the async connect
*/
- (void)asyncConnectToHost: (OFString *)host
port: (uint16_t)port
runLoopMode: (of_run_loop_mode_t)runLoopMode;
#ifdef OF_HAVE_BLOCKS
/**
* @brief Asynchronously connect the OFSCTPSocket to the specified destination.
*
* @param host The host to connect to
* @param port The port on the host to connect to
* @param block The block to execute once the connection has been established
*/
- (void)asyncConnectToHost: (OFString *)host
port: (uint16_t)port
block: (of_sctp_socket_async_connect_block_t)block;
/**
* @brief Asynchronously connect the OFSCTPSocket to the specified destination.
*
* @param host The host to connect to
* @param port The port on the host to connect to
* @param runLoopMode The run loop mode in which to perform the async connect
* @param block The block to execute once the connection has been established
*/
- (void)asyncConnectToHost: (OFString *)host
port: (uint16_t)port
runLoopMode: (of_run_loop_mode_t)runLoopMode
block: (of_sctp_socket_async_connect_block_t)block;
#endif
/**
* @brief Bind the socket to the specified host and port.
*
* @param host The host to bind to. Use `@"0.0.0.0"` for IPv4 or `@"::"` for
* IPv6 to bind to all.
* @param port The port to bind to. If the port is 0, an unused port will be
* chosen, which can be obtained using the return value.
* @return The port the socket was bound to
*/
- (uint16_t)bindToHost: (OFString *)host
port: (uint16_t)port;
@end
OF_ASSUME_NONNULL_END
|
Deleted src/OFSCTPSocket.m version [f509519c08].
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_FCNTL_H
# include <fcntl.h>
#endif
#import "OFSCTPSocket.h"
#import "OFDNSResolver.h"
#import "OFData.h"
#import "OFDate.h"
#import "OFIPSocketAsyncConnector.h"
#import "OFRunLoop.h"
#import "OFRunLoop+Private.h"
#import "OFString.h"
#import "OFThread.h"
#import "OFAlreadyConnectedException.h"
#import "OFBindFailedException.h"
#import "OFGetOptionFailedException.h"
#import "OFNotOpenException.h"
#import "OFSetOptionFailedException.h"
#import "socket.h"
#import "socket_helpers.h"
static const of_run_loop_mode_t connectRunLoopMode =
@"of_sctp_socket_connect_mode";
@interface OFSCTPSocket () <OFIPSocketAsyncConnecting>
@end
@interface OFSCTPSocketConnectDelegate: OFObject <OFSCTPSocketDelegate>
{
@public
bool _done;
id _exception;
}
@end
@implementation OFSCTPSocketConnectDelegate
- (void)dealloc
{
[_exception release];
[super dealloc];
}
- (void)socket: (OFSCTPSocket *)sock
didConnectToHost: (OFString *)host
port: (uint16_t)port
exception: (id)exception
{
_done = true;
_exception = [exception retain];
}
@end
@implementation OFSCTPSocket
@dynamic delegate;
- (bool)of_createSocketForAddress: (const of_socket_address_t *)address
errNo: (int *)errNo
{
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
int flags;
#endif
if (_socket != INVALID_SOCKET)
@throw [OFAlreadyConnectedException exceptionWithSocket: self];
if ((_socket = socket(address->sockaddr.sockaddr.sa_family,
SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_SCTP)) == INVALID_SOCKET) {
*errNo = of_socket_errno();
return false;
}
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif
return true;
}
- (bool)of_connectSocketToAddress: (const of_socket_address_t *)address
errNo: (int *)errNo
{
if (_socket == INVALID_SOCKET)
@throw [OFNotOpenException exceptionWithObject: self];
if (connect(_socket, &address->sockaddr.sockaddr,
address->length) != 0) {
*errNo = of_socket_errno();
return false;
}
return true;
}
- (void)of_closeSocket
{
closesocket(_socket);
_socket = INVALID_SOCKET;
}
- (void)connectToHost: (OFString *)host
port: (uint16_t)port
{
void *pool = objc_autoreleasePoolPush();
id <OFSCTPSocketDelegate> delegate = _delegate;
OFSCTPSocketConnectDelegate *connectDelegate =
[[[OFSCTPSocketConnectDelegate alloc] init] autorelease];
OFRunLoop *runLoop = [OFRunLoop currentRunLoop];
self.delegate = connectDelegate;
[self asyncConnectToHost: host
port: port
runLoopMode: connectRunLoopMode];
while (!connectDelegate->_done)
[runLoop runMode: connectRunLoopMode
beforeDate: nil];
/* Cleanup */
[runLoop runMode: connectRunLoopMode
beforeDate: [OFDate date]];
if (connectDelegate->_exception != nil)
@throw connectDelegate->_exception;
self.delegate = delegate;
objc_autoreleasePoolPop(pool);
}
- (void)asyncConnectToHost: (OFString *)host
port: (uint16_t)port
{
[self asyncConnectToHost: host
port: port
runLoopMode: of_run_loop_mode_default];
}
- (void)asyncConnectToHost: (OFString *)host
port: (uint16_t)port
runLoopMode: (of_run_loop_mode_t)runLoopMode
{
void *pool = objc_autoreleasePoolPush();
if (_socket != INVALID_SOCKET)
@throw [OFAlreadyConnectedException exceptionWithSocket: self];
[[[[OFIPSocketAsyncConnector alloc]
initWithSocket: self
host: host
port: port
delegate: _delegate
block: NULL
] autorelease] startWithRunLoopMode: runLoopMode];
objc_autoreleasePoolPop(pool);
}
#ifdef OF_HAVE_BLOCKS
- (void)asyncConnectToHost: (OFString *)host
port: (uint16_t)port
block: (of_sctp_socket_async_connect_block_t)block
{
[self asyncConnectToHost: host
port: port
runLoopMode: of_run_loop_mode_default
block: block];
}
- (void)asyncConnectToHost: (OFString *)host
port: (uint16_t)port
runLoopMode: (of_run_loop_mode_t)runLoopMode
block: (of_sctp_socket_async_connect_block_t)block
{
void *pool = objc_autoreleasePoolPush();
if (_socket != INVALID_SOCKET)
@throw [OFAlreadyConnectedException exceptionWithSocket: self];
[[[[OFIPSocketAsyncConnector alloc]
initWithSocket: self
host: host
port: port
delegate: nil
block: block] autorelease]
startWithRunLoopMode: runLoopMode];
objc_autoreleasePoolPop(pool);
}
#endif
- (uint16_t)bindToHost: (OFString *)host
port: (uint16_t)port
{
const int one = 1;
void *pool = objc_autoreleasePoolPush();
OFData *socketAddresses;
of_socket_address_t address;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
int flags;
#endif
if (_socket != INVALID_SOCKET)
@throw [OFAlreadyConnectedException exceptionWithSocket: self];
socketAddresses = [[OFThread DNSResolver]
resolveAddressesForHost: host
addressFamily: OF_SOCKET_ADDRESS_FAMILY_ANY];
address = *(of_socket_address_t *)[socketAddresses itemAtIndex: 0];
of_socket_address_set_port(&address, port);
if ((_socket = socket(address.sockaddr.sockaddr.sa_family,
SOCK_STREAM | SOCK_CLOEXEC, IPPROTO_SCTP)) == INVALID_SOCKET)
@throw [OFBindFailedException
exceptionWithHost: host
port: port
socket: self
errNo: of_socket_errno()];
_canBlock = true;
#if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC)
if ((flags = fcntl(_socket, F_GETFD, 0)) != -1)
fcntl(_socket, F_SETFD, flags | FD_CLOEXEC);
#endif
setsockopt(_socket, SOL_SOCKET, SO_REUSEADDR,
(char *)&one, (socklen_t)sizeof(one));
if (bind(_socket, &address.sockaddr.sockaddr, address.length) != 0) {
int errNo = of_socket_errno();
closesocket(_socket);
_socket = INVALID_SOCKET;
@throw [OFBindFailedException exceptionWithHost: host
port: port
socket: self
errNo: errNo];
}
objc_autoreleasePoolPop(pool);
if (port > 0)
return port;
memset(&address, 0, sizeof(address));
address.length = (socklen_t)sizeof(address.sockaddr);
if (of_getsockname(_socket, &address.sockaddr.sockaddr,
&address.length) != 0) {
int errNo = of_socket_errno();
closesocket(_socket);
_socket = INVALID_SOCKET;
@throw [OFBindFailedException exceptionWithHost: host
port: port
socket: self
errNo: errNo];
}
if (address.sockaddr.sockaddr.sa_family == AF_INET)
return OF_BSWAP16_IF_LE(address.sockaddr.in.sin_port);
# ifdef OF_HAVE_IPV6
else if (address.sockaddr.sockaddr.sa_family == AF_INET6)
return OF_BSWAP16_IF_LE(address.sockaddr.in6.sin6_port);
# endif
else {
closesocket(_socket);
_socket = INVALID_SOCKET;
@throw [OFBindFailedException exceptionWithHost: host
port: port
socket: self
errNo: EAFNOSUPPORT];
}
}
- (void)setCanDelaySendingPackets: (bool)canDelaySendingPackets
{
int v = !canDelaySendingPackets;
if (setsockopt(_socket, IPPROTO_SCTP, SCTP_NODELAY,
(char *)&v, (socklen_t)sizeof(v)) != 0)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: of_socket_errno()];
}
- (bool)canDelaySendingPackets
{
int v;
socklen_t len = sizeof(v);
if (getsockopt(_socket, IPPROTO_SCTP, SCTP_NODELAY,
(char *)&v, &len) != 0 || len != sizeof(v))
@throw [OFGetOptionFailedException
exceptionWithObject: self
errNo: of_socket_errno()];
return !v;
}
@end
|
Deleted src/OFThreadPool.h version [9825eb68b1].
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
116
117
118
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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"
OF_ASSUME_NONNULL_BEGIN
/** @file */
#ifdef OF_HAVE_BLOCKS
/**
* @brief A block for a job which should be executed in a thread pool.
*/
typedef void (^of_thread_pool_block_t)(void);
#endif
@class OFCondition;
@class OFList OF_GENERIC(ObjectType);
@class OFMutableArray OF_GENERIC(ObjectType);
@class OFThreadPoolJob;
/**
* @class OFThreadPool OFThreadPool.h ObjFW/OFThreadPool.h
*
* @brief A class providing a pool of reusable threads.
*
* @note When the thread pool is released, all threads will terminate after
* they finish the job they are currently processing.
*/
OF_SUBCLASSING_RESTRICTED
@interface OFThreadPool: OFObject
{
size_t _size;
OFMutableArray *_threads;
volatile int _count;
#ifdef OF_THREAD_POOL_M
@public
#endif
OFList *_queue;
OFCondition *_queueCondition;
volatile int _doneCount;
OFCondition *_countCondition;
}
/**
* @brief The size of the thread pool.
*/
@property (readonly, nonatomic) size_t size;
/**
* @brief Returns a new thread pool with one thread for each core in the system.
*
* @warning If for some reason the number of cores in the system could not be
* determined, the pool will only have one thread!
*
* @return A new thread pool with one thread for each core in the system
*/
+ (instancetype)threadPool;
/**
* @brief Returns a new thread pool with the specified number of threads.
*
* @param size The number of threads for the pool
* @return A new thread pool with the specified number of threads
*/
+ (instancetype)threadPoolWithSize: (size_t)size;
/**
* @brief Initializes an already allocated OFThreadPool with the specified
* number of threads.
*
* @param size The number of threads for the pool
* @return An initialized OFThreadPool with the specified number of threads
*/
- (instancetype)initWithSize: (size_t)size OF_DESIGNATED_INITIALIZER;
/**
* @brief Execute the specified selector on the specified target with the
* specified object as soon as a thread is ready.
*
* @param target The target on which to perform the selector
* @param selector The selector to perform on the target
* @param object The object with which the selector is performed on the target
*/
- (void)dispatchWithTarget: (id)target
selector: (SEL)selector
object: (nullable id)object;
#ifdef OF_HAVE_BLOCKS
/**
* @brief Executes the specified block as soon as a thread is ready.
*
* @param block The block to execute
*/
- (void)dispatchWithBlock: (of_thread_pool_block_t)block;
#endif
/**
* @brief Waits until all jobs are done.
*/
- (void)waitUntilDone;
@end
OF_ASSUME_NONNULL_END
|
Deleted src/OFThreadPool.m version [29bc99edba].
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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"
#define OF_THREAD_POOL_M
#import "OFThreadPool.h"
#import "OFArray.h"
#import "OFList.h"
#import "OFThread.h"
#import "OFCondition.h"
#import "OFSystemInfo.h"
OF_DIRECT_MEMBERS
@interface OFThreadPoolJob: OFObject
{
id _target;
SEL _selector;
id _object;
#ifdef OF_HAVE_BLOCKS
of_thread_pool_block_t _block;
#endif
}
- (instancetype)initWithTarget: (id)target
selector: (SEL)selector
object: (id)object;
#ifdef OF_HAVE_BLOCKS
- (instancetype)initWithBlock: (of_thread_pool_block_t)block;
#endif
- (void)perform;
@end
@implementation OFThreadPoolJob
- (instancetype)initWithTarget: (id)target
selector: (SEL)selector
object: (id)object
{
self = [super init];
@try {
_target = [target retain];
_selector = selector;
_object = [object retain];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
#ifdef OF_HAVE_BLOCKS
- (instancetype)initWithBlock: (of_thread_pool_block_t)block
{
self = [super init];
@try {
_block = [block copy];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
#endif
- (void)dealloc
{
[_target release];
[_object release];
#ifdef OF_HAVE_BLOCKS
[_block release];
#endif
[super dealloc];
}
- (void)perform
{
#ifdef OF_HAVE_BLOCKS
if (_block != NULL)
_block();
else
#endif
[_target performSelector: _selector
withObject: _object];
}
@end
OF_DIRECT_MEMBERS
@interface OFThreadPoolThread: OFThread
{
OFList *_queue;
OFCondition *_queueCondition, *_countCondition;
@public
volatile bool _terminate;
volatile int *_doneCount;
}
+ (instancetype)threadWithThreadPool: (OFThreadPool *)threadPool;
- (instancetype)initWithThreadPool: (OFThreadPool *)threadPool;
@end
@implementation OFThreadPoolThread
+ (instancetype)threadWithThreadPool: (OFThreadPool *)threadPool
{
return [[(OFThreadPoolThread *)[self alloc]
initWithThreadPool: threadPool] autorelease];
}
- (instancetype)initWithThreadPool: (OFThreadPool *)threadPool
{
self = [super init];
@try {
_queue = [threadPool->_queue retain];
_queueCondition = [threadPool->_queueCondition retain];
_countCondition = [threadPool->_countCondition retain];
_doneCount = &threadPool->_doneCount;
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
[_queue release];
[_queueCondition release];
[_countCondition release];
[super dealloc];
}
- (id)main
{
void *pool;
if (_terminate)
return nil;
pool = objc_autoreleasePoolPush();
for (;;) {
OFThreadPoolJob *job;
[_queueCondition lock];
@try {
of_list_object_t *listObject;
if (_terminate) {
objc_autoreleasePoolPop(pool);
return nil;
}
listObject = _queue.firstListObject;
while (listObject == NULL) {
[_queueCondition wait];
if (_terminate) {
objc_autoreleasePoolPop(pool);
return nil;
}
listObject = _queue.firstListObject;
}
job = [[listObject->object retain] autorelease];
[_queue removeListObject: listObject];
} @finally {
[_queueCondition unlock];
}
if (_terminate) {
objc_autoreleasePoolPop(pool);
return nil;
}
[job perform];
if (_terminate) {
objc_autoreleasePoolPop(pool);
return nil;
}
objc_autoreleasePoolPop(pool);
pool = objc_autoreleasePoolPush();
[_countCondition lock];
@try {
if (_terminate) {
objc_autoreleasePoolPop(pool);
return nil;
}
(*_doneCount)++;
[_countCondition signal];
} @finally {
[_countCondition unlock];
}
}
}
@end
@implementation OFThreadPool
+ (instancetype)threadPool
{
return [[[self alloc] init] autorelease];
}
+ (instancetype)threadPoolWithSize: (size_t)size
{
return [[[self alloc] initWithSize: size] autorelease];
}
- (instancetype)init
{
return [self initWithSize: [OFSystemInfo numberOfCPUs]];
}
- (instancetype)initWithSize: (size_t)size
{
self = [super init];
@try {
_size = size;
_threads = [[OFMutableArray alloc] init];
_queue = [[OFList alloc] init];
_queueCondition = [[OFCondition alloc] init];
_countCondition = [[OFCondition alloc] init];
for (size_t i = 0; i < size; i++) {
void *pool = objc_autoreleasePoolPush();
OFThreadPoolThread *thread =
[OFThreadPoolThread threadWithThreadPool: self];
[_threads addObject: thread];
objc_autoreleasePoolPop(pool);
}
/*
* We need to start the threads in a separate loop to make sure
* _threads is not modified anymore to prevent a race condition.
*/
for (size_t i = 0; i < size; i++)
[[_threads objectAtIndex: i] start];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
[_queueCondition lock];
@try {
[_countCondition lock];
@try {
for (OFThreadPoolThread *thread in _threads)
thread->_terminate = true;
} @finally {
[_countCondition unlock];
}
[_queueCondition broadcast];
} @finally {
[_queueCondition unlock];
}
[_threads release];
[_queue release];
[_queueCondition release];
[_countCondition release];
[super dealloc];
}
- (void)of_dispatchJob: (OFThreadPoolJob *)job OF_DIRECT
{
[_countCondition lock];
_count++;
[_countCondition unlock];
[_queueCondition lock];
@try {
[_queue appendObject: job];
[_queueCondition signal];
} @finally {
[_queueCondition unlock];
}
}
- (void)waitUntilDone
{
for (;;) {
[_countCondition lock];
@try {
if (_doneCount == _count)
return;
[_countCondition wait];
} @finally {
[_countCondition unlock];
}
}
}
- (void)dispatchWithTarget: (id)target
selector: (SEL)selector
object: (id)object
{
OFThreadPoolJob *job = [[OFThreadPoolJob alloc] initWithTarget: target
selector: selector
object: object];
@try {
[self of_dispatchJob: job];
} @finally {
[job release];
}
}
#ifdef OF_HAVE_BLOCKS
- (void)dispatchWithBlock: (of_thread_pool_block_t)block
{
OFThreadPoolJob *job = [[OFThreadPoolJob alloc] initWithBlock: block];
@try {
[self of_dispatchJob: job];
} @finally {
[job release];
}
}
#endif
- (size_t)size
{
return _size;
}
@end
|
Modified src/ObjFW.h
from [117174bdb9]
to [253b474482].
︙ | | |
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
-
-
-
|
# import "OFDNSResponse.h"
# import "OFDNSResolver.h"
# ifdef OF_HAVE_IPX
# import "OFIPXSocket.h"
# import "OFSPXSocket.h"
# import "OFSPXStreamSocket.h"
# endif
# ifdef OF_HAVE_SCTP
# import "OFSCTPSocket.h"
# endif
#endif
#ifdef OF_HAVE_SOCKETS
# ifdef OF_HAVE_THREADS
# import "OFHTTPClient.h"
# endif
# import "OFHTTPCookie.h"
# import "OFHTTPCookieManager.h"
|
︙ | | |
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
-
-
-
-
-
-
-
-
-
-
-
-
|
#import "OFRunLoop.h"
#import "OFSandbox.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"
#import "OFASN1UTF8String.h"
#import "OFASN1Value.h"
#import "OFAllocFailedException.h"
#import "OFException.h"
#ifdef OF_HAVE_SOCKETS
# import "OFAcceptFailedException.h"
# import "OFAlreadyConnectedException.h"
# import "OFBindFailedException.h"
#endif
|
︙ | | |
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
249
250
251
252
253
254
255
256
257
258
259
260
261
262
|
-
|
#import "OFThread.h"
#import "once.h"
#ifdef OF_HAVE_THREADS
# import "thread.h"
# import "tlskey.h"
# import "mutex.h"
# import "condition.h"
# import "OFThreadPool.h"
# import "OFMutex.h"
# import "OFRecursiveMutex.h"
# import "OFCondition.h"
#endif
#import "base64.h"
#import "crc16.h"
|
︙ | | |
Deleted src/invocation/Makefile version [a7afc8dd3a].
1
2
3
4
5
6
7
8
9
10
11
12
|
|
-
-
-
-
-
-
-
-
-
-
-
-
|
include ../../extra.mk
STATIC_PIC_LIB_NOINST = ${INVOCATION_LIB_A}
STATIC_LIB_NOINST = ${INVOCATION_A}
SRCS = call.S \
invoke.m
include ../../buildsys.mk
ASFLAGS += -I../.. -I..
OBJCFLAGS += -I../.. -I.. -I../exceptions -I../runtime
|
Deleted src/invocation/apple-call-x86_64.S version [3884ee11f3].
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
116
117
118
119
120
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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"
#include "invoke-x86_64.h"
.intel_syntax noprefix
.globl _of_invocation_call
.section __TEXT, __text, regular, pure_instructions
_of_invocation_call:
push rbp
mov rbp, rsp
sub rsp, 16
and rsp, -16
mov [rbp-8], rdi
lea rdx, [rdi+OFFSET_STACK]
mov rcx, [rdi+OFFSET_STACK_SIZE]
test rcx, 1
jnz Lfix_align
Lfill_stack:
test rcx, rcx
jz Lstack_filled
dec rcx
mov r11, [rdx+rcx*8]
push r11
jmp Lfill_stack
Lstack_filled:
mov al, [rdi+OFFSET_NUM_SSE_USED]
movaps xmm7, [rdi+OFFSET_SSE_INOUT+112]
movaps xmm6, [rdi+OFFSET_SSE_INOUT+96]
movaps xmm5, [rdi+OFFSET_SSE_INOUT+80]
movaps xmm4, [rdi+OFFSET_SSE_INOUT+64]
movaps xmm3, [rdi+OFFSET_SSE_INOUT+48]
movaps xmm2, [rdi+OFFSET_SSE_INOUT+32]
movaps xmm1, [rdi+OFFSET_SSE_INOUT+16]
movaps xmm0, [rdi+OFFSET_SSE_INOUT]
mov r9, [rdi+OFFSET_GPR_IN+40]
mov r8, [rdi+OFFSET_GPR_IN+32]
mov rcx, [rdi+OFFSET_GPR_IN+24]
mov rdx, [rdi+OFFSET_GPR_IN+16]
mov rsi, [rdi+OFFSET_GPR_IN+8]
mov r11b, [rdi+OFFSET_RETURN_TYPE]
mov rdi, [rdi+OFFSET_GPR_IN]
cmp r11b, RETURN_TYPE_STRET
je Lcall_send_stret
cmp r11b, RETURN_TYPE_JMP
je _objc_msgSend
cmp r11b, RETURN_TYPE_JMP_STRET
je _objc_msgSend_stret
call _objc_msgSend
Lafter_send:
mov rdi, [rbp-8]
mov [rdi+OFFSET_GPR_OUT], rax
mov [rdi+OFFSET_GPR_OUT+8], rdx
movaps [rdi+OFFSET_SSE_INOUT], xmm0
movaps [rdi+OFFSET_SSE_INOUT+16], xmm1
mov r11b, [rdi+OFFSET_RETURN_TYPE]
cmp r11b, RETURN_TYPE_X87
je Lpop_long_double
cmp r11b, RETURN_TYPE_COMPLEX_X87
je Lpop_complex_long_double
Lreturn:
mov rsp, rbp
pop rbp
ret
Lfix_align:
xor r11, r11
push r11
jmp Lfill_stack
Lcall_send_stret:
call _objc_msgSend_stret
jmp Lafter_send
Lpop_long_double:
fstp tbyte ptr [rdi+OFFSET_X87_OUT]
jmp Lreturn
Lpop_complex_long_double:
fstp tbyte ptr [rdi+OFFSET_X87_OUT]
fstp tbyte ptr [rdi+OFFSET_X87_OUT+16]
jmp Lreturn
|
Deleted src/invocation/call-x86_64-elf.S version [10e2914d71].
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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"
#include "invoke-x86_64.h"
.intel_syntax noprefix
.globl of_invocation_call
.section .text
of_invocation_call:
pushq rbp
mov rbp, rsp
sub rsp, 16
and rsp, -16
mov [rbp-8], rdi
mov r11b, [rdi+OFFSET_RETURN_TYPE]
cmp r11b, RETURN_TYPE_STRET
je short .Llookup_stret
cmp r11b, RETURN_TYPE_JMP_STRET
je short .Llookup_stret
mov rsi, [rdi+OFFSET_GPR_IN+8]
mov rdi, [rdi+OFFSET_GPR_IN]
call objc_msg_lookup@PLT
.Lafter_lookup:
mov [rbp-16], rax
mov rdi, [rbp-8]
lea rdx, [rdi+OFFSET_STACK]
mov rcx, [rdi+OFFSET_STACK_SIZE]
test rcx, 1
jnz short .Lfix_align
.Lfill_stack:
test rcx, rcx
jz short .Lstack_filled
dec rcx
mov r11, [rdx+rcx*8]
push r11
jmp short .Lfill_stack
.Lstack_filled:
mov al, [rdi+OFFSET_NUM_SSE_USED]
movaps xmm7, [rdi+OFFSET_SSE_INOUT+112]
movaps xmm6, [rdi+OFFSET_SSE_INOUT+96]
movaps xmm5, [rdi+OFFSET_SSE_INOUT+80]
movaps xmm4, [rdi+OFFSET_SSE_INOUT+64]
movaps xmm3, [rdi+OFFSET_SSE_INOUT+48]
movaps xmm2, [rdi+OFFSET_SSE_INOUT+32]
movaps xmm1, [rdi+OFFSET_SSE_INOUT+16]
movaps xmm0, [rdi+OFFSET_SSE_INOUT]
mov r9, [rdi+OFFSET_GPR_IN+40]
mov r8, [rdi+OFFSET_GPR_IN+32]
mov rcx, [rdi+OFFSET_GPR_IN+24]
mov rdx, [rdi+OFFSET_GPR_IN+16]
mov rsi, [rdi+OFFSET_GPR_IN+8]
mov r11b, [rdi+OFFSET_RETURN_TYPE]
mov rdi, [rdi+OFFSET_GPR_IN]
cmp r11b, RETURN_TYPE_JMP
je short .Ljmp_into_method
cmp r11b, RETURN_TYPE_JMP_STRET
je short .Ljmp_into_method
mov r11, [rbp-16]
call r11
.Lafter_send:
mov rdi, [rbp-8]
mov [rdi+OFFSET_GPR_OUT], rax
mov [rdi+OFFSET_GPR_OUT+8], rdx
movaps [rdi+OFFSET_SSE_INOUT], xmm0
movaps [rdi+OFFSET_SSE_INOUT+16], xmm1
mov r11b, [rdi+OFFSET_RETURN_TYPE]
cmp r11b, RETURN_TYPE_X87
je short .Lpop_long_double
cmp r11b, RETURN_TYPE_COMPLEX_X87
je short .Lpop_complex_long_double
.Lreturn:
mov rsp, rbp
pop rbp
ret
.Lfix_align:
xor r11, r11
push r11
jmp short .Lfill_stack
.Llookup_stret:
mov rsi, [rdi+OFFSET_GPR_IN+16]
mov rdi, [rdi+OFFSET_GPR_IN+8]
call objc_msg_lookup_stret@PLT
jmp short .Lafter_lookup
.Ljmp_into_method:
mov r11, [rbp-16]
jmp r11
.Lpop_long_double:
fstp tbyte ptr [rdi+OFFSET_X87_OUT]
jmp short .Lreturn
.Lpop_complex_long_double:
fstp tbyte ptr [rdi+OFFSET_X87_OUT]
fstp tbyte ptr [rdi+OFFSET_X87_OUT+16]
jmp short .Lreturn
#ifdef OF_LINUX
.section .note.GNU-stack, "", %progbits
#endif
|
Deleted src/invocation/call.S version [94426b7ab0].
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
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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"
#include "platform.h"
#ifdef OF_APPLE_RUNTIME
# ifdef OF_X86_64
# include "apple-call-x86_64.S"
# endif
#else
# ifdef OF_ELF
# ifdef OF_X86_64
# include "call-x86_64-elf.S"
# endif
# endif
#endif
|
Deleted src/invocation/invoke-x86_64.h version [e748f149fa].
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
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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.
*/
#define RETURN_TYPE_NORMAL 0
#define RETURN_TYPE_STRET 1
#define RETURN_TYPE_X87 2
#define RETURN_TYPE_COMPLEX_X87 3
#define RETURN_TYPE_JMP 4
#define RETURN_TYPE_JMP_STRET 5
#define NUM_GPR_IN 6
#define NUM_GPR_OUT 2
#define NUM_SSE_INOUT 8
#define NUM_X87_OUT 2
#define OFFSET_GPR_IN 0
#define OFFSET_GPR_OUT (OFFSET_GPR_IN + NUM_GPR_IN * 8)
#define OFFSET_SSE_INOUT (OFFSET_GPR_OUT + NUM_GPR_OUT * 8)
#define OFFSET_X87_OUT (OFFSET_SSE_INOUT + NUM_SSE_INOUT * 16)
#define OFFSET_NUM_SSE_USED (OFFSET_X87_OUT + NUM_X87_OUT * 16)
#define OFFSET_RETURN_TYPE (OFFSET_NUM_SSE_USED + 1)
#define OFFSET_STACK_SIZE (OFFSET_RETURN_TYPE + 7)
#define OFFSET_STACK (OFFSET_STACK_SIZE + 8)
|
Deleted src/invocation/invoke-x86_64.m version [ab1dc9bdb2].
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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"
#include <stdint.h>
#include <stdlib.h>
#include <xmmintrin.h>
#import "OFInvocation.h"
#import "OFMethodSignature.h"
#import "OFInvalidFormatException.h"
#import "OFOutOfMemoryException.h"
#import "invoke-x86_64.h"
#import "macros.h"
struct call_context {
uint64_t GPR[NUM_GPR_IN + NUM_GPR_OUT];
__m128 SSE[NUM_SSE_INOUT];
long double X87[NUM_X87_OUT];
uint8_t numSSEUsed;
uint8_t returnType;
uint64_t stackSize;
uint64_t stack[];
};
extern void of_invocation_call(struct call_context *);
static void
pushGPR(struct call_context **context, uint_fast8_t *currentGPR, uint64_t value)
{
struct call_context *newContext;
if (*currentGPR < NUM_GPR_IN) {
(*context)->GPR[(*currentGPR)++] = value;
return;
}
if ((newContext = realloc(*context,
sizeof(**context) + ((*context)->stackSize + 1) * 8)) == NULL) {
free(*context);
@throw [OFOutOfMemoryException exceptionWithRequestedSize:
sizeof(**context) + ((*context)->stackSize + 1) * 8];
}
newContext->stack[newContext->stackSize] = value;
newContext->stackSize++;
*context = newContext;
}
static void
pushDouble(struct call_context **context, uint_fast8_t *currentSSE,
double value)
{
struct call_context *newContext;
if (*currentSSE < NUM_SSE_INOUT) {
(*context)->SSE[(*currentSSE)++] = (__m128)_mm_set_sd(value);
(*context)->numSSEUsed++;
return;
}
if ((newContext = realloc(*context,
sizeof(**context) + ((*context)->stackSize + 1) * 8)) == NULL) {
free(*context);
@throw [OFOutOfMemoryException exceptionWithRequestedSize:
sizeof(**context) + ((*context)->stackSize + 1) * 8];
}
memcpy(&newContext->stack[newContext->stackSize], &value, 8);
newContext->stackSize++;
*context = newContext;
}
static void
pushQuad(struct call_context **context, uint_fast8_t *currentSSE,
double low, double high)
{
size_t stackSize;
struct call_context *newContext;
if (*currentSSE + 1 < NUM_SSE_INOUT) {
(*context)->SSE[(*currentSSE)++] = (__m128)_mm_set_sd(low);
(*context)->SSE[(*currentSSE)++] = (__m128)_mm_set_sd(high);
(*context)->numSSEUsed += 2;
return;
}
stackSize = (*context)->stackSize + 2;
if ((newContext = realloc(*context,
sizeof(**context) + stackSize * 8)) == NULL) {
free(*context);
@throw [OFOutOfMemoryException exceptionWithRequestedSize:
sizeof(**context) + stackSize * 8];
}
memset(&newContext->stack[newContext->stackSize], '\0',
(stackSize - newContext->stackSize) * 8);
memcpy(&newContext->stack[stackSize - 2], &low, 8);
memcpy(&newContext->stack[stackSize - 1], &high, 8);
newContext->stackSize = stackSize;
*context = newContext;
}
static void
pushLongDouble(struct call_context **context, long double value)
{
struct call_context *newContext;
if ((newContext = realloc(*context,
sizeof(**context) + ((*context)->stackSize + 2) * 8)) == NULL) {
free(*context);
@throw [OFOutOfMemoryException exceptionWithRequestedSize:
sizeof(**context) + ((*context)->stackSize + 2) * 8];
}
memcpy(&newContext->stack[newContext->stackSize], &value, 16);
newContext->stackSize += 2;
*context = newContext;
}
static void
pushLongDoublePair(struct call_context **context, long double value[2])
{
size_t stackSize;
struct call_context *newContext;
stackSize = OF_ROUND_UP_POW2(2UL, (*context)->stackSize) + 4;
if ((newContext = realloc(*context,
sizeof(**context) + stackSize * 8)) == NULL) {
free(*context);
@throw [OFOutOfMemoryException exceptionWithRequestedSize:
sizeof(**context) + stackSize * 8];
}
memset(&newContext->stack[newContext->stackSize], '\0',
(stackSize - newContext->stackSize) * 8);
memcpy(&newContext->stack[stackSize - 4], value, 32);
newContext->stackSize = stackSize;
*context = newContext;
}
#if defined(__SIZEOF_INT128__) && !defined(__clang__)
static void
pushInt128(struct call_context **context, uint_fast8_t *currentGPR,
uint64_t value[2])
{
size_t stackSize;
struct call_context *newContext;
if (*currentGPR + 1 < NUM_GPR_IN) {
(*context)->GPR[(*currentGPR)++] = value[0];
(*context)->GPR[(*currentGPR)++] = value[1];
return;
}
stackSize = OF_ROUND_UP_POW2(2, (*context)->stackSize) + 2;
if ((newContext = realloc(*context,
sizeof(**context) + stackSize * 8)) == NULL) {
free(*context);
@throw [OFOutOfMemoryException exceptionWithRequestedSize:
sizeof(**context) + stackSize * 8];
}
memset(&newContext->stack[newContext->stackSize], '\0',
(stackSize - newContext->stackSize) * 8);
memcpy(&newContext->stack[stackSize - 2], value, 16);
newContext->stackSize = stackSize;
*context = newContext;
}
#endif
void
of_invocation_invoke(OFInvocation *invocation)
{
OFMethodSignature *methodSignature = invocation.methodSignature;
size_t numberOfArguments = methodSignature.numberOfArguments;
struct call_context *context;
const char *typeEncoding;
uint_fast8_t currentGPR = 0, currentSSE = 0;
if ((context = calloc(sizeof(*context), 1)) == NULL)
@throw [OFOutOfMemoryException exception];
for (size_t i = 0; i < numberOfArguments; i++) {
typeEncoding = [methodSignature argumentTypeAtIndex: i];
if (*typeEncoding == 'r')
typeEncoding++;
switch (*typeEncoding) {
#define CASE_GPR(encoding, type) \
case encoding: \
{ \
type tmp; \
[invocation getArgument: &tmp \
atIndex: i]; \
pushGPR(&context, ¤tGPR, (uint64_t)tmp); \
} \
break;
CASE_GPR('c', char)
CASE_GPR('C', unsigned char)
CASE_GPR('i', int)
CASE_GPR('I', unsigned int)
CASE_GPR('s', short)
CASE_GPR('S', unsigned short)
CASE_GPR('l', long)
CASE_GPR('L', unsigned long)
CASE_GPR('q', long long)
CASE_GPR('Q', unsigned long long)
CASE_GPR('B', _Bool)
CASE_GPR('*', char *)
CASE_GPR('@', id)
CASE_GPR('#', Class)
/*
* Using SEL triggers a warning that casting a SEL to an
* integer is deprecated.
*/
CASE_GPR(':', void *)
CASE_GPR('^', void *)
#undef CASE_GPR
#ifdef __SIZEOF_INT128__
case 't':
case 'T':;
uint64_t int128Tmp[2];
[invocation getArgument: &int128Tmp
atIndex: i];
# ifndef __clang__
pushInt128(&context, ¤tGPR, int128Tmp);
# else
/* See https://bugs.llvm.org/show_bug.cgi?id=34646 */
pushGPR(&context, ¤tGPR, int128Tmp[0]);
pushGPR(&context, ¤tGPR, int128Tmp[1]);
# endif
break;
#endif
case 'f':;
double floatTmp = 0;
[invocation getArgument: &floatTmp
atIndex: i];
pushDouble(&context, ¤tSSE, floatTmp);
break;
case 'd':;
double doubleTmp;
[invocation getArgument: &doubleTmp
atIndex: i];
pushDouble(&context, ¤tSSE, doubleTmp);
break;
case 'D':;
long double longDoubleTmp;
[invocation getArgument: &longDoubleTmp
atIndex: i];
pushLongDouble(&context, longDoubleTmp);
break;
case 'j':
switch (typeEncoding[1]) {
case 'f':;
double complexFloatTmp;
[invocation getArgument: &complexFloatTmp
atIndex: i];
pushDouble(&context, ¤tSSE,
complexFloatTmp);
break;
case 'd':;
double complexDoubleTmp[2];
[invocation getArgument: &complexDoubleTmp
atIndex: i];
pushQuad(&context, ¤tSSE,
complexDoubleTmp[0], complexDoubleTmp[1]);
break;
case 'D':;
long double complexLongDoubleTmp[2];
[invocation getArgument: &complexLongDoubleTmp
atIndex: i];
pushLongDoublePair(&context,
complexLongDoubleTmp);
break;
default:
free(context);
@throw [OFInvalidFormatException exception];
}
break;
/* TODO: '[' */
/* TODO: '{' */
/* TODO: '(' */
default:
free(context);
@throw [OFInvalidFormatException exception];
}
}
typeEncoding = methodSignature.methodReturnType;
if (*typeEncoding == 'r')
typeEncoding++;
switch (*typeEncoding) {
case 'v':
case 'c':
case 'C':
case 'i':
case 'I':
case 's':
case 'S':
case 'l':
case 'L':
case 'q':
case 'Q':
case 'B':
case '*':
case '@':
case '#':
case ':':
case '^':
#ifdef __SIZEOF_INT128__
case 't':
case 'T':
#endif
case 'f':
case 'd':
context->returnType = RETURN_TYPE_NORMAL;
break;
case 'D':
context->returnType = RETURN_TYPE_X87;
break;
case 'j':
switch (typeEncoding[1]) {
case 'f':
case 'd':
context->returnType = RETURN_TYPE_NORMAL;
break;
case 'D':
context->returnType = RETURN_TYPE_COMPLEX_X87;
break;
default:
free(context);
@throw [OFInvalidFormatException exception];
}
break;
/* TODO: '[' */
/* TODO: '{' */
/* TODO: '(' */
default:
free(context);
@throw [OFInvalidFormatException exception];
}
of_invocation_call(context);
switch (*typeEncoding) {
case 'v':
break;
#define CASE_GPR(encoding, type) \
case encoding: \
{ \
type tmp = (type)context->GPR[NUM_GPR_IN]; \
[invocation setReturnValue: &tmp]; \
} \
break;
CASE_GPR('c', char)
CASE_GPR('C', unsigned char)
CASE_GPR('i', int)
CASE_GPR('I', unsigned int)
CASE_GPR('s', short)
CASE_GPR('S', unsigned short)
CASE_GPR('l', long)
CASE_GPR('L', unsigned long)
CASE_GPR('q', long long)
CASE_GPR('Q', unsigned long long)
CASE_GPR('B', _Bool)
CASE_GPR('*', char *)
CASE_GPR('@', id)
CASE_GPR('#', Class)
CASE_GPR(':', SEL)
CASE_GPR('^', void *)
#undef CASE_GPR
#ifdef __SIZEOF_INT128__
case 't':
case 'T':;
[invocation setReturnValue: &context->GPR[NUM_GPR_IN]];
break;
#endif
case 'f':;
float floatTmp;
_mm_store_ss(&floatTmp, context->SSE[0]);
[invocation setReturnValue: &floatTmp];
break;
case 'd':;
double doubleTmp;
_mm_store_sd(&doubleTmp, (__m128d)context->SSE[0]);
[invocation setReturnValue: &doubleTmp];
break;
case 'D':
[invocation setReturnValue: &context->X87[0]];
break;
case 'j':
switch (typeEncoding[1]) {
case 'f':;
double complexFloatTmp;
_mm_store_sd(&complexFloatTmp,
(__m128d)context->SSE[0]);
[invocation setReturnValue: &complexFloatTmp];
break;
case 'd':;
double complexDoubleTmp[2];
_mm_store_sd(&complexDoubleTmp[0],
(__m128d)context->SSE[0]);
_mm_store_sd(&complexDoubleTmp[1],
(__m128d)context->SSE[1]);
[invocation setReturnValue: &complexDoubleTmp];
break;
case 'D':
[invocation setReturnValue: context->X87];
break;
default:
free(context);
@throw [OFInvalidFormatException exception];
}
break;
/* TODO: '[' */
/* TODO: '{' */
/* TODO: '(' */
default:
free(context);
@throw [OFInvalidFormatException exception];
}
free(context);
}
|
Deleted src/invocation/invoke.m version [619adef304].
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
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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"
#include "platform.h"
#if defined(OF_X86_64) && (defined(OF_APPLE_RUNTIME) || defined(OF_ELF))
# include "invoke-x86_64.m"
#else
/* To not have an empty translation unit otherwise */
int of_invocation_cannot_invoke;
#endif
|
Modified src/objfw-defs.h.in
from [4530c4317b]
to [993881fae7].
︙ | | |
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
-
|
#undef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR
#undef OF_HAVE_IPV6
#undef OF_HAVE_IPX
#undef OF_HAVE_LIMITS_H
#undef OF_HAVE_LINK
#undef OF_HAVE_MAX_ALIGN_T
#undef OF_HAVE_NETINET_IN_H
#undef OF_HAVE_NETINET_SCTP_H
#undef OF_HAVE_NETINET_TCP_H
#undef OF_HAVE_NETIPX_IPX_H
#undef OF_HAVE_OSATOMIC
#undef OF_HAVE_OSATOMIC_64
#undef OF_HAVE_PIPE
#undef OF_HAVE_PLEDGE
#undef OF_HAVE_PLUGINS
|
︙ | | |
Deleted src/runtime/lookup-asm/lookup-asm-x86_64-macho.S version [1d842ab593].
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
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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"
.intel_syntax noprefix
.globl _objc_msg_lookup
.globl _objc_msg_lookup_stret
.globl _objc_msg_lookup_super
.globl _objc_msg_lookup_super_stret
.section __TEXT, __text, regular, pure_instructions
.macro generate_lookup
$0:
test rdi, rdi
jz ret_nil
bt edi, 0
jc Ltagged_pointer_$0
mov r8, [rdi]
mov r8, [r8+64]
Lmain_$0:
mov rax, [rsi]
movzx ecx, ah
movzx edx, al
#ifdef OF_SELUID24
shr eax, 16
mov r8, [r8+rax*8]
#endif
mov r8, [r8+rcx*8]
mov rax, [r8+rdx*8]
test rax, rax
jz $1
ret
Ltagged_pointer_$0:
mov rax, [rip+_objc_tagged_pointer_secret@GOTPCREL]
xor rdi, [rax]
and dil, 0xE
movzx r8, dil
mov rax, [rip+_objc_tagged_pointer_classes@GOTPCREL]
mov r8, [rax+r8*4]
mov r8, [r8+64]
jmp Lmain_$0
.endmacro
.macro generate_lookup_super
$0:
mov r8, rdi
mov rdi, [rdi]
test rdi, rdi
jz ret_nil
mov r8, [r8+8]
mov r8, [r8+64]
jmp Lmain_$1
.endmacro
generate_lookup _objc_msg_lookup, _objc_method_not_found
generate_lookup _objc_msg_lookup_stret, _objc_method_not_found_stret
generate_lookup_super _objc_msg_lookup_super, _objc_msg_lookup
generate_lookup_super _objc_msg_lookup_super_stret, _objc_msg_lookup_stret
ret_nil:
lea rax, [rip+nil_method]
ret
nil_method:
mov rax, rdi
ret
|
Modified src/runtime/lookup-asm/lookup-asm.S
from [4908be8ba8]
to [79ebaba74d].
︙ | | |
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
-
-
-
-
|
# elif defined(OF_MIPS)
# include "lookup-asm-mips-elf.S"
# elif defined(OF_SPARC64)
# include "lookup-asm-sparc64-elf.S"
# elif defined(OF_SPARC)
# include "lookup-asm-sparc-elf.S"
# endif
#elif defined(OF_MACH_O)
# if defined(OF_X86_64)
# include "lookup-asm-x86_64-macho.S"
# endif
#elif defined(OF_WINDOWS)
# if defined(OF_X86_64)
# include "lookup-asm-x86_64-win64.S"
# elif defined(OF_X86)
# include "lookup-asm-x86-win32.S"
# endif
#endif
|
Modified src/runtime/private.h
from [049226b1f0]
to [21af80272e].
︙ | | |
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
|
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
-
-
-
-
|
}
#if defined(OF_ELF)
# if defined(OF_X86_64) || defined(OF_X86) || defined(OF_POWERPC) || \
defined(OF_ARM64) || defined(OF_ARM) || \
defined(OF_MIPS64_N64) || defined(OF_MIPS) || \
defined(OF_SPARC64) || defined(OF_SPARC)
# define OF_ASM_LOOKUP
# endif
#elif defined(OF_MACH_O)
# if defined(OF_X86_64)
# define OF_ASM_LOOKUP
# endif
#elif defined(OF_WINDOWS)
# if defined(OF_X86_64) || defined(OF_X86)
# define OF_ASM_LOOKUP
# endif
#endif
|
︙ | | |
Modified src/socket.h
from [fc5416a7db]
to [a0b49c9437].
︙ | | |
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
-
-
-
|
#endif
#ifdef OF_HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
#ifdef OF_HAVE_NETINET_TCP_H
# include <netinet/tcp.h>
#endif
#ifdef OF_HAVE_NETINET_SCTP_H
# include <netinet/sctp.h>
#endif
#ifdef OF_HAVE_NETIPX_IPX_H
# include <netipx/ipx.h>
#endif
#include "platform.h"
#ifdef OF_WINDOWS
|
︙ | | |
Modified tests/Makefile
from [6a6c363390]
to [a491bea751].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
-
-
|
include ../extra.mk
SUBDIRS = ${TESTPLUGIN}
CLEAN = EBOOT.PBP \
boot.dol \
${PROG_NOINST}.arm9 \
${PROG_NOINST}.nds
DISTCLEAN = Info.plist
PROG_NOINST = tests${PROG_SUFFIX}
STATIC_LIB_NOINST = ${TESTS_STATIC_LIB}
SRCS = ForwardingTests.m \
OFASN1DERParsingTests.m \
OFASN1DERRepresentationTests.m \
OFArrayTests.m \
${OF_BLOCK_TESTS_M} \
OFCharacterSetTests.m \
OFDataTests.m \
OFDateTests.m \
OFDictionaryTests.m \
OFInvocationTests.m \
|
︙ | | |
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
|
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
-
-
+
-
|
OFSHA256HashTests.m \
OFSHA384HashTests.m \
OFSHA512HashTests.m
SRCS_IPX = OFIPXSocketTests.m \
OFSPXSocketTests.m \
OFSPXStreamSocketTests.m
SRCS_PLUGINS = OFPluginTests.m
SRCS_SCTP = OFSCTPSocketTests.m
SRCS_SOCKETS = OFDNSResolverTests.m \
${OF_HTTP_CLIENT_TESTS_M} \
OFHTTPCookieTests.m \
OFHTTPCookieManagerTests.m \
OFKernelEventObserverTests.m \
OFTCPSocketTests.m \
OFUDPSocketTests.m \
SocketTests.m \
${USE_SRCS_IPX} \
${USE_SRCS_IPX}
${USE_SRCS_SCTP}
SRCS_THREADS = OFThreadTests.m
SRCS_WINDOWS = OFWindowsRegistryKeyTests.m
IOS_USER ?= mobile
IOS_TMP ?= /tmp/objfw-test
include ../buildsys.mk
|
︙ | | |
Deleted tests/OFASN1DERParsingTests.m version [dd4c3da7d2].
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "TestsAppDelegate.h"
static OFString *module = @"OFData+ASN1DERParsing";
@implementation TestsAppDelegate (OFASN1DERParsingTests)
- (void)ASN1DERParsingTests
{
void *pool = objc_autoreleasePoolPush();
OFASN1BitString *bitString;
OFArray *array;
OFSet *set;
OFEnumerator *enumerator;
/* Boolean */
TEST(@"Parsing of boolean",
![[[OFData dataWithItems: "\x01\x01\x00"
count: 3] objectByParsingASN1DER]
booleanValue] &&
[[[OFData dataWithItems: "\x01\x01\xFF"
count: 3] objectByParsingASN1DER] booleanValue])
EXPECT_EXCEPTION(@"Detection of invalid boolean #1",
OFInvalidFormatException,
[[OFData dataWithItems: "\x01\x01\x01"
count: 3] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of invalid boolean #2",
OFInvalidFormatException,
[[OFData dataWithItems: "\x01\x02\x00\x00"
count: 4] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of invalid boolean #3",
OFInvalidFormatException,
[[OFData dataWithItems: "\x01\x00"
count: 2] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated boolean",
OFTruncatedDataException,
[[OFData dataWithItems: "\x01\x01"
count: 2] objectByParsingASN1DER])
/* Integer */
TEST(@"Parsing of integer",
[[[OFData dataWithItems: "\x02\x00"
count: 2] objectByParsingASN1DER]
longLongValue] == 0 &&
[[[OFData dataWithItems: "\x02\x01\x01"
count: 3] objectByParsingASN1DER]
longLongValue] == 1 &&
[[[OFData dataWithItems: "\x02\x02\x01\x04"
count: 4] objectByParsingASN1DER]
longLongValue] == 260 &&
[[[OFData dataWithItems: "\x02\x01\xFF"
count: 3] objectByParsingASN1DER]
longLongValue] == -1 &&
[[[OFData dataWithItems: "\x02\x03\xFF\x00\x00"
count: 5] objectByParsingASN1DER]
longLongValue] == -65536 &&
(unsigned long long)[[[OFData dataWithItems: "\x02\x09\x00\xFF\xFF"
"\xFF\xFF\xFF\xFF\xFF"
"\xFF"
count: 11]
objectByParsingASN1DER] longLongValue] == ULLONG_MAX)
EXPECT_EXCEPTION(@"Detection of invalid integer #1",
OFInvalidFormatException,
[[OFData dataWithItems: "\x02\x02\x00\x00"
count: 4] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of invalid integer #2",
OFInvalidFormatException,
[[OFData dataWithItems: "\x02\x02\x00\x7F"
count: 4] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of invalid integer #3",
OFInvalidFormatException,
[[OFData dataWithItems: "\x02\x02\xFF\x80"
count: 4] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of out of range integer",
OFOutOfRangeException,
[[OFData dataWithItems: "\x02\x09\x01"
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
count: 11] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated integer",
OFTruncatedDataException,
[[OFData dataWithItems: "\x02\x02\x00"
count: 3] objectByParsingASN1DER])
/* Bit string */
TEST(@"Parsing of bit string",
(bitString = [[OFData dataWithItems: "\x03\x01\x00"
count: 3] objectByParsingASN1DER]) &&
[bitString.bitStringValue isEqual: [OFData dataWithItems: ""
count: 0]] &&
bitString.bitStringLength == 0 &&
(bitString = [[OFData dataWithItems: "\x03\x0D\x01Hello World\x80"
count: 15] objectByParsingASN1DER]) &&
[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] objectByParsingASN1DER]) &&
[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] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of invalid bit string #2",
OFInvalidFormatException,
[[OFData dataWithItems: "\x03\x01\x01"
count: 3] objectByParsingASN1DER])
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] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated bit string",
OFTruncatedDataException,
[[OFData dataWithItems: "\x03\x01"
count: 2] objectByParsingASN1DER])
/* Octet string */
TEST(@"Parsing of octet string",
[[[[OFData dataWithItems: "\x04\x0CHello World!"
count: 14] objectByParsingASN1DER]
octetStringValue] isEqual: [OFData dataWithItems: "Hello World!"
count: 12]] &&
[[[[OFData dataWithItems: "\x04\x81\x80xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxx"
count: 131] objectByParsingASN1DER]
octetStringValue] isEqual:
[OFData dataWithItems: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
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] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated octet string",
OFTruncatedDataException,
[[OFData dataWithItems: "\x04\x01"
count: 2] objectByParsingASN1DER])
/* Null */
TEST(@"Parsing of null",
[[[OFData dataWithItems: "\x05\x00"
count: 2] objectByParsingASN1DER]
isEqual: [OFNull null]])
EXPECT_EXCEPTION(@"Detection of invalid null",
OFInvalidFormatException,
[[OFData dataWithItems: "\x05\x01\x00"
count: 3] objectByParsingASN1DER])
/* Object Identifier */
TEST(@"Parsing of Object Identifier",
(array = [[[OFData dataWithItems: "\x06\x01\x27"
count: 3] objectByParsingASN1DER]
subidentifiers]) && array.count == 2 &&
[[array objectAtIndex: 0] unsignedLongLongValue] == 0 &&
[[array objectAtIndex: 1] unsignedLongLongValue] == 39 &&
(array = [[[OFData dataWithItems: "\x06\x01\x4F"
count: 3] objectByParsingASN1DER]
subidentifiers]) && array.count == 2 &&
[[array objectAtIndex: 0] unsignedLongLongValue] == 1 &&
[[array objectAtIndex: 1] unsignedLongLongValue] == 39 &&
(array = [[[OFData dataWithItems: "\x06\x02\x88\x37"
count: 4] objectByParsingASN1DER]
subidentifiers]) && array.count == 2 &&
[[array objectAtIndex: 0] unsignedLongLongValue] == 2 &&
[[array objectAtIndex: 1] unsignedLongLongValue] == 999 &&
(array = [[[OFData dataWithItems: "\x06\x09\x2A\x86\x48\x86\xF7\x0D"
"\x01\x01\x0B"
count: 11] objectByParsingASN1DER]
subidentifiers]) && array.count == 7 &&
[[array objectAtIndex: 0] unsignedLongLongValue] == 1 &&
[[array objectAtIndex: 1] unsignedLongLongValue] == 2 &&
[[array objectAtIndex: 2] unsignedLongLongValue] == 840 &&
[[array objectAtIndex: 3] unsignedLongLongValue] == 113549 &&
[[array objectAtIndex: 4] unsignedLongLongValue] == 1 &&
[[array objectAtIndex: 5] unsignedLongLongValue] == 1 &&
[[array objectAtIndex: 6] unsignedLongLongValue] == 11)
EXPECT_EXCEPTION(@"Detection of invalid Object Identifier #1",
OFInvalidFormatException,
[[OFData dataWithItems: "\x06\x01\x81"
count: 3] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of invalid Object Identifier #2",
OFInvalidFormatException,
[[OFData dataWithItems: "\x06\x02\x80\x01"
count: 4] objectByParsingASN1DER])
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] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated Object Identifier",
OFTruncatedDataException,
[[OFData dataWithItems: "\x06\x02\x00"
count: 3] objectByParsingASN1DER])
/* Enumerated */
TEST(@"Parsing of enumerated",
[[[OFData dataWithItems: "\x0A\x00"
count: 2] objectByParsingASN1DER] longLongValue] ==
0 &&
[[[OFData dataWithItems: "\x0A\x01\x01"
count: 3] objectByParsingASN1DER] longLongValue] ==
1 &&
[[[OFData dataWithItems: "\x0A\x02\x01\x04"
count: 4] objectByParsingASN1DER] longLongValue] ==
260 &&
[[[OFData dataWithItems: "\x0A\x01\xFF"
count: 3] objectByParsingASN1DER] longLongValue] ==
-1 &&
[[[OFData dataWithItems: "\x0A\x03\xFF\x00\x00"
count: 5] objectByParsingASN1DER] longLongValue] ==
-65536 &&
(unsigned long long)[[[OFData dataWithItems: "\x0A\x09\x00\xFF\xFF"
"\xFF\xFF\xFF\xFF\xFF"
"\xFF"
count: 11]
objectByParsingASN1DER] longLongValue] == ULLONG_MAX)
EXPECT_EXCEPTION(@"Detection of invalid enumerated #1",
OFInvalidFormatException,
[[OFData dataWithItems: "\x0A\x02\x00\x00"
count: 4] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of invalid enumerated #2",
OFInvalidFormatException,
[[OFData dataWithItems: "\x0A\x02\x00\x7F"
count: 4] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of invalid enumerated #3",
OFInvalidFormatException,
[[OFData dataWithItems: "\x0A\x02\xFF\x80"
count: 4] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of out of range enumerated",
OFOutOfRangeException,
[[OFData dataWithItems: "\x0A\x09\x01"
"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
count: 11] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated enumerated",
OFTruncatedDataException,
[[OFData dataWithItems: "\x0A\x02\x00"
count: 3] objectByParsingASN1DER])
/* UTF-8 string */
TEST(@"Parsing of UTF-8 string",
[[[[OFData dataWithItems: "\x0C\x0EHällo Wörld!"
count: 16] objectByParsingASN1DER]
UTF8StringValue] isEqual: @"Hällo Wörld!"] &&
[[[[OFData dataWithItems: "\x0C\x81\x80xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxx"
count: 131] objectByParsingASN1DER]
UTF8StringValue] isEqual: @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
@"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
@"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
@"xxxxxxxxxxx"])
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] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated UTF-8 string",
OFTruncatedDataException,
[[OFData dataWithItems: "\x0C\x01"
count: 2] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated length",
OFTruncatedDataException,
[[OFData dataWithItems: "\x0C\x83\x01\x01"
count: 4] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of invalid / inefficient length #1",
OFInvalidFormatException,
[[OFData dataWithItems: "\x0C\x81\x7F"
count: 3] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of invalid / inefficient length #2",
OFInvalidFormatException,
[[OFData dataWithItems: "\x0C\x82\x00\x80xxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxx"
count: 132] objectByParsingASN1DER])
/* Sequence */
TEST(@"Parsing of sequence",
(array = [[OFData dataWithItems: "\x30\x00"
count: 2] objectByParsingASN1DER]) &&
[array isKindOfClass: [OFArray class]] && array.count == 0 &&
(array = [[OFData dataWithItems: "\x30\x09\x02\x01\x7B\x0C\x04Test"
count: 11] objectByParsingASN1DER]) &&
[array isKindOfClass: [OFArray class]] && array.count == 2 &&
[[array objectAtIndex: 0] longLongValue] == 123 &&
[[[array objectAtIndex: 1] stringValue] isEqual: @"Test"])
EXPECT_EXCEPTION(@"Detection of truncated sequence #1",
OFTruncatedDataException,
[[OFData dataWithItems: "\x30\x01"
count: 2] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated sequence #2",
OFTruncatedDataException,
[[OFData dataWithItems: "\x30\x04\x02\x01\x01\x00\x00"
count: 7] objectByParsingASN1DER])
/* Set */
TEST(@"Parsing of set",
(set = [[OFData dataWithItems: "\x31\x00"
count: 2] objectByParsingASN1DER]) &&
[set isKindOfClass: [OFSet class]] && set.count == 0 &&
(set = [[OFData dataWithItems: "\x31\x09\x02\x01\x7B\x0C\x04Test"
count: 11] objectByParsingASN1DER]) &&
[set isKindOfClass: [OFSet class]] && set.count == 2 &&
(enumerator = [set objectEnumerator]) &&
[[enumerator nextObject] longLongValue] == 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] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated set #1",
OFTruncatedDataException,
[[OFData dataWithItems: "\x31\x01"
count: 2] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated set #2",
OFTruncatedDataException,
[[OFData dataWithItems: "\x31\x04\x02\x01\x01\x00\x00"
count: 7] objectByParsingASN1DER])
/* NumericString */
TEST(@"Parsing of NumericString",
[[[[OFData dataWithItems: "\x12\x0B" "12345 67890"
count: 13] objectByParsingASN1DER]
numericStringValue] isEqual: @"12345 67890"] &&
[[[[OFData dataWithItems: "\x12\x81\x80" "0000000000000000000000000"
"0000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000"
"00000000000000000000000"
count: 131] objectByParsingASN1DER]
numericStringValue] isEqual: @"000000000000000000000000000000000000"
@"000000000000000000000000000000000000"
@"000000000000000000000000000000000000"
@"00000000000000000000"])
EXPECT_EXCEPTION(@"Detection of invalid NumericString",
OFInvalidEncodingException,
[[OFData dataWithItems: "\x12\x02."
count: 4] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of out of range NumericString",
OFOutOfRangeException,
[[OFData dataWithItems: "\x12\x89"
"\x01\x01\x01\x01\x01\x01\x01\x01\x01"
count: 11] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated NumericString",
OFTruncatedDataException,
[[OFData dataWithItems: "\x12\x01"
count: 2] objectByParsingASN1DER])
/* PrintableString */
TEST(@"Parsing of PrintableString",
[[[[OFData dataWithItems: "\x13\x0CHello World."
count: 14] objectByParsingASN1DER]
printableStringValue] isEqual: @"Hello World."] &&
[[[[OFData dataWithItems: "\x13\x81\x80 '()+,-./:=?abcdefghijklmnop"
"qrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '()"
"+,-./:=?abcdefghijklmnopqrstuvwxyzABCDEF"
"GHIJKLMNOPQRSTUVWXYZ"
count: 131] objectByParsingASN1DER]
printableStringValue] isEqual: @" '()+,-./:=?abcdefghijklmnopqrstuv"
@"wxyzABCDEFGHIJKLMNOPQRSTUVWXYZ '()"
@"+,-./:=?abcdefghijklmnopqrstuvwxyz"
@"ABCDEFGHIJKLMNOPQRSTUVWXYZ"])
EXPECT_EXCEPTION(@"Detection of invalid PrintableString",
OFInvalidEncodingException,
[[OFData dataWithItems: "\x13\x02;"
count: 4] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of out of range PrintableString",
OFOutOfRangeException,
[[OFData dataWithItems: "\x13\x89"
"\x01\x01\x01\x01\x01\x01\x01\x01\x01"
count: 11] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated PrintableString",
OFTruncatedDataException,
[[OFData dataWithItems: "\x13\x01"
count: 2] objectByParsingASN1DER])
/* IA5String */
TEST(@"Parsing of IA5String",
[[[[OFData dataWithItems: "\x16\x0CHello World!"
count: 14] objectByParsingASN1DER]
IA5StringValue] isEqual: @"Hello World!"] &&
[[[[OFData dataWithItems: "\x16\x81\x80xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"xxxxxxxxxxxxxxxxxxxx"
count: 131] objectByParsingASN1DER]
IA5StringValue] isEqual: @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
@"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
@"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
@"xxxxxxxx"])
EXPECT_EXCEPTION(@"Detection of invalid IA5String",
OFInvalidEncodingException,
[[OFData dataWithItems: "\x16\x02ä"
count: 4] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of out of range IA5String",
OFOutOfRangeException,
[[OFData dataWithItems: "\x16\x89"
"\x01\x01\x01\x01\x01\x01\x01\x01\x01"
count: 11] objectByParsingASN1DER])
EXPECT_EXCEPTION(@"Detection of truncated IA5String",
OFTruncatedDataException,
[[OFData dataWithItems: "\x16\x01"
count: 2] objectByParsingASN1DER])
objc_autoreleasePoolPop(pool);
}
@end
|
Deleted tests/OFASN1DERRepresentationTests.m version [6efb5a6e9d].
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
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "TestsAppDelegate.h"
static OFString *module;
@implementation TestsAppDelegate (OFASN1DERRepresentationTests)
- (void)ASN1DERRepresentationTests
{
void *pool = objc_autoreleasePoolPush();
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]])
objc_autoreleasePoolPop(pool);
}
@end
|
Modified tests/OFInvocationTests.m
from [2e969e8d08]
to [afee5baf5a].
︙ | | |
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
|
309
310
311
312
313
314
315
316
317
318
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
atIndex: 4]) &&
stp == stp2)
TEST(@"-[getArgument:atIndex:] #4", R([invocation getArgument: &st2
atIndex: 5]) &&
memcmp(&st, &st2, sizeof(st)) == 0)
#ifdef OF_INVOCATION_CAN_INVOKE
/* -[invoke] #1 */
selector = @selector(invocationTestMethod2:);
invocation = [OFInvocation invocationWithMethodSignature:
[self methodSignatureForSelector: selector]];
[invocation setArgument: &self
atIndex: 0];
[invocation setArgument: &selector
atIndex: 1];
[invocation setArgument: &self
atIndex: 2];
TEST(@"-[invoke] #1", R([invocation invoke]))
/* -[invoke] #2 */
selector = @selector(invocationTestMethod3::::::::::::::::);
invocation = [OFInvocation invocationWithMethodSignature:
[self methodSignatureForSelector: selector]];
[invocation setArgument: &self
atIndex: 0];
[invocation setArgument: &selector
atIndex: 1];
for (int j = 1; j <= 16; j++)
[invocation setArgument: &j
atIndex: j + 1];
int intResult;
TEST(@"-[invoke] #2", R([invocation invoke]) &&
R([invocation getReturnValue: &intResult]) && intResult == 8)
/* -[invoke] #3 */
selector = @selector(invocationTestMethod4::::::::::::::::);
invocation = [OFInvocation invocationWithMethodSignature:
[self methodSignatureForSelector: selector]];
[invocation setArgument: &self
atIndex: 0];
[invocation setArgument: &selector
atIndex: 1];
for (int j = 1; j <= 16; j++) {
double d = j;
[invocation setArgument: &d
atIndex: j + 1];
}
double doubleResult;
TEST(@"-[invoke] #3", R([invocation invoke]) &&
R([invocation getReturnValue: &doubleResult]) &&
doubleResult == 8.5)
/* -[invoke] #4 */
selector = @selector(invocationTestMethod5::::::::::::::::);
invocation = [OFInvocation invocationWithMethodSignature:
[self methodSignatureForSelector: selector]];
[invocation setArgument: &self
atIndex: 0];
[invocation setArgument: &selector
atIndex: 1];
for (int j = 1; j <= 16; j++) {
float f = j;
double d = j;
if (j == 1 || j == 10)
[invocation setArgument: &d
atIndex: j + 1];
else
[invocation setArgument: &f
atIndex: j + 1];
}
float floatResult;
TEST(@"-[invoke] #4", R([invocation invoke]) &&
R([invocation getReturnValue: &floatResult]) && floatResult == 8.5)
/* Only when encoding long doubles is supported */
if (strcmp(@encode(double), @encode(long double)) != 0) {
/* -[invoke] #5 */
selector = @selector(invocationTestMethod6::::::::::::::::);
invocation = [OFInvocation invocationWithMethodSignature:
[self methodSignatureForSelector: selector]];
[invocation setArgument: &self
atIndex: 0];
[invocation setArgument: &selector
atIndex: 1];
for (int j = 1; j <= 16; j++) {
long double d = j;
[invocation setArgument: &d
atIndex: j + 1];
}
long double longDoubleResult;
TEST(@"-[invoke] #5", R([invocation invoke]) &&
R([invocation getReturnValue: &longDoubleResult]) &&
longDoubleResult == 8.5)
}
# if defined(HAVE_COMPLEX_H) && !defined(__STDC_NO_COMPLEX__)
/* -[invoke] #6 */
selector = @selector(invocationTestMethod7::::::::::::::::);
invocation = [OFInvocation invocationWithMethodSignature:
[self methodSignatureForSelector: selector]];
[invocation setArgument: &self
atIndex: 0];
[invocation setArgument: &selector
atIndex: 1];
for (int j = 1; j <= 16; j++) {
complex float cf = j + 0.5 * j * I;
complex double cd = j + 0.5 * j * I;
if (j & 1)
[invocation setArgument: &cf
atIndex: j + 1];
else
[invocation setArgument: &cd
atIndex: j + 1];
}
complex double complexDoubleResult;
TEST(@"-[invoke] #6", R([invocation invoke]) &&
R([invocation getReturnValue: &complexDoubleResult]) &&
complexDoubleResult == 8.5 + 4.25 * I)
/* Only when encoding complex long doubles is supported */
if (strcmp(@encode(complex double),
@encode(complex long double)) != 0) {
/* -[invoke] #7 */
selector = @selector(invocationTestMethod8::::::::::::::::);
invocation = [OFInvocation invocationWithMethodSignature:
[self methodSignatureForSelector: selector]];
[invocation setArgument: &self
atIndex: 0];
[invocation setArgument: &selector
atIndex: 1];
for (int j = 1; j <= 16; j++) {
complex double cd = j + 0.5 * j * I;
complex float cf = j + 0.5 * j * I;
complex long double cld = j + 0.5 * j * I;
switch (j % 3) {
case 0:
[invocation setArgument: &cld
atIndex: j + 1];
break;
case 1:
[invocation setArgument: &cd
atIndex: j + 1];
break;
case 2:
[invocation setArgument: &cf
atIndex: j + 1];
break;
}
}
complex long double complexLongDoubleResult;
TEST(@"-[invoke] #7", R([invocation invoke]) &&
R([invocation getReturnValue: &complexLongDoubleResult]) &&
complexLongDoubleResult == 8.5 + 4.25 * I)
}
# endif
# ifdef __SIZEOF_INT128__
/* -[invoke] #8 */
selector = @selector(invocationTestMethod9::::::::::::::::);
invocation = [OFInvocation invocationWithMethodSignature:
[self methodSignatureForSelector: selector]];
[invocation setArgument: &self
atIndex: 0];
[invocation setArgument: &selector
atIndex: 1];
for (int j = 1; j <= 16; j++) {
__extension__ __int128 i128 = 0xFFFFFFFFFFFFFFFF;
i128 <<= 64;
i128 |= j;
if (j == 1 || j == 5)
[invocation setArgument: &j
atIndex: j + 1];
else
[invocation setArgument: &i128
atIndex: j + 1];
}
__extension__ __int128 int128Result;
TEST(@"-[invoke] #8", R([invocation invoke]) &&
R([invocation getReturnValue: &int128Result]) &&
int128Result == __extension__ ((__int128)0xFFFFFFFFFFFFFFFF << 64) +
8)
# endif
#endif
objc_autoreleasePoolPop(pool);
}
@end
|
Deleted tests/OFSCTPSocketTests.m version [810fa289fa].
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
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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"
#include <errno.h>
#include <string.h>
#import "TestsAppDelegate.h"
static OFString *module = @"OFSCTPSocket";
@implementation TestsAppDelegate (OFSCTPSocketTests)
- (void)SCTPSocketTests
{
void *pool = objc_autoreleasePoolPush();
OFSCTPSocket *server, *client = nil, *accepted;
uint16_t port;
char buf[6];
TEST(@"+[socket]", (server = [OFSCTPSocket socket]) &&
(client = [OFSCTPSocket socket]))
@try {
TEST(@"-[bindToHost:port:]",
(port = [server bindToHost: @"127.0.0.1"
port: 0]))
} @catch (OFBindFailedException *e) {
switch (e.errNo) {
case EPROTONOSUPPORT:
[of_stdout setForegroundColor: [OFColor lime]];
[of_stdout writeLine:
@"[OFSCTPSocket] -[bindToHost:port:]: "
@"SCTP unsupported, skipping tests"];
break;
default:
@throw e;
}
objc_autoreleasePoolPop(pool);
return;
}
TEST(@"-[listen]", R([server listen]))
TEST(@"-[connectToHost:port:]",
R([client connectToHost: @"127.0.0.1"
port: port]))
TEST(@"-[accept]", (accepted = [server accept]))
TEST(@"-[remoteAddress]",
[of_socket_address_ip_string(accepted.remoteAddress, NULL)
isEqual: @"127.0.0.1"])
TEST(@"-[sendBuffer:length:]", R([client sendBuffer: "Hello!"
length: 6]))
TEST(@"-[receiveIntoBuffer:length:]", [accepted receiveIntoBuffer: buf
length: 6] &&
!memcmp(buf, "Hello!", 6))
objc_autoreleasePoolPop(pool);
}
@end
|
Modified tests/TestsAppDelegate.h
from [474ebe8ce9]
to [9d4e5d8bfc].
︙ | | |
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
-
-
-
-
-
-
-
-
|
inModule: (OFString *)module;
- (void)outputSuccess: (OFString *)test
inModule: (OFString *)module;
- (void)outputFailure: (OFString *)test
inModule: (OFString *)module;
@end
@interface TestsAppDelegate (OFASN1DERParsingTests)
- (void)ASN1DERParsingTests;
@end
@interface TestsAppDelegate (OFASN1DERRepresentationTests)
- (void)ASN1DERRepresentationTests;
@end
@interface TestsAppDelegate (OFArrayTests)
- (void)arrayTests;
@end
@interface TestsAppDelegate (OFBlockTests)
- (void)blockTests;
@end
|
︙ | | |
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
-
-
-
-
|
- (void)SHA384HashTests;
@end
@interface TestsAppDelegate (OFSHA512HashTests)
- (void)SHA512HashTests;
@end
@interface TestsAppDelegate (OFSCTPSocketTests)
- (void)SCTPSocketTests;
@end
@interface TestsAppDelegate (OFSPXSocketTests)
- (void)SPXSocketTests;
@end
@interface TestsAppDelegate (OFSPXStreamSocketTests)
- (void)SPXStreamSocketTests;
@end
|
︙ | | |
Modified tests/TestsAppDelegate.m
from [7de17ddfab]
to [bee16b75be].
︙ | | |
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
350
351
352
353
354
355
356
357
358
359
360
361
362
363
|
-
-
-
|
#if defined(OF_HAVE_FILES) && defined(HAVE_CODEPAGE_437)
[self INIFileTests];
#endif
#ifdef OF_HAVE_SOCKETS
[self socketTests];
[self TCPSocketTests];
[self UDPSocketTests];
# ifdef OF_HAVE_SCTP
[self SCTPSocketTests];
# endif
# ifdef OF_HAVE_IPX
[self IPXSocketTests];
[self SPXSocketTests];
[self SPXStreamSocketTests];
# endif
[self kernelEventObserverTests];
#endif
|
︙ | | |
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
|
376
377
378
379
380
381
382
383
384
385
386
387
388
389
|
-
-
|
[self XMLNodeTests];
[self XMLElementBuilderTests];
#ifdef OF_HAVE_FILES
[self serializationTests];
#endif
[self JSONTests];
[self propertyListTests];
[self ASN1DERParsingTests];
[self ASN1DERRepresentationTests];
#if defined(OF_HAVE_PLUGINS)
[self pluginTests];
#endif
#ifdef OF_WINDOWS
[self windowsRegistryKeyTests];
#endif
|
︙ | | |
Modified utils/Makefile
from [82be3d0820]
to [521b7f89ce].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
-
|
include ../extra.mk
SUBDIRS += ${OFARC} \
${OFDNS} \
${OFHASH} \
${OFHTTP} \
${OFSOCK} \
completions
include ../buildsys.mk
DISTCLEAN = objfw-config
install-extra: objfw-config objfw-compile objfw-new
|
︙ | | |
Deleted utils/ofsock/Makefile version [0438ba0691].
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
include ../../extra.mk
PROG = ofsock${PROG_SUFFIX}
SRCS = OFSock.m
include ../../buildsys.mk
PACKAGE_NAME = ofsock
${PROG}: ${LIBOBJFW_DEP_LVL2} ${LIBOBJFWRT_DEP_LVL2}
CPPFLAGS += -I../../src \
-I../../src/runtime \
-I../../src/exceptions \
-I../..
LIBS := -L../../src -lobjfw \
-L../../src/runtime -L../../src/runtime/linklib ${RUNTIME_LIBS} \
${LIBS}
LD = ${OBJC}
LDFLAGS += ${LDFLAGS_RPATH}
|
Deleted utils/ofsock/OFSock.m version [9ce3b460c5].
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
* 2018, 2019, 2020
* 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 "OFApplication.h"
#import "OFArray.h"
#import "OFNumber.h"
#import "OFPair.h"
#import "OFStdIOStream.h"
#import "OFStream.h"
#import "OFString.h"
#import "OFTCPSocket.h"
#import "OFURL.h"
#define BUFFER_LEN 4096
@interface OFSock: OFObject <OFApplicationDelegate, OFStreamDelegate>
{
char _buffer[BUFFER_LEN];
OFMutableArray OF_GENERIC(OFPair OF_GENERIC(OFStream *, OFStream *) *)
*_streams;
int _errors;
}
@end
OF_APPLICATION_DELEGATE(OFSock)
static OFPair OF_GENERIC(OFStream *, OFStream *) *
streamFromString(OFString *string)
{
OFURL *URL;
OFString *scheme;
if ([string isEqual: @"-"])
return [OFPair pairWithFirstObject: of_stdin
secondObject: of_stdout];
URL = [OFURL URLWithString: string];
scheme = URL.scheme;
if ([scheme isEqual: @"tcp"]) {
OFTCPSocket *sock = [OFTCPSocket socket];
if (URL.port == nil) {
[of_stderr writeLine: @"Need a port!"];
[OFApplication terminateWithStatus: 1];
}
[sock connectToHost: URL.host
port: URL.port.shortValue];
return [OFPair pairWithFirstObject: sock
secondObject: sock];
}
[of_stderr writeFormat: @"Invalid protocol: %@\n", scheme];
[OFApplication terminateWithStatus: 1];
abort();
}
@implementation OFSock
- (void)applicationDidFinishLaunching
{
OFArray OF_GENERIC(OFString *) *arguments = [OFApplication arguments];
if (arguments.count < 1) {
[of_stderr writeLine: @"Need at least one argument!"];
[OFApplication terminateWithStatus: 1];
}
_streams = [[OFMutableArray alloc] init];
for (OFString *argument in arguments) {
OFPair *pair = streamFromString(argument);
[pair.firstObject setDelegate: self];
[_streams addObject: pair];
}
if (arguments.count == 1) {
of_stdin.delegate = self;
[_streams addObject:
[OFPair pairWithFirstObject: of_stdin
secondObject: of_stdout]];
}
for (OFPair *pair in _streams)
[pair.firstObject asyncReadIntoBuffer: _buffer
length: BUFFER_LEN];
}
- (void)removeDeadStream: (OFStream *)stream
{
size_t count = _streams.count;
for (size_t i = 0; i < count; i++) {
if ([[_streams objectAtIndex: i] firstObject] == stream) {
[_streams removeObjectAtIndex: i];
break;
}
}
if (_streams.count < 2)
[OFApplication terminateWithStatus: _errors];
}
- (bool)stream: (OFStream *)stream
didReadIntoBuffer: (void *)buffer
length: (size_t)length
exception: (id)exception
{
if (exception != nil) {
[of_stderr writeFormat: @"Exception on stream %@: %@\n",
stream, exception];
_errors++;
[self removeDeadStream: stream];
return false;
}
if (stream.atEndOfStream) {
[self removeDeadStream: stream];
return false;
}
for (OFPair *pair in _streams) {
if (pair.firstObject == stream)
continue;
[pair.secondObject writeBuffer: buffer
length: length];
}
return true;
}
@end
|