@algocare/react-native-code-push 12.6.3 → 13.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (292) hide show
  1. package/CodePush.podspec +6 -8
  2. package/README.md +343 -586
  3. package/android/app/build.gradle +2 -1
  4. package/android/app/proguard-rules.pro +14 -0
  5. package/android/app/src/debug/AndroidManifest.xml +9 -0
  6. package/android/app/src/main/AndroidManifest.xml +1 -2
  7. package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +14 -139
  8. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushConstants.java +0 -3
  9. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +108 -63
  10. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java +2 -33
  11. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateUtils.java +13 -109
  12. package/android/build.gradle +3 -0
  13. package/app.plugin.js +1 -0
  14. package/bin/code-push.js +6 -0
  15. package/cli/commands/bundleCommand/bundleCodePush.ts +118 -0
  16. package/cli/commands/bundleCommand/index.ts +34 -0
  17. package/cli/commands/createHistoryCommand/createReleaseHistory.ts +37 -0
  18. package/cli/commands/createHistoryCommand/createReleaseHistoryList.ts +40 -0
  19. package/cli/commands/createHistoryCommand/index.ts +44 -0
  20. package/cli/commands/createPullRequestHistoryCommand/createPullRequestHistory.ts +33 -0
  21. package/cli/commands/createPullRequestHistoryCommand/index.ts +31 -0
  22. package/cli/commands/createPullRequestReleaseCommand/addToPullRequestRelease.ts +71 -0
  23. package/cli/commands/createPullRequestReleaseCommand/createPullRequestRelease.ts +75 -0
  24. package/cli/commands/createPullRequestReleaseCommand/index.ts +74 -0
  25. package/cli/commands/getPackageHashCommand/index.ts +45 -0
  26. package/cli/commands/initCommand/index.ts +14 -0
  27. package/cli/commands/initCommand/initAndroid.ts +91 -0
  28. package/cli/commands/initCommand/initIos.ts +123 -0
  29. package/cli/commands/initCommand/test/initAndroid.test.ts +128 -0
  30. package/cli/commands/initCommand/test/initIos.test.ts +99 -0
  31. package/cli/commands/releaseCommand/addToReleaseHistory.ts +57 -0
  32. package/cli/commands/releaseCommand/index.ts +90 -0
  33. package/cli/commands/releaseCommand/release.ts +105 -0
  34. package/cli/commands/removePullRequestHistoryCommand/index.ts +37 -0
  35. package/cli/commands/removePullRequestHistoryCommand/removePullRequestHistory.ts +28 -0
  36. package/cli/commands/showHistoryCommand/index.ts +31 -0
  37. package/cli/commands/updateHistoryCommand/index.ts +55 -0
  38. package/cli/commands/updateHistoryCommand/updateReleaseHistory.ts +42 -0
  39. package/cli/constant.ts +4 -0
  40. package/cli/dist/commands/bundleCommand/bundleCodePush.js +65 -0
  41. package/cli/dist/commands/bundleCommand/index.js +15 -0
  42. package/cli/dist/commands/createHistoryCommand/createReleaseHistory.js +25 -0
  43. package/cli/dist/commands/createHistoryCommand/createReleaseHistoryList.js +27 -0
  44. package/cli/dist/commands/createHistoryCommand/index.js +20 -0
  45. package/cli/dist/commands/createPullRequestHistoryCommand/createPullRequestHistory.js +23 -0
  46. package/cli/dist/commands/createPullRequestHistoryCommand/index.js +15 -0
  47. package/cli/dist/commands/createPullRequestReleaseCommand/addToPullRequestRelease.js +51 -0
  48. package/cli/dist/commands/createPullRequestReleaseCommand/createPullRequestRelease.js +39 -0
  49. package/cli/dist/commands/createPullRequestReleaseCommand/index.js +35 -0
  50. package/cli/dist/commands/getPackageHashCommand/index.js +26 -0
  51. package/cli/dist/commands/initCommand/index.js +12 -0
  52. package/cli/dist/commands/initCommand/initAndroid.js +73 -0
  53. package/cli/dist/commands/initCommand/initIos.js +108 -0
  54. package/cli/dist/commands/initCommand/test/initAndroid.test.js +113 -0
  55. package/cli/dist/commands/initCommand/test/initIos.test.js +95 -0
  56. package/cli/dist/commands/releaseCommand/addToReleaseHistory.js +35 -0
  57. package/cli/dist/commands/releaseCommand/index.js +45 -0
  58. package/cli/dist/commands/releaseCommand/release.js +62 -0
  59. package/cli/dist/commands/removePullRequestHistoryCommand/index.js +19 -0
  60. package/cli/dist/commands/removePullRequestHistoryCommand/removePullRequestHistory.js +18 -0
  61. package/cli/dist/commands/showHistoryCommand/index.js +15 -0
  62. package/cli/dist/commands/updateHistoryCommand/index.js +31 -0
  63. package/cli/dist/commands/updateHistoryCommand/updateReleaseHistory.js +28 -0
  64. package/cli/dist/constant.js +4 -0
  65. package/cli/dist/functions/getReactTempDir.js +10 -0
  66. package/cli/{functions → dist/functions}/makeCodePushBundle.js +5 -11
  67. package/cli/{functions → dist/functions}/prepareToBundleJS.js +2 -5
  68. package/cli/dist/functions/runExpoBundleCommand.js +35 -0
  69. package/cli/{functions → dist/functions}/runHermesEmitBinaryCommand.js +36 -71
  70. package/cli/{functions → dist/functions}/runReactNativeBundleCommand.js +19 -24
  71. package/cli/dist/index.js +54 -0
  72. package/cli/dist/utils/datetime.js +17 -0
  73. package/cli/dist/utils/file-utils.js +19 -0
  74. package/cli/dist/utils/fsUtils.js +44 -0
  75. package/cli/{utils → dist/utils}/hash-utils.js +19 -130
  76. package/cli/{utils → dist/utils}/promisfied-fs.js +5 -16
  77. package/cli/dist/utils/showLogo.js +21 -0
  78. package/cli/dist/utils/unzip.js +41 -0
  79. package/cli/{utils → dist/utils}/zip.js +15 -51
  80. package/cli/functions/{getReactTempDir.js → getReactTempDir.ts} +2 -6
  81. package/cli/functions/makeCodePushBundle.ts +26 -0
  82. package/cli/functions/prepareToBundleJS.ts +10 -0
  83. package/cli/functions/runExpoBundleCommand.ts +45 -0
  84. package/cli/functions/runHermesEmitBinaryCommand.ts +203 -0
  85. package/cli/functions/runReactNativeBundleCommand.ts +67 -0
  86. package/cli/index.ts +68 -0
  87. package/cli/package.json +35 -0
  88. package/cli/utils/datetime.ts +19 -0
  89. package/cli/utils/{file-utils.js → file-utils.ts} +4 -21
  90. package/cli/utils/fsUtils.ts +50 -0
  91. package/cli/utils/hash-utils.ts +143 -0
  92. package/cli/utils/promisfied-fs.ts +19 -0
  93. package/cli/utils/{showLogo.js → showLogo.ts} +4 -6
  94. package/cli/utils/unzip.ts +46 -0
  95. package/cli/utils/zip.ts +65 -0
  96. package/expo/plugin/withCodePush.js +14 -0
  97. package/expo/plugin/withCodePushAndroid.js +92 -0
  98. package/expo/plugin/withCodePushIos.js +143 -0
  99. package/ios/CodePush/CodePush.h +0 -16
  100. package/ios/CodePush/CodePush.m +30 -20
  101. package/ios/CodePush/CodePushConfig.m +1 -11
  102. package/ios/CodePush/CodePushPackage.m +12 -69
  103. package/ios/CodePush/CodePushUpdateUtils.m +1 -91
  104. package/ios/CodePush/SSZipArchive/Info.plist +26 -0
  105. package/ios/CodePush/SSZipArchive/README.md +1 -1
  106. package/ios/CodePush/SSZipArchive/SSZipArchive.h +129 -27
  107. package/ios/CodePush/SSZipArchive/SSZipArchive.m +1119 -314
  108. package/ios/CodePush/SSZipArchive/SSZipCommon.h +71 -0
  109. package/ios/CodePush/SSZipArchive/Supporting Files/PrivacyInfo.xcprivacy +23 -0
  110. package/ios/CodePush/SSZipArchive/include/ZipArchive.h +25 -0
  111. package/ios/CodePush/SSZipArchive/minizip/LICENSE +17 -0
  112. package/ios/CodePush/SSZipArchive/minizip/mz.h +273 -0
  113. package/ios/CodePush/SSZipArchive/minizip/mz_compat.c +1306 -0
  114. package/ios/CodePush/SSZipArchive/minizip/mz_compat.h +346 -0
  115. package/ios/CodePush/SSZipArchive/minizip/mz_crypt.c +187 -0
  116. package/ios/CodePush/SSZipArchive/minizip/mz_crypt.h +65 -0
  117. package/ios/CodePush/SSZipArchive/minizip/mz_crypt_apple.c +526 -0
  118. package/ios/CodePush/SSZipArchive/minizip/mz_os.c +348 -0
  119. package/ios/CodePush/SSZipArchive/minizip/mz_os.h +176 -0
  120. package/ios/CodePush/SSZipArchive/minizip/mz_os_posix.c +350 -0
  121. package/ios/CodePush/SSZipArchive/minizip/mz_strm.c +556 -0
  122. package/ios/CodePush/SSZipArchive/minizip/mz_strm.h +132 -0
  123. package/ios/CodePush/SSZipArchive/minizip/mz_strm_buf.c +383 -0
  124. package/ios/CodePush/SSZipArchive/minizip/mz_strm_buf.h +42 -0
  125. package/ios/CodePush/SSZipArchive/minizip/mz_strm_mem.c +269 -0
  126. package/ios/CodePush/SSZipArchive/minizip/mz_strm_mem.h +48 -0
  127. package/ios/CodePush/SSZipArchive/minizip/mz_strm_os.h +40 -0
  128. package/ios/CodePush/SSZipArchive/minizip/mz_strm_os_posix.c +203 -0
  129. package/ios/CodePush/SSZipArchive/minizip/mz_strm_pkcrypt.c +334 -0
  130. package/ios/CodePush/SSZipArchive/minizip/mz_strm_pkcrypt.h +46 -0
  131. package/ios/CodePush/SSZipArchive/minizip/mz_strm_split.c +429 -0
  132. package/ios/CodePush/SSZipArchive/minizip/mz_strm_split.h +43 -0
  133. package/ios/CodePush/SSZipArchive/minizip/mz_strm_wzaes.c +360 -0
  134. package/ios/CodePush/SSZipArchive/minizip/mz_strm_wzaes.h +46 -0
  135. package/ios/CodePush/SSZipArchive/minizip/mz_strm_zlib.c +389 -0
  136. package/ios/CodePush/SSZipArchive/minizip/mz_strm_zlib.h +43 -0
  137. package/ios/CodePush/SSZipArchive/minizip/mz_zip.c +2782 -0
  138. package/ios/CodePush/SSZipArchive/minizip/mz_zip.h +262 -0
  139. package/ios/CodePush/SSZipArchive/minizip/mz_zip_rw.c +1942 -0
  140. package/ios/CodePush/SSZipArchive/minizip/mz_zip_rw.h +285 -0
  141. package/ios/CodePush.xcodeproj/project.pbxproj +244 -453
  142. package/ios/PrivacyInfo.xcprivacy +31 -0
  143. package/package.json +67 -41
  144. package/react-native.config.js +1 -1
  145. package/{AlertAdapter.js → src/AlertAdapter.js} +5 -5
  146. package/src/CodePush.js +947 -0
  147. package/{package-mixins.js → src/package-mixins.js} +1 -1
  148. package/{versioning → src/versioning}/BaseVersioning.js +12 -1
  149. package/{versioning → src/versioning}/SemverVersioning.test.js +78 -0
  150. package/typings/react-native-code-push.d.ts +559 -495
  151. package/CONTRIBUTING.md +0 -134
  152. package/CodePush.js +0 -972
  153. package/SECURITY.md +0 -41
  154. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushBuilder.java +0 -37
  155. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushInvalidPublicKeyException.java +0 -12
  156. package/android/app/src/main/java/com/microsoft/codepush/react/ReactInstanceHolder.java +0 -17
  157. package/android/codepush.gradle +0 -162
  158. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  159. package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
  160. package/android/gradlew +0 -164
  161. package/android/gradlew.bat +0 -90
  162. package/babel.config.js +0 -3
  163. package/cli/commands/bundleCommand/bundleCodePush.js +0 -57
  164. package/cli/commands/bundleCommand/index.js +0 -55
  165. package/cli/commands/common.js +0 -245
  166. package/cli/commands/createHistoryCommand/createReleaseHistory.js +0 -42
  167. package/cli/commands/createHistoryCommand/createReleaseHistoryList.js +0 -52
  168. package/cli/commands/createHistoryCommand/index.js +0 -95
  169. package/cli/commands/createPullRequestHistoryCommand/createPullRequestHistory.js +0 -34
  170. package/cli/commands/createPullRequestHistoryCommand/index.js +0 -29
  171. package/cli/commands/createPullRequestReleaseCommand/addToPullRequestRelease.js +0 -74
  172. package/cli/commands/createPullRequestReleaseCommand/createPullRequestRelease.js +0 -91
  173. package/cli/commands/createPullRequestReleaseCommand/index.js +0 -68
  174. package/cli/commands/getPackageHashCommand/index.js +0 -42
  175. package/cli/commands/releaseCommand/addToReleaseHistory.js +0 -85
  176. package/cli/commands/releaseCommand/index.js +0 -151
  177. package/cli/commands/releaseCommand/release.js +0 -121
  178. package/cli/commands/removePullRequestHistoryCommand/index.js +0 -28
  179. package/cli/commands/removePullRequestHistoryCommand/removePullRequestHistory.js +0 -23
  180. package/cli/commands/showHistoryCommand/index.js +0 -88
  181. package/cli/commands/updateHistoryCommand/index.js +0 -123
  182. package/cli/commands/updateHistoryCommand/updateReleaseHistory.js +0 -69
  183. package/cli/constant.js +0 -8
  184. package/cli/index.js +0 -63
  185. package/cli/utils/datetime.js +0 -22
  186. package/cli/utils/fsUtils.js +0 -64
  187. package/cli/utils/version.js +0 -26
  188. package/code-push.config.example.supabase.ts +0 -114
  189. package/code-push.config.js +0 -229
  190. package/code-push.config.ts +0 -175
  191. package/docs/api-android.md +0 -83
  192. package/docs/api-ios.md +0 -31
  193. package/docs/api-js.md +0 -592
  194. package/docs/multi-deployment-testing-android.md +0 -148
  195. package/docs/multi-deployment-testing-ios.md +0 -59
  196. package/docs/setup-android.md +0 -482
  197. package/docs/setup-ios.md +0 -280
  198. package/eslint.config.mjs +0 -32
  199. package/ios/CodePush/Base64/Base64/MF_Base64Additions.h +0 -34
  200. package/ios/CodePush/Base64/Base64/MF_Base64Additions.m +0 -252
  201. package/ios/CodePush/Base64/README.md +0 -47
  202. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithm.h +0 -69
  203. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.h +0 -16
  204. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmFactory.m +0 -51
  205. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.h +0 -15
  206. package/ios/CodePush/JWT/Core/Algorithms/Base/JWTAlgorithmNone.m +0 -55
  207. package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.h +0 -24
  208. package/ios/CodePush/JWT/Core/Algorithms/ESFamily/JWTAlgorithmESBase.m +0 -41
  209. package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.h +0 -28
  210. package/ios/CodePush/JWT/Core/Algorithms/HSFamily/JWTAlgorithmHSBase.m +0 -205
  211. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.h +0 -103
  212. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolder.m +0 -322
  213. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.h +0 -37
  214. package/ios/CodePush/JWT/Core/Algorithms/Holders/JWTAlgorithmDataHolderChain.m +0 -145
  215. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.h +0 -35
  216. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTAlgorithmRSBase.m +0 -551
  217. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/JWTRSAlgorithm.h +0 -23
  218. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.h +0 -43
  219. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKey.m +0 -230
  220. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.h +0 -31
  221. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoKeyExtractor.m +0 -113
  222. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.h +0 -38
  223. package/ios/CodePush/JWT/Core/Algorithms/RSFamily/RSKeys/JWTCryptoSecurity.m +0 -500
  224. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.h +0 -18
  225. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaim.m +0 -214
  226. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.h +0 -23
  227. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSet.m +0 -29
  228. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.h +0 -19
  229. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetSerializer.m +0 -68
  230. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.h +0 -18
  231. package/ios/CodePush/JWT/Core/ClaimSet/JWTClaimsSetVerifier.m +0 -72
  232. package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.h +0 -67
  233. package/ios/CodePush/JWT/Core/Coding/JWTCoding+ResultTypes.m +0 -111
  234. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.h +0 -119
  235. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionOne.m +0 -307
  236. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.h +0 -94
  237. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionThree.m +0 -619
  238. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.h +0 -164
  239. package/ios/CodePush/JWT/Core/Coding/JWTCoding+VersionTwo.m +0 -514
  240. package/ios/CodePush/JWT/Core/Coding/JWTCoding.h +0 -24
  241. package/ios/CodePush/JWT/Core/Coding/JWTCoding.m +0 -11
  242. package/ios/CodePush/JWT/Core/FrameworkSupplement/JWT.h +0 -52
  243. package/ios/CodePush/JWT/Core/FrameworkSupplement/Map.modulemap +0 -5
  244. package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.h +0 -28
  245. package/ios/CodePush/JWT/Core/Supplement/JWTBase64Coder.m +0 -70
  246. package/ios/CodePush/JWT/Core/Supplement/JWTDeprecations.h +0 -22
  247. package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.h +0 -34
  248. package/ios/CodePush/JWT/Core/Supplement/JWTErrorDescription.m +0 -73
  249. package/ios/CodePush/JWT/LICENSE +0 -19
  250. package/ios/CodePush/JWT/README.md +0 -489
  251. package/ios/CodePush/SSZipArchive/Common.h +0 -81
  252. package/ios/CodePush/SSZipArchive/aes/aes.h +0 -198
  253. package/ios/CodePush/SSZipArchive/aes/aes_via_ace.h +0 -541
  254. package/ios/CodePush/SSZipArchive/aes/aescrypt.c +0 -294
  255. package/ios/CodePush/SSZipArchive/aes/aeskey.c +0 -548
  256. package/ios/CodePush/SSZipArchive/aes/aesopt.h +0 -739
  257. package/ios/CodePush/SSZipArchive/aes/aestab.c +0 -391
  258. package/ios/CodePush/SSZipArchive/aes/aestab.h +0 -173
  259. package/ios/CodePush/SSZipArchive/aes/brg_endian.h +0 -126
  260. package/ios/CodePush/SSZipArchive/aes/brg_types.h +0 -219
  261. package/ios/CodePush/SSZipArchive/aes/entropy.c +0 -54
  262. package/ios/CodePush/SSZipArchive/aes/entropy.h +0 -16
  263. package/ios/CodePush/SSZipArchive/aes/fileenc.c +0 -144
  264. package/ios/CodePush/SSZipArchive/aes/fileenc.h +0 -121
  265. package/ios/CodePush/SSZipArchive/aes/hmac.c +0 -145
  266. package/ios/CodePush/SSZipArchive/aes/hmac.h +0 -103
  267. package/ios/CodePush/SSZipArchive/aes/prng.c +0 -155
  268. package/ios/CodePush/SSZipArchive/aes/prng.h +0 -82
  269. package/ios/CodePush/SSZipArchive/aes/pwd2key.c +0 -103
  270. package/ios/CodePush/SSZipArchive/aes/pwd2key.h +0 -57
  271. package/ios/CodePush/SSZipArchive/aes/sha1.c +0 -258
  272. package/ios/CodePush/SSZipArchive/aes/sha1.h +0 -73
  273. package/ios/CodePush/SSZipArchive/minizip/crypt.h +0 -130
  274. package/ios/CodePush/SSZipArchive/minizip/ioapi.c +0 -369
  275. package/ios/CodePush/SSZipArchive/minizip/ioapi.h +0 -175
  276. package/ios/CodePush/SSZipArchive/minizip/mztools.c +0 -284
  277. package/ios/CodePush/SSZipArchive/minizip/mztools.h +0 -31
  278. package/ios/CodePush/SSZipArchive/minizip/unzip.c +0 -1839
  279. package/ios/CodePush/SSZipArchive/minizip/unzip.h +0 -248
  280. package/ios/CodePush/SSZipArchive/minizip/zip.c +0 -1910
  281. package/ios/CodePush/SSZipArchive/minizip/zip.h +0 -202
  282. package/scripts/generateBundledResourcesHash.js +0 -125
  283. package/scripts/getFilesInFolder.js +0 -19
  284. package/scripts/recordFilesBeforeBundleCommand.js +0 -41
  285. package/tsconfig.json +0 -20
  286. package/tslint.json +0 -32
  287. /package/{logging.js → src/logging.js} +0 -0
  288. /package/{versioning → src/versioning}/BaseVersioning.test.js +0 -0
  289. /package/{versioning → src/versioning}/IncrementalVersioning.js +0 -0
  290. /package/{versioning → src/versioning}/IncrementalVersioning.test.js +0 -0
  291. /package/{versioning → src/versioning}/SemverVersioning.js +0 -0
  292. /package/{versioning → src/versioning}/index.js +0 -0
@@ -1,500 +0,0 @@
1
- //
2
- // JWTCryptoSecurity.m
3
- // JWT
4
- //
5
- // Created by Lobanov Dmitry on 04.02.17.
6
- // Copyright © 2017 JWTIO. All rights reserved.
7
- //
8
-
9
- #import "JWTCryptoSecurity.h"
10
- @interface JWTMemoryLayout : NSObject
11
- + (NSString *)typeUInt8;
12
- + (NSString *)typeCUnsignedChar;
13
- - (instancetype)initWithType:(NSString *)type;
14
- + (instancetype)createWithType:(NSString *)type;
15
- @property (copy, nonatomic, readwrite) NSString *type;
16
- @property (assign, nonatomic, readonly) NSInteger size;
17
- @end
18
- @implementation JWTMemoryLayout
19
- + (NSString *)typeUInt8 {
20
- return NSStringFromSelector(_cmd);
21
- }
22
- + (NSString *)typeCUnsignedChar {
23
- return [self typeUInt8];
24
- }
25
- - (instancetype)initWithType:(NSString *)type {
26
- self = [super init];
27
- if (self) {
28
- self.type = type;
29
- }
30
- return self;
31
- }
32
- + (instancetype)createWithType:(NSString *)type {
33
- return [[self alloc] initWithType:type];
34
- }
35
- + (NSDictionary *)sizesAndTypes {
36
- static NSDictionary *sizesAndTypes = nil;
37
- return sizesAndTypes ?: (sizesAndTypes = @{
38
- [self typeUInt8] : @(1) // or 8?
39
- }, sizesAndTypes);
40
- }
41
- - (NSInteger)size {
42
- return [[self.class sizesAndTypes][self.type] integerValue];
43
- }
44
- @end
45
- @implementation JWTCryptoSecurity
46
- + (NSDictionary *)dictionaryByCombiningDictionaries:(NSArray *)dictionaries {
47
- NSMutableDictionary *result = [@{} mutableCopy];
48
- for (NSDictionary *dictionary in dictionaries) {
49
- [result addEntriesFromDictionary:dictionary];
50
- }
51
- return [result copy];
52
- }
53
- + (NSString *)keyTypeRSA {
54
- return (__bridge NSString *)kSecAttrKeyTypeRSA;
55
- }
56
- + (NSString *)keyTypeEC {
57
- // extern const CFStringRef kSecAttrKeyTypeEC
58
- // __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_4_0);
59
- // extern const CFStringRef kSecAttrKeyTypeECSECPrimeRandom
60
- // __OSX_AVAILABLE_STARTING(__MAC_10_12, __IPHONE_10_0);
61
- return (__bridge NSString *)kSecAttrKeyTypeEC;
62
- }
63
- + (SecKeyRef)addKeyWithData:(NSData *)data asPublic:(BOOL)public tag:(NSString *)tag type:(NSString *)type error:(NSError *__autoreleasing*)error; {
64
- NSString *keyClass = (__bridge NSString *)(public ? kSecAttrKeyClassPublic : kSecAttrKeyClassPrivate);
65
- NSInteger sizeInBits = data.length * [JWTMemoryLayout createWithType:[JWTMemoryLayout typeUInt8]].size;
66
- NSDictionary *attributes = @{
67
- (__bridge NSString*)kSecAttrKeyType : type,
68
- (__bridge NSString*)kSecAttrKeyClass : keyClass,
69
- (__bridge NSString*)kSecAttrKeySizeInBits : @(sizeInBits)
70
- };
71
-
72
- if (SecKeyCreateWithData != NULL) {
73
- CFErrorRef createError = NULL;
74
- SecKeyRef key = SecKeyCreateWithData((__bridge CFDataRef)data, (__bridge CFDictionaryRef)attributes, &createError);
75
- if (error && createError != nil) {
76
- *error = (__bridge NSError*)createError;
77
- }
78
- return key;
79
- }
80
- // oh... not avaialbe API :/
81
- else {
82
-
83
- CFTypeRef result = NULL;
84
- NSData *tagData = [tag dataUsingEncoding:NSUTF8StringEncoding];
85
- NSDictionary *commonAttributes = @{
86
- (__bridge NSString*)kSecClass: (__bridge NSString*)kSecClassKey,
87
- (__bridge NSString*)kSecAttrApplicationTag: tagData,
88
- (__bridge NSString*)kSecAttrAccessible: (__bridge NSString*)kSecAttrAccessibleWhenUnlocked
89
- };
90
-
91
-
92
- NSDictionary *addItemAttributes = @{
93
- (__bridge NSString*)kSecValueData: data,
94
- (__bridge NSString*)kSecReturnPersistentRef: @(YES),
95
- };
96
-
97
- OSStatus addItemStatus = SecItemAdd((__bridge CFDictionaryRef)[self dictionaryByCombiningDictionaries:@[attributes, commonAttributes, addItemAttributes]], &result);
98
- if (addItemStatus != errSecSuccess && addItemStatus != errSecDuplicateItem) {
99
- // add item error
100
- // not duplicate and not added to keychain.
101
- return NULL;
102
- }
103
-
104
- NSDictionary *copyAttributes = @{
105
- (__bridge NSString*)kSecReturnRef: @(YES),
106
- };
107
-
108
- CFTypeRef key = NULL;
109
- // TODO: Add error handling later.
110
- OSStatus copyItemStatus = errSecSuccess;
111
- SecItemCopyMatching((__bridge CFDictionaryRef)[self dictionaryByCombiningDictionaries:@[attributes, commonAttributes, copyAttributes]], &key);
112
- if (key == NULL) {
113
- // copy item error
114
- }
115
- return (SecKeyRef)key;
116
- }
117
-
118
- return NULL;
119
- }
120
- + (SecKeyRef)addKeyWithData:(NSData *)data asPublic:(BOOL)public tag:(NSString *)tag error:(NSError *__autoreleasing*)error; {
121
- return [self addKeyWithData:data asPublic:public tag:tag type:[self keyTypeRSA] error:error];
122
- }
123
-
124
- + (SecKeyRef)keyByTag:(NSString *)tag error:(NSError *__autoreleasing*)error; {
125
- return NULL;
126
- }
127
-
128
- + (void)removeKeyByTag:(NSString *)tag error:(NSError *__autoreleasing*)error; {
129
- NSData *tagData = [tag dataUsingEncoding:NSUTF8StringEncoding];
130
- if (tagData == nil) {
131
- // tell that nothing to remove.
132
- return;
133
- }
134
- NSDictionary *removeAttributes = @{
135
- (__bridge NSString*)kSecClass: (__bridge NSString*)kSecClassKey,
136
- (__bridge NSString*)kSecAttrKeyType: (__bridge NSString*)kSecAttrKeyTypeRSA,
137
- (__bridge NSString*)kSecAttrApplicationTag: tagData,
138
- };
139
- SecItemDelete((__bridge CFDictionaryRef)removeAttributes);
140
- }
141
- @end
142
-
143
- @implementation JWTCryptoSecurity (Certificates)
144
- + (OSStatus)extractIdentityAndTrustFromPKCS12:(CFDataRef)inPKCS12Data password:(CFStringRef)password identity:(SecIdentityRef *)outIdentity trust:(SecTrustRef *)outTrust {
145
-
146
- OSStatus securityError = errSecSuccess;
147
-
148
-
149
- const void *keys[] = { kSecImportExportPassphrase };
150
- const void *values[] = { password };
151
- CFDictionaryRef optionsDictionary = NULL;
152
-
153
- /* Create a dictionary containing the passphrase if one
154
- was specified. Otherwise, create an empty dictionary. */
155
- optionsDictionary = CFDictionaryCreate(
156
- NULL, keys,
157
- values, (password ? 1 : 0),
158
- NULL, NULL); // 1
159
-
160
- CFArrayRef items = NULL;
161
- securityError = SecPKCS12Import(inPKCS12Data,
162
- optionsDictionary,
163
- &items); // 2
164
-
165
-
166
- //
167
- if (securityError == 0) { // 3
168
- CFDictionaryRef myIdentityAndTrust = CFArrayGetValueAtIndex (items, 0);
169
- const void *tempIdentity = NULL;
170
- tempIdentity = CFDictionaryGetValue (myIdentityAndTrust,
171
- kSecImportItemIdentity);
172
- CFRetain(tempIdentity);
173
- *outIdentity = (SecIdentityRef)tempIdentity;
174
- const void *tempTrust = NULL;
175
- tempTrust = CFDictionaryGetValue (myIdentityAndTrust, kSecImportItemTrust);
176
-
177
- CFRetain(tempTrust);
178
- *outTrust = (SecTrustRef)tempTrust;
179
- }
180
-
181
- if (optionsDictionary) // 4
182
- CFRelease(optionsDictionary);
183
-
184
- if (items)
185
- CFRelease(items);
186
-
187
- return securityError;
188
- }
189
-
190
- + (SecKeyRef)publicKeyFromCertificate:(NSData *)certificateData {
191
- SecCertificateRef certificate = SecCertificateCreateWithData(NULL, (__bridge CFDataRef)certificateData);
192
- if (certificate != NULL) {
193
- SecPolicyRef secPolicy = SecPolicyCreateBasicX509();
194
- SecTrustRef trust;
195
- SecTrustCreateWithCertificates(certificate, secPolicy, &trust);
196
- SecTrustResultType resultType;
197
- SecTrustEvaluate(trust, &resultType);
198
- SecKeyRef publicKey = SecTrustCopyPublicKey(trust);
199
- (CFRelease(trust));
200
- (CFRelease(secPolicy));
201
- (CFRelease(certificate));
202
- return publicKey;
203
- }
204
- return NULL;
205
- }
206
- @end
207
-
208
- @implementation JWTCryptoSecurity (Pem)
209
- + (NSString *)certificateFromPemFileContent:(NSString *)content {
210
- NSRegularExpression *expression = [[NSRegularExpression alloc] initWithPattern:@"-----BEGIN CERTIFICATE-----(.+?)-----END CERTIFICATE-----" options:NSRegularExpressionDotMatchesLineSeparators error:nil];
211
- return [self itemsFromPemFileContent:content byRegex:expression].firstObject;
212
- }
213
- + (NSString *)keyFromPemFileContent:(NSString *)content {
214
- NSRegularExpression *expression = [[NSRegularExpression alloc] initWithPattern:@"-----BEGIN(?:[\\w\\s]|)+KEY-----(.+?)-----END(?:[\\w\\s])+KEY-----" options:NSRegularExpressionDotMatchesLineSeparators error:nil];
215
- return [self itemsFromPemFileContent:content byRegex:expression].firstObject;
216
- }
217
- + (NSArray *)itemsFromPemFileContent:(NSString *)content byRegex:(NSRegularExpression *)expression {
218
- NSArray *matches = [expression matchesInString:content options:0 range:NSMakeRange(0, content.length)];
219
- NSTextCheckingResult *result = matches.firstObject;
220
- NSArray *resultArray = @[];
221
-
222
- if (result) {
223
- for (NSUInteger i = 1; i < result.numberOfRanges; ++i) {
224
- NSString *extractedString = [content substringWithRange:[result rangeAtIndex:i]];
225
- resultArray = [resultArray arrayByAddingObject:extractedString];
226
- }
227
- }
228
- return resultArray;
229
- }
230
- + (NSString *)certificateFromPemFileWithName:(NSString *)name {
231
- NSRegularExpression *expression = [[NSRegularExpression alloc] initWithPattern:@"-----BEGIN CERTIFICATE-----(.+?)-----END CERTIFICATE-----" options:NSRegularExpressionDotMatchesLineSeparators error:nil];
232
- return [self itemsFromPemFileWithName:name byRegex:expression].firstObject;
233
- }
234
- + (NSString *)keyFromPemFileWithName:(NSString *)name {
235
- NSRegularExpression *expression = [[NSRegularExpression alloc] initWithPattern:@"-----BEGIN(?:[\\w\\s]|)+KEY-----(.+?)-----END(?:[\\w\\s])+KEY-----" options:NSRegularExpressionDotMatchesLineSeparators error:nil];
236
- return [self itemsFromPemFileWithName:name byRegex:expression].firstObject;
237
- }
238
- + (NSArray *)itemsFromPemFileWithName:(NSString *)name byRegex:(NSRegularExpression *)expression {
239
- NSURL *fileURL = [[NSBundle bundleForClass:self.class] URLForResource:name withExtension:@"pem"];
240
- NSError *error = nil;
241
- NSString *fileContent = [NSString stringWithContentsOfURL:fileURL encoding:NSUTF8StringEncoding error:&error];
242
-
243
- if (error) {
244
- NSLog(@"%@ error: %@", self.debugDescription, error);
245
- return nil;
246
- }
247
-
248
- return [self itemsFromPemFileContent:fileContent byRegex:expression];
249
- }
250
- + (NSString *)stringByRemovingPemHeadersFromString:(NSString *)string {
251
- NSArray *lines = [string componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
252
- NSArray *linesWithoutHeaders = [lines filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(NSString *_Nullable evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
253
- return !([evaluatedObject hasPrefix:@"-----BEGIN"] || [evaluatedObject hasPrefix:@"-----END"]);
254
- }]];
255
- return [linesWithoutHeaders componentsJoinedByString:@""];
256
- }
257
- @end
258
-
259
- @implementation JWTCryptoSecurity (PublicKey)
260
- /**
261
- This method strips the x509 from a provided ASN.1 DER public key.
262
- If the key doesn't contain a header, the DER data is returned as is.
263
-
264
- Supported formats are:
265
-
266
- Headerless:
267
- SEQUENCE
268
- INTEGER (1024 or 2048 bit) -- modulo
269
- INTEGER -- public exponent
270
-
271
- With x509 header:
272
- SEQUENCE
273
- SEQUENCE
274
- OBJECT IDENTIFIER 1.2.840.113549.1.1.1
275
- NULL
276
- BIT STRING
277
- SEQUENCE
278
- INTEGER (1024 or 2048 bit) -- modulo
279
- INTEGER -- public exponent
280
-
281
- Example of headerless key:
282
- https://lapo.it/asn1js/#3082010A0282010100C1A0DFA367FBC2A5FD6ED5A071E02A4B0617E19C6B5AD11BB61192E78D212F10A7620084A3CED660894134D4E475BAD7786FA1D40878683FD1B7A1AD9C0542B7A666457A270159DAC40CE25B2EAE7CCD807D31AE725CA394F90FBB5C5BA500545B99C545A9FE08EFF00A5F23457633E1DB84ED5E908EF748A90F8DFCCAFF319CB0334705EA012AF15AA090D17A9330159C9AFC9275C610BB9B7C61317876DC7386C723885C100F774C19830F475AD1E9A9925F9CA9A69CE0181A214DF2EB75FD13E6A546B8C8ED699E33A8521242B7E42711066AEC22D25DD45D56F94D3170D6F2C25164D2DACED31C73963BA885ADCB706F40866B8266433ED5161DC50E4B3B0203010001
283
-
284
- Example of key with X509 header (notice the additional ASN.1 sequence):
285
- https://lapo.it/asn1js/#30819F300D06092A864886F70D010101050003818D0030818902818100D0674615A252ED3D75D2A3073A0A8A445F3188FD3BEB8BA8584F7299E391BDEC3427F287327414174997D147DD8CA62647427D73C9DA5504E0A3EED5274A1D50A1237D688486FADB8B82061675ABFA5E55B624095DB8790C6DBCAE83D6A8588C9A6635D7CF257ED1EDE18F04217D37908FD0CBB86B2C58D5F762E6207FF7B92D0203010001
286
- */
287
- //static func stripPublicKeyHeader(keyData: Data) throws -> Data {
288
- // let count = keyData.count / MemoryLayout<CUnsignedChar>.size
289
- //
290
- // guard count > 0 else {
291
- // throw SwiftyRSAError(message: "Provided public key is empty")
292
- // }
293
- //
294
- // var byteArray = [UInt8](repeating: 0, count: count)
295
- // (keyData as NSData).getBytes(&byteArray, length: keyData.count)
296
- //
297
- // var index = 0
298
- // guard byteArray[index] == 0x30 else {
299
- // throw SwiftyRSAError(message: "Provided key doesn't have a valid ASN.1 structure (first byte should be 0x30 == SEQUENCE)")
300
- // }
301
- //
302
- // index += 1
303
- // if byteArray[index] > 0x80 {
304
- // index += Int(byteArray[index]) - 0x80 + 1
305
- // } else {
306
- // index += 1
307
- // }
308
- //
309
- // // If current byte marks an integer (0x02), it means the key doesn't have a X509 header and just
310
- // // contains its modulo & public exponent. In this case, we can just return the provided DER data as is.
311
- // if Int(byteArray[index]) == 0x02 {
312
- // return keyData
313
- // }
314
- //
315
- // // Now that we've excluded the possibility of headerless key, we're looking for a valid X509 header sequence.
316
- // // It should look like this:
317
- // // 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00
318
- // guard Int(byteArray[index]) == 0x30 else {
319
- // throw SwiftyRSAError(message: "Provided key doesn't have a valid X509 header")
320
- // }
321
- //
322
- // index += 15
323
- // if byteArray[index] != 0x03 {
324
- // throw SwiftyRSAError(message: "Invalid byte at index \(index - 1) (\(byteArray[index - 1])) for public key header")
325
- // }
326
- //
327
- // index += 1
328
- // if byteArray[index] > 0x80 {
329
- // index += Int(byteArray[index]) - 0x80 + 1
330
- // } else {
331
- // index += 1
332
- // }
333
- //
334
- // guard byteArray[index] == 0 else {
335
- // throw SwiftyRSAError(message: "Invalid byte at index \(index - 1) (\(byteArray[index - 1])) for public key header")
336
- // }
337
- //
338
- // index += 1
339
- //
340
- // let strippedKeyBytes = [UInt8](byteArray[index...keyData.count - 1])
341
- // let data = Data(bytes: UnsafePointer<UInt8>(strippedKeyBytes), count: keyData.count - index)
342
- //
343
- // return data
344
- //}
345
- typedef NS_ENUM(NSInteger, JWTPublicHeaderStrippingError) {
346
- JWTPublicHeaderStrippingError_KeyIsEmpty = -200,
347
- JWTPublicHeaderStrippingError_Invalid_ASN1_Structure,
348
- JWTPublicHeaderStrippingError_Invalid_X509_Header,
349
- JWTPublicHeaderStrippingError_Invalid_Byte_At_Index,
350
- };
351
- + (NSDictionary *)publicHeaderStrippingMessagesAndCodes {
352
- static NSDictionary *publicHeaderStrippingMessagesAndCodes = nil;
353
- return publicHeaderStrippingMessagesAndCodes ?:
354
- (publicHeaderStrippingMessagesAndCodes = @{
355
- @(JWTPublicHeaderStrippingError_KeyIsEmpty) : @"Provided public key is empty",
356
- @(JWTPublicHeaderStrippingError_Invalid_ASN1_Structure) : @"Provided key doesn't have a valid ASN.1 structure (first byte should be 0x30 == SEQUENCE)",
357
- @(JWTPublicHeaderStrippingError_Invalid_X509_Header) : @"Provided key doesn't have a valid X509 header",
358
- @(JWTPublicHeaderStrippingError_Invalid_Byte_At_Index) : @"Invalid byte at index (index - 1) ((bytes[index - 1])) for public key header. Access as error.userInfo[Parameters][index] or error.userInfo[Parameters][byte]"
359
- },
360
- publicHeaderStrippingMessagesAndCodes);
361
- }
362
- + (NSString *)stringForPublicHeaderStrippingErrorCode:(NSInteger)code {
363
- return [self publicHeaderStrippingMessagesAndCodes][@(code)] ?: @"Unknown Public Header Stripping Error";
364
- }
365
- + (NSError*)publicHeaderStrippingErrorForCode:(NSInteger)code parameters:(NSDictionary *)parameters {
366
- return [NSError errorWithDomain:@"io.jwt.crypto.stripping_public_header" code:code userInfo:@{
367
- @"Parameters" : parameters ?: [NSNull null],NSLocalizedDescriptionKey: [self stringForPublicHeaderStrippingErrorCode:code]
368
- }];
369
- }
370
- + (NSError*)publicHeaderStrippingErrorForCode:(NSInteger)code {
371
- return [self publicHeaderStrippingErrorForCode:code parameters:nil];
372
- }
373
- + (NSData *)dataByRemovingPublicKeyHeader:(NSData *)data error:(NSError *__autoreleasing *)error {
374
- NSError *currentError = nil;
375
- NSData *currentData = [data copy];
376
- // let count = keyData.count / MemoryLayout<CUnsignedChar>.size
377
- //
378
- // guard count > 0 else {
379
- // throw SwiftyRSAError(message: "Provided public key is empty")
380
- // }
381
- NSInteger countOfBytes = currentData.length / [JWTMemoryLayout createWithType:[JWTMemoryLayout typeUInt8]].size;
382
- if (countOfBytes == 0) {
383
- // throw SwiftyRSAError(message: "Provided public key is empty")
384
- currentError = [self publicHeaderStrippingErrorForCode:JWTPublicHeaderStrippingError_KeyIsEmpty];
385
- if (error) {
386
- *error = currentError;
387
- }
388
- return nil;
389
- }
390
- // var byteArray = [UInt8](repeating: 0, count: count)
391
- // (keyData as NSData).getBytes(&byteArray, length: keyData.count)
392
- // UInt8 *bytes = (UInt8*)malloc(countOfBytes);
393
- UInt8 *bytes = (UInt8 *)[currentData bytes];
394
- // memcpy(bytes, [currentData bytes], countOfBytes);
395
-
396
- // var index = 0
397
- // guard byteArray[index] == 0x30 else {
398
- // throw SwiftyRSAError(message: "Provided key doesn't have a valid ASN.1 structure (first byte should be 0x30 == SEQUENCE)")
399
- // }
400
-
401
- UInt8 index = 0;
402
- if (bytes[index] != 0x30) {
403
- // throw SwiftyRSAError(message: "Provided key doesn't have a valid ASN.1 structure (first byte should be 0x30 == SEQUENCE)")
404
- currentError = [self publicHeaderStrippingErrorForCode:JWTPublicHeaderStrippingError_Invalid_ASN1_Structure];
405
- if (error) {
406
- *error = currentError;
407
- }
408
- return nil;
409
- }
410
-
411
- // index += 1
412
- // if byteArray[index] > 0x80 {
413
- // index += Int(byteArray[index]) - 0x80 + 1
414
- // } else {
415
- // index += 1
416
- // }
417
- index += 1;
418
- if (bytes[index] > 0x80) {
419
- index += (SInt8)bytes[index] - 0x80 + 1;
420
- }
421
- else {
422
- index += 1;
423
- }
424
-
425
- // Headerless!
426
- // // If current byte marks an integer (0x02), it means the key doesn't have a X509 header and just
427
- // // contains its modulo & public exponent. In this case, we can just return the provided DER data as is.
428
- // if Int(byteArray[index]) == 0x02 {
429
- // return keyData
430
- // }
431
- if ((SInt8)bytes[index] == 0x02) {
432
- return currentData;
433
- }
434
-
435
- // Has header.
436
-
437
- // // Now that we've excluded the possibility of headerless key, we're looking for a valid X509 header sequence.
438
- // // It should look like this:
439
- // // 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00
440
- // guard Int(byteArray[index]) == 0x30 else {
441
- // throw SwiftyRSAError(message: "Provided key doesn't have a valid X509 header")
442
- // }
443
- if ((SInt8)bytes[index] != 0x30) {
444
- // throw SwiftyRSAError(message: "Provided key doesn't have a valid X509 header")
445
- currentError = [self publicHeaderStrippingErrorForCode:JWTPublicHeaderStrippingError_Invalid_X509_Header];
446
- if (error) {
447
- *error = currentError;
448
- }
449
- return nil;
450
- }
451
-
452
- // index += 15
453
- // if byteArray[index] != 0x03 {
454
- // throw SwiftyRSAError(message: "Invalid byte at index \(index - 1) (\(byteArray[index - 1])) for public key header")
455
- // }
456
- index += 15;
457
- if (bytes[index] != 0x03) {
458
- // throw SwiftyRSAError(message: "Invalid byte at index \(index - 1) (\(byteArray[index - 1])) for public key header")
459
- currentError = [self publicHeaderStrippingErrorForCode:JWTPublicHeaderStrippingError_Invalid_Byte_At_Index parameters:@{@"index" : @(index - 1), @"byte": @(bytes[index - 1] ?: 0)}];
460
- if (error) {
461
- *error = currentError;
462
- }
463
- return nil;
464
- }
465
- // index += 1
466
- // if byteArray[index] > 0x80 {
467
- // index += Int(byteArray[index]) - 0x80 + 1
468
- // } else {
469
- // index += 1
470
- // }
471
- index += 1;
472
- if (bytes[index] > 0x80) {
473
- index += (SInt8)bytes[index] - 0x80 + 1;
474
- }
475
- else {
476
- index += 1;
477
- }
478
- // guard byteArray[index] == 0 else {
479
- // throw SwiftyRSAError(message: "Invalid byte at index \(index - 1) (\(byteArray[index - 1])) for public key header")
480
- // }
481
- if (bytes[index] != 0) {
482
- // throw SwiftyRSAError(message: "Invalid byte at index \(index - 1) (\(byteArray[index - 1])) for public key header")
483
- currentError = [self publicHeaderStrippingErrorForCode:JWTPublicHeaderStrippingError_Invalid_Byte_At_Index parameters:@{@"index" : @(index - 1), @"byte": @(bytes[index - 1] ?: 0)}];
484
- if (error) {
485
- *error = currentError;
486
- }
487
- return nil;
488
- }
489
- // index += 1
490
- //
491
- // let strippedKeyBytes = [UInt8](byteArray[index...keyData.count - 1])
492
- // let data = Data(bytes: UnsafePointer<UInt8>(strippedKeyBytes), count: keyData.count - index)
493
- index += 1;
494
- NSInteger countOfStrippedBytes = currentData.length - index;
495
- UInt8 *strippedBytes = (UInt8 *)(bytes + index);
496
- NSData *resultData = [[NSData alloc] initWithBytes:strippedBytes length:countOfStrippedBytes];
497
- // return data
498
- return resultData;
499
- }
500
- @end
@@ -1,18 +0,0 @@
1
- //
2
- // JWTClaim.h
3
- // JWT
4
- //
5
- // Created by Lobanov Dmitry on 13.02.16.
6
- // Copyright © 2016 Karma. All rights reserved.
7
- //
8
-
9
- #import <Foundation/Foundation.h>
10
-
11
- @interface JWTClaim : NSObject
12
-
13
- + (NSString *)name;
14
- + (instancetype)claimByName:(NSString *)name;
15
- + (BOOL)verifyValue:(NSObject *)value withTrustedValue:(NSObject *)trustedValue;
16
- - (BOOL)verifyValue:(NSObject *)value withTrustedValue:(NSObject *)trustedValue;
17
-
18
- @end