react-native-quick-crypto 0.7.11 → 1.0.0-beta.10

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 (419) hide show
  1. package/QuickCrypto.podspec +47 -0
  2. package/README.md +6 -4
  3. package/android/CMakeLists.txt +26 -55
  4. package/android/build.gradle +70 -112
  5. package/android/gradle.properties +3 -3
  6. package/android/src/main/cpp/cpp-adapter.cpp +3 -64
  7. package/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.java +43 -0
  8. package/cpp/ed25519/HybridEdKeyPair.cpp +268 -0
  9. package/cpp/ed25519/HybridEdKeyPair.hpp +85 -0
  10. package/cpp/pbkdf2/HybridPbkdf2.cpp +72 -0
  11. package/cpp/pbkdf2/HybridPbkdf2.hpp +35 -0
  12. package/cpp/random/HybridRandom.cpp +59 -0
  13. package/cpp/random/HybridRandom.hpp +33 -0
  14. package/cpp/utils/Utils.hpp +20 -0
  15. package/lib/commonjs/ed.js +42 -0
  16. package/lib/commonjs/ed.js.map +1 -0
  17. package/lib/commonjs/index.js +90 -39
  18. package/lib/commonjs/index.js.map +1 -1
  19. package/lib/commonjs/keys/classes.js +191 -0
  20. package/lib/commonjs/keys/classes.js.map +1 -0
  21. package/lib/commonjs/keys/generateKeyPair.js +148 -0
  22. package/lib/commonjs/keys/generateKeyPair.js.map +1 -0
  23. package/lib/commonjs/keys/index.js +62 -0
  24. package/lib/commonjs/keys/index.js.map +1 -0
  25. package/lib/commonjs/keys/signVerify.js +41 -0
  26. package/lib/commonjs/keys/signVerify.js.map +1 -0
  27. package/lib/commonjs/keys/utils.js +118 -0
  28. package/lib/commonjs/keys/utils.js.map +1 -0
  29. package/lib/commonjs/pbkdf2.js +29 -19
  30. package/lib/commonjs/pbkdf2.js.map +1 -1
  31. package/lib/commonjs/random.js +27 -11
  32. package/lib/commonjs/random.js.map +1 -1
  33. package/lib/commonjs/{NativeQuickCrypto/aes.js → specs/edKeyPair.nitro.js} +1 -1
  34. package/lib/commonjs/{NativeQuickCrypto/aes.js.map → specs/edKeyPair.nitro.js.map} +1 -1
  35. package/lib/commonjs/{NativeQuickCrypto/keygen.js → specs/keyObjectHandle.nitro.js} +1 -1
  36. package/lib/commonjs/{NativeQuickCrypto/hash.js.map → specs/keyObjectHandle.nitro.js.map} +1 -1
  37. package/lib/commonjs/{NativeQuickCrypto/rsa.js → specs/pbkdf2.nitro.js} +1 -1
  38. package/lib/{module/NativeQuickCrypto/aes.js.map → commonjs/specs/pbkdf2.nitro.js.map} +1 -1
  39. package/lib/commonjs/{NativeQuickCrypto/webcrypto.js → specs/random.nitro.js} +1 -1
  40. package/lib/{module/NativeQuickCrypto/rsa.js.map → commonjs/specs/random.nitro.js.map} +1 -1
  41. package/lib/commonjs/utils/conversion.js +117 -0
  42. package/lib/commonjs/utils/conversion.js.map +1 -0
  43. package/lib/commonjs/utils/errors.js +14 -0
  44. package/lib/commonjs/utils/errors.js.map +1 -0
  45. package/lib/commonjs/{Hashnames.js → utils/hashnames.js} +2 -5
  46. package/lib/commonjs/utils/hashnames.js.map +1 -0
  47. package/lib/commonjs/utils/index.js +61 -0
  48. package/lib/commonjs/utils/index.js.map +1 -0
  49. package/lib/commonjs/utils/types.js +40 -0
  50. package/lib/commonjs/utils/types.js.map +1 -0
  51. package/lib/commonjs/utils/validation.js +25 -0
  52. package/lib/commonjs/utils/validation.js.map +1 -0
  53. package/lib/module/ed.js +37 -0
  54. package/lib/module/ed.js.map +1 -0
  55. package/lib/module/index.js +44 -37
  56. package/lib/module/index.js.map +1 -1
  57. package/lib/module/keys/classes.js +182 -0
  58. package/lib/module/keys/classes.js.map +1 -0
  59. package/lib/module/keys/generateKeyPair.js +148 -0
  60. package/lib/module/keys/generateKeyPair.js.map +1 -0
  61. package/lib/module/keys/index.js +29 -0
  62. package/lib/module/keys/index.js.map +1 -0
  63. package/lib/module/keys/signVerify.js +41 -0
  64. package/lib/module/keys/signVerify.js.map +1 -0
  65. package/lib/module/keys/utils.js +110 -0
  66. package/lib/module/keys/utils.js.map +1 -0
  67. package/lib/module/pbkdf2.js +17 -7
  68. package/lib/module/pbkdf2.js.map +1 -1
  69. package/lib/module/random.js +26 -10
  70. package/lib/module/random.js.map +1 -1
  71. package/lib/module/specs/edKeyPair.nitro.js +4 -0
  72. package/lib/{commonjs/NativeQuickCrypto/rsa.js.map → module/specs/edKeyPair.nitro.js.map} +1 -1
  73. package/lib/module/specs/keyObjectHandle.nitro.js +4 -0
  74. package/lib/{commonjs/NativeQuickCrypto/hmac.js.map → module/specs/keyObjectHandle.nitro.js.map} +1 -1
  75. package/lib/module/specs/pbkdf2.nitro.js +4 -0
  76. package/lib/module/specs/pbkdf2.nitro.js.map +1 -0
  77. package/lib/module/specs/random.nitro.js +4 -0
  78. package/lib/module/specs/random.nitro.js.map +1 -0
  79. package/lib/module/utils/conversion.js +107 -0
  80. package/lib/module/utils/conversion.js.map +1 -0
  81. package/lib/module/utils/errors.js +10 -0
  82. package/lib/module/utils/errors.js.map +1 -0
  83. package/lib/module/{Hashnames.js → utils/hashnames.js} +2 -5
  84. package/lib/module/utils/hashnames.js.map +1 -0
  85. package/lib/module/utils/index.js +8 -0
  86. package/lib/module/utils/index.js.map +1 -0
  87. package/lib/module/utils/types.js +42 -0
  88. package/lib/module/utils/types.js.map +1 -0
  89. package/lib/module/utils/validation.js +19 -0
  90. package/lib/module/utils/validation.js.map +1 -0
  91. package/lib/tsconfig.tsbuildinfo +1 -0
  92. package/lib/typescript/ed.d.ts +17 -0
  93. package/lib/typescript/ed.d.ts.map +1 -0
  94. package/lib/typescript/index.d.ts +74 -0
  95. package/lib/typescript/index.d.ts.map +1 -0
  96. package/lib/typescript/keys/classes.d.ts +38 -0
  97. package/lib/typescript/keys/classes.d.ts.map +1 -0
  98. package/lib/typescript/keys/generateKeyPair.d.ts +1 -0
  99. package/lib/typescript/keys/generateKeyPair.d.ts.map +1 -0
  100. package/lib/typescript/keys/index.d.ts +4 -0
  101. package/lib/typescript/keys/index.d.ts.map +1 -0
  102. package/lib/typescript/keys/signVerify.d.ts +1 -0
  103. package/lib/typescript/keys/signVerify.d.ts.map +1 -0
  104. package/lib/typescript/keys/utils.d.ts +32 -0
  105. package/lib/typescript/keys/utils.d.ts.map +1 -0
  106. package/lib/typescript/{src/pbkdf2.d.ts → pbkdf2.d.ts} +4 -3
  107. package/lib/typescript/pbkdf2.d.ts.map +1 -0
  108. package/lib/typescript/{src/random.d.ts → random.d.ts} +4 -4
  109. package/lib/typescript/random.d.ts.map +1 -0
  110. package/lib/typescript/specs/edKeyPair.nitro.d.ts +16 -0
  111. package/lib/typescript/specs/edKeyPair.nitro.d.ts.map +1 -0
  112. package/lib/typescript/specs/keyObjectHandle.nitro.d.ts +15 -0
  113. package/lib/typescript/specs/keyObjectHandle.nitro.d.ts.map +1 -0
  114. package/lib/typescript/specs/pbkdf2.nitro.d.ts +9 -0
  115. package/lib/typescript/specs/pbkdf2.nitro.d.ts.map +1 -0
  116. package/lib/typescript/specs/random.nitro.d.ts +9 -0
  117. package/lib/typescript/specs/random.nitro.d.ts.map +1 -0
  118. package/lib/typescript/utils/conversion.d.ts +25 -0
  119. package/lib/typescript/utils/conversion.d.ts.map +1 -0
  120. package/lib/typescript/utils/errors.d.ts +7 -0
  121. package/lib/typescript/utils/errors.d.ts.map +1 -0
  122. package/lib/typescript/{src/Hashnames.d.ts → utils/hashnames.d.ts} +3 -3
  123. package/lib/typescript/utils/hashnames.d.ts.map +1 -0
  124. package/lib/typescript/utils/index.d.ts +6 -0
  125. package/lib/typescript/utils/index.d.ts.map +1 -0
  126. package/lib/typescript/utils/types.d.ts +162 -0
  127. package/lib/typescript/utils/types.d.ts.map +1 -0
  128. package/lib/typescript/utils/validation.d.ts +8 -0
  129. package/lib/typescript/utils/validation.d.ts.map +1 -0
  130. package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +65 -0
  131. package/nitrogen/generated/android/QuickCrypto+autolinking.gradle +27 -0
  132. package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +64 -0
  133. package/nitrogen/generated/android/QuickCryptoOnLoad.hpp +25 -0
  134. package/nitrogen/generated/ios/QuickCrypto+autolinking.rb +58 -0
  135. package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp +17 -0
  136. package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp +27 -0
  137. package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp +38 -0
  138. package/nitrogen/generated/ios/QuickCryptoAutolinking.mm +55 -0
  139. package/nitrogen/generated/ios/QuickCryptoAutolinking.swift +12 -0
  140. package/nitrogen/generated/shared/c++/CFRGKeyPairType.hpp +86 -0
  141. package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.cpp +29 -0
  142. package/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.hpp +74 -0
  143. package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.cpp +27 -0
  144. package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.hpp +93 -0
  145. package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.cpp +22 -0
  146. package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.hpp +66 -0
  147. package/nitrogen/generated/shared/c++/HybridRandomSpec.cpp +22 -0
  148. package/nitrogen/generated/shared/c++/HybridRandomSpec.hpp +65 -0
  149. package/nitrogen/generated/shared/c++/JWK.hpp +162 -0
  150. package/nitrogen/generated/shared/c++/JWKkty.hpp +86 -0
  151. package/nitrogen/generated/shared/c++/JWKuse.hpp +78 -0
  152. package/nitrogen/generated/shared/c++/KFormatType.hpp +65 -0
  153. package/nitrogen/generated/shared/c++/KeyDetail.hpp +93 -0
  154. package/nitrogen/generated/shared/c++/KeyEncoding.hpp +66 -0
  155. package/nitrogen/generated/shared/c++/KeyType.hpp +65 -0
  156. package/nitrogen/generated/shared/c++/KeyUsage.hpp +102 -0
  157. package/nitrogen/generated/shared/c++/NamedCurve.hpp +82 -0
  158. package/package.json +57 -51
  159. package/src/ed.ts +79 -0
  160. package/src/index.ts +43 -47
  161. package/src/keys/classes.ts +211 -0
  162. package/src/keys/generateKeyPair.ts +146 -0
  163. package/src/keys/index.ts +42 -0
  164. package/src/keys/signVerify.ts +39 -0
  165. package/src/keys/utils.ts +184 -0
  166. package/src/pbkdf2.ts +26 -15
  167. package/src/random.ts +33 -20
  168. package/src/specs/edKeyPair.nitro.ts +41 -0
  169. package/src/specs/keyObjectHandle.nitro.ts +32 -0
  170. package/src/{NativeQuickCrypto/pbkdf2.ts → specs/pbkdf2.nitro.ts} +8 -6
  171. package/src/specs/random.nitro.ts +14 -0
  172. package/src/utils/conversion.ts +123 -0
  173. package/src/utils/errors.ts +15 -0
  174. package/src/{Hashnames.ts → utils/hashnames.ts} +4 -7
  175. package/src/utils/index.ts +5 -0
  176. package/src/utils/types.ts +275 -0
  177. package/src/utils/validation.ts +35 -0
  178. package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoModule.java +0 -70
  179. package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoPackage.java +0 -25
  180. package/cpp/Cipher/MGLCipherHostObject.cpp +0 -663
  181. package/cpp/Cipher/MGLCipherHostObject.h +0 -90
  182. package/cpp/Cipher/MGLCreateCipherInstaller.cpp +0 -75
  183. package/cpp/Cipher/MGLCreateCipherInstaller.h +0 -22
  184. package/cpp/Cipher/MGLCreateDecipherInstaller.cpp +0 -77
  185. package/cpp/Cipher/MGLCreateDecipherInstaller.h +0 -17
  186. package/cpp/Cipher/MGLGenerateKeyPairInstaller.cpp +0 -134
  187. package/cpp/Cipher/MGLGenerateKeyPairInstaller.h +0 -35
  188. package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.cpp +0 -63
  189. package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.h +0 -37
  190. package/cpp/Cipher/MGLPublicCipher.h +0 -124
  191. package/cpp/Cipher/MGLPublicCipherInstaller.h +0 -107
  192. package/cpp/Cipher/MGLRsa.cpp +0 -573
  193. package/cpp/Cipher/MGLRsa.h +0 -109
  194. package/cpp/HMAC/MGLHmacHostObject.cpp +0 -95
  195. package/cpp/HMAC/MGLHmacHostObject.h +0 -39
  196. package/cpp/HMAC/MGLHmacInstaller.cpp +0 -43
  197. package/cpp/HMAC/MGLHmacInstaller.h +0 -20
  198. package/cpp/Hash/MGLHashHostObject.cpp +0 -147
  199. package/cpp/Hash/MGLHashHostObject.h +0 -53
  200. package/cpp/Hash/MGLHashInstaller.cpp +0 -44
  201. package/cpp/Hash/MGLHashInstaller.h +0 -20
  202. package/cpp/JSIUtils/MGLJSIMacros.h +0 -110
  203. package/cpp/JSIUtils/MGLJSIUtils.h +0 -41
  204. package/cpp/JSIUtils/MGLSmartHostObject.cpp +0 -43
  205. package/cpp/JSIUtils/MGLSmartHostObject.h +0 -46
  206. package/cpp/JSIUtils/MGLThreadAwareHostObject.cpp +0 -24
  207. package/cpp/JSIUtils/MGLThreadAwareHostObject.h +0 -43
  208. package/cpp/JSIUtils/MGLTypedArray.cpp +0 -352
  209. package/cpp/JSIUtils/MGLTypedArray.h +0 -179
  210. package/cpp/MGLKeys.cpp +0 -1426
  211. package/cpp/MGLKeys.h +0 -203
  212. package/cpp/MGLQuickCryptoHostObject.cpp +0 -127
  213. package/cpp/MGLQuickCryptoHostObject.h +0 -30
  214. package/cpp/Random/MGLRandomHostObject.cpp +0 -96
  215. package/cpp/Random/MGLRandomHostObject.h +0 -27
  216. package/cpp/Sig/MGLSignHostObjects.cpp +0 -757
  217. package/cpp/Sig/MGLSignHostObjects.h +0 -128
  218. package/cpp/Sig/MGLSignInstaller.cpp +0 -24
  219. package/cpp/Sig/MGLSignInstaller.h +0 -29
  220. package/cpp/Sig/MGLVerifyInstaller.cpp +0 -24
  221. package/cpp/Sig/MGLVerifyInstaller.h +0 -22
  222. package/cpp/Utils/MGLDispatchQueue.cpp +0 -75
  223. package/cpp/Utils/MGLDispatchQueue.h +0 -55
  224. package/cpp/Utils/MGLUtils.cpp +0 -295
  225. package/cpp/Utils/MGLUtils.h +0 -358
  226. package/cpp/Utils/base64.h +0 -320
  227. package/cpp/Utils/logs.h +0 -38
  228. package/cpp/Utils/node.h +0 -13
  229. package/cpp/fastpbkdf2/MGLPbkdf2HostObject.cpp +0 -164
  230. package/cpp/fastpbkdf2/MGLPbkdf2HostObject.h +0 -29
  231. package/cpp/webcrypto/MGLWebCrypto.cpp +0 -125
  232. package/cpp/webcrypto/MGLWebCrypto.h +0 -32
  233. package/cpp/webcrypto/crypto_aes.cpp +0 -516
  234. package/cpp/webcrypto/crypto_aes.h +0 -79
  235. package/cpp/webcrypto/crypto_ec.cpp +0 -424
  236. package/cpp/webcrypto/crypto_ec.h +0 -78
  237. package/cpp/webcrypto/crypto_keygen.cpp +0 -86
  238. package/cpp/webcrypto/crypto_keygen.h +0 -38
  239. package/ios/QuickCrypto.xcodeproj/project.pbxproj +0 -274
  240. package/ios/QuickCrypto.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  241. package/ios/QuickCrypto.xcodeproj/project.xcworkspace/xcuserdata/brad.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  242. package/ios/QuickCrypto.xcodeproj/xcuserdata/brad.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
  243. package/ios/QuickCryptoModule.h +0 -5
  244. package/ios/QuickCryptoModule.mm +0 -57
  245. package/lib/commonjs/Algorithms.js +0 -224
  246. package/lib/commonjs/Algorithms.js.map +0 -1
  247. package/lib/commonjs/Cipher.js +0 -504
  248. package/lib/commonjs/Cipher.js.map +0 -1
  249. package/lib/commonjs/Hash.js +0 -102
  250. package/lib/commonjs/Hash.js.map +0 -1
  251. package/lib/commonjs/Hashnames.js.map +0 -1
  252. package/lib/commonjs/Hmac.js +0 -81
  253. package/lib/commonjs/Hmac.js.map +0 -1
  254. package/lib/commonjs/NativeQuickCrypto/Cipher.js +0 -30
  255. package/lib/commonjs/NativeQuickCrypto/Cipher.js.map +0 -1
  256. package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js +0 -59
  257. package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
  258. package/lib/commonjs/NativeQuickCrypto/hash.js +0 -2
  259. package/lib/commonjs/NativeQuickCrypto/hmac.js +0 -2
  260. package/lib/commonjs/NativeQuickCrypto/keygen.js.map +0 -1
  261. package/lib/commonjs/NativeQuickCrypto/pbkdf2.js +0 -2
  262. package/lib/commonjs/NativeQuickCrypto/pbkdf2.js.map +0 -1
  263. package/lib/commonjs/NativeQuickCrypto/random.js +0 -2
  264. package/lib/commonjs/NativeQuickCrypto/random.js.map +0 -1
  265. package/lib/commonjs/NativeQuickCrypto/sig.js +0 -19
  266. package/lib/commonjs/NativeQuickCrypto/sig.js.map +0 -1
  267. package/lib/commonjs/NativeQuickCrypto/webcrypto.js.map +0 -1
  268. package/lib/commonjs/Utils.js +0 -437
  269. package/lib/commonjs/Utils.js.map +0 -1
  270. package/lib/commonjs/aes.js +0 -282
  271. package/lib/commonjs/aes.js.map +0 -1
  272. package/lib/commonjs/constants.js +0 -85
  273. package/lib/commonjs/constants.js.map +0 -1
  274. package/lib/commonjs/ec.js +0 -275
  275. package/lib/commonjs/ec.js.map +0 -1
  276. package/lib/commonjs/keygen.js +0 -58
  277. package/lib/commonjs/keygen.js.map +0 -1
  278. package/lib/commonjs/keys.js +0 -497
  279. package/lib/commonjs/keys.js.map +0 -1
  280. package/lib/commonjs/rsa.js +0 -248
  281. package/lib/commonjs/rsa.js.map +0 -1
  282. package/lib/commonjs/sig.js +0 -128
  283. package/lib/commonjs/sig.js.map +0 -1
  284. package/lib/commonjs/subtle.js +0 -450
  285. package/lib/commonjs/subtle.js.map +0 -1
  286. package/lib/commonjs/webcrypto.js +0 -14
  287. package/lib/commonjs/webcrypto.js.map +0 -1
  288. package/lib/module/Algorithms.js +0 -219
  289. package/lib/module/Algorithms.js.map +0 -1
  290. package/lib/module/Cipher.js +0 -493
  291. package/lib/module/Cipher.js.map +0 -1
  292. package/lib/module/Hash.js +0 -96
  293. package/lib/module/Hash.js.map +0 -1
  294. package/lib/module/Hashnames.js.map +0 -1
  295. package/lib/module/Hmac.js +0 -76
  296. package/lib/module/Hmac.js.map +0 -1
  297. package/lib/module/NativeQuickCrypto/Cipher.js +0 -26
  298. package/lib/module/NativeQuickCrypto/Cipher.js.map +0 -1
  299. package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js +0 -56
  300. package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
  301. package/lib/module/NativeQuickCrypto/aes.js +0 -4
  302. package/lib/module/NativeQuickCrypto/hash.js +0 -2
  303. package/lib/module/NativeQuickCrypto/hash.js.map +0 -1
  304. package/lib/module/NativeQuickCrypto/hmac.js +0 -2
  305. package/lib/module/NativeQuickCrypto/hmac.js.map +0 -1
  306. package/lib/module/NativeQuickCrypto/keygen.js +0 -4
  307. package/lib/module/NativeQuickCrypto/keygen.js.map +0 -1
  308. package/lib/module/NativeQuickCrypto/pbkdf2.js +0 -2
  309. package/lib/module/NativeQuickCrypto/pbkdf2.js.map +0 -1
  310. package/lib/module/NativeQuickCrypto/random.js +0 -2
  311. package/lib/module/NativeQuickCrypto/random.js.map +0 -1
  312. package/lib/module/NativeQuickCrypto/rsa.js +0 -4
  313. package/lib/module/NativeQuickCrypto/sig.js +0 -17
  314. package/lib/module/NativeQuickCrypto/sig.js.map +0 -1
  315. package/lib/module/NativeQuickCrypto/webcrypto.js +0 -4
  316. package/lib/module/NativeQuickCrypto/webcrypto.js.map +0 -1
  317. package/lib/module/Utils.js +0 -369
  318. package/lib/module/Utils.js.map +0 -1
  319. package/lib/module/aes.js +0 -275
  320. package/lib/module/aes.js.map +0 -1
  321. package/lib/module/constants.js +0 -81
  322. package/lib/module/constants.js.map +0 -1
  323. package/lib/module/ec.js +0 -266
  324. package/lib/module/ec.js.map +0 -1
  325. package/lib/module/keygen.js +0 -51
  326. package/lib/module/keygen.js.map +0 -1
  327. package/lib/module/keys.js +0 -482
  328. package/lib/module/keys.js.map +0 -1
  329. package/lib/module/rsa.js +0 -242
  330. package/lib/module/rsa.js.map +0 -1
  331. package/lib/module/sig.js +0 -123
  332. package/lib/module/sig.js.map +0 -1
  333. package/lib/module/subtle.js +0 -445
  334. package/lib/module/subtle.js.map +0 -1
  335. package/lib/module/webcrypto.js +0 -10
  336. package/lib/module/webcrypto.js.map +0 -1
  337. package/lib/typescript/src/Algorithms.d.ts +0 -4
  338. package/lib/typescript/src/Algorithms.d.ts.map +0 -1
  339. package/lib/typescript/src/Cipher.d.ts +0 -85
  340. package/lib/typescript/src/Cipher.d.ts.map +0 -1
  341. package/lib/typescript/src/Hash.d.ts +0 -44
  342. package/lib/typescript/src/Hash.d.ts.map +0 -1
  343. package/lib/typescript/src/Hashnames.d.ts.map +0 -1
  344. package/lib/typescript/src/Hmac.d.ts +0 -37
  345. package/lib/typescript/src/Hmac.d.ts.map +0 -1
  346. package/lib/typescript/src/NativeQuickCrypto/Cipher.d.ts +0 -44
  347. package/lib/typescript/src/NativeQuickCrypto/Cipher.d.ts.map +0 -1
  348. package/lib/typescript/src/NativeQuickCrypto/NativeQuickCrypto.d.ts +0 -33
  349. package/lib/typescript/src/NativeQuickCrypto/NativeQuickCrypto.d.ts.map +0 -1
  350. package/lib/typescript/src/NativeQuickCrypto/aes.d.ts +0 -5
  351. package/lib/typescript/src/NativeQuickCrypto/aes.d.ts.map +0 -1
  352. package/lib/typescript/src/NativeQuickCrypto/hash.d.ts +0 -7
  353. package/lib/typescript/src/NativeQuickCrypto/hash.d.ts.map +0 -1
  354. package/lib/typescript/src/NativeQuickCrypto/hmac.d.ts +0 -6
  355. package/lib/typescript/src/NativeQuickCrypto/hmac.d.ts.map +0 -1
  356. package/lib/typescript/src/NativeQuickCrypto/keygen.d.ts +0 -4
  357. package/lib/typescript/src/NativeQuickCrypto/keygen.d.ts.map +0 -1
  358. package/lib/typescript/src/NativeQuickCrypto/pbkdf2.d.ts +0 -5
  359. package/lib/typescript/src/NativeQuickCrypto/pbkdf2.d.ts.map +0 -1
  360. package/lib/typescript/src/NativeQuickCrypto/random.d.ts +0 -5
  361. package/lib/typescript/src/NativeQuickCrypto/random.d.ts.map +0 -1
  362. package/lib/typescript/src/NativeQuickCrypto/rsa.d.ts +0 -5
  363. package/lib/typescript/src/NativeQuickCrypto/rsa.d.ts.map +0 -1
  364. package/lib/typescript/src/NativeQuickCrypto/sig.d.ts +0 -23
  365. package/lib/typescript/src/NativeQuickCrypto/sig.d.ts.map +0 -1
  366. package/lib/typescript/src/NativeQuickCrypto/webcrypto.d.ts +0 -40
  367. package/lib/typescript/src/NativeQuickCrypto/webcrypto.d.ts.map +0 -1
  368. package/lib/typescript/src/Utils.d.ts +0 -71
  369. package/lib/typescript/src/Utils.d.ts.map +0 -1
  370. package/lib/typescript/src/aes.d.ts +0 -22
  371. package/lib/typescript/src/aes.d.ts.map +0 -1
  372. package/lib/typescript/src/constants.d.ts +0 -76
  373. package/lib/typescript/src/constants.d.ts.map +0 -1
  374. package/lib/typescript/src/ec.d.ts +0 -7
  375. package/lib/typescript/src/ec.d.ts.map +0 -1
  376. package/lib/typescript/src/index.d.ts +0 -139
  377. package/lib/typescript/src/index.d.ts.map +0 -1
  378. package/lib/typescript/src/keygen.d.ts +0 -6
  379. package/lib/typescript/src/keygen.d.ts.map +0 -1
  380. package/lib/typescript/src/keys.d.ts +0 -211
  381. package/lib/typescript/src/keys.d.ts.map +0 -1
  382. package/lib/typescript/src/pbkdf2.d.ts.map +0 -1
  383. package/lib/typescript/src/random.d.ts.map +0 -1
  384. package/lib/typescript/src/rsa.d.ts +0 -12
  385. package/lib/typescript/src/rsa.d.ts.map +0 -1
  386. package/lib/typescript/src/sig.d.ts +0 -21
  387. package/lib/typescript/src/sig.d.ts.map +0 -1
  388. package/lib/typescript/src/subtle.d.ts +0 -15
  389. package/lib/typescript/src/subtle.d.ts.map +0 -1
  390. package/lib/typescript/src/webcrypto.d.ts +0 -9
  391. package/lib/typescript/src/webcrypto.d.ts.map +0 -1
  392. package/react-native-quick-crypto.podspec +0 -40
  393. package/src/Algorithms.ts +0 -247
  394. package/src/Cipher.ts +0 -890
  395. package/src/Hash.ts +0 -139
  396. package/src/Hmac.ts +0 -107
  397. package/src/NativeQuickCrypto/Cipher.ts +0 -103
  398. package/src/NativeQuickCrypto/NativeQuickCrypto.ts +0 -106
  399. package/src/NativeQuickCrypto/aes.ts +0 -14
  400. package/src/NativeQuickCrypto/hash.ts +0 -10
  401. package/src/NativeQuickCrypto/hmac.ts +0 -9
  402. package/src/NativeQuickCrypto/keygen.ts +0 -7
  403. package/src/NativeQuickCrypto/random.ts +0 -12
  404. package/src/NativeQuickCrypto/rsa.ts +0 -12
  405. package/src/NativeQuickCrypto/sig.ts +0 -46
  406. package/src/NativeQuickCrypto/webcrypto.ts +0 -73
  407. package/src/Utils.ts +0 -628
  408. package/src/aes.ts +0 -402
  409. package/src/constants.ts +0 -79
  410. package/src/ec.ts +0 -374
  411. package/src/keygen.ts +0 -80
  412. package/src/keys.ts +0 -797
  413. package/src/rsa.ts +0 -372
  414. package/src/sig.ts +0 -163
  415. package/src/subtle.ts +0 -643
  416. package/src/webcrypto.ts +0 -8
  417. /package/android/src/main/{AndroidManifestNew.xml → AndroidManifest.xml} +0 -0
  418. /package/{cpp → deps}/fastpbkdf2/fastpbkdf2.c +0 -0
  419. /package/{cpp → deps}/fastpbkdf2/fastpbkdf2.h +0 -0
@@ -1,128 +0,0 @@
1
- #ifndef MGLSignHostObjects_h
2
- #define MGLSignHostObjects_h
3
-
4
- #include <jsi/jsi.h>
5
- #include <openssl/evp.h>
6
-
7
- #include <memory>
8
- #include <optional>
9
- #include <string>
10
- #include <utility>
11
-
12
- #include "MGLKeys.h"
13
- #ifdef ANDROID
14
- #include "JSIUtils/MGLSmartHostObject.h"
15
- #include "Utils/MGLUtils.h"
16
- #else
17
- #include "MGLSmartHostObject.h"
18
- #include "MGLUtils.h"
19
- #endif
20
-
21
- namespace margelo {
22
-
23
- namespace jsi = facebook::jsi;
24
-
25
- static const unsigned int kNoDsaSignature = static_cast<unsigned int>(-1);
26
-
27
- enum mode { kModeSign, kModeVerify };
28
-
29
- enum DSASigEnc {
30
- kSigEncDER,
31
- kSigEncP1363,
32
- };
33
-
34
- class SignBase : public MGLSmartHostObject {
35
- public:
36
- SignBase(std::shared_ptr<react::CallInvoker> jsCallInvoker,
37
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
38
-
39
- typedef enum {
40
- kSignOk,
41
- kSignUnknownDigest,
42
- kSignInit,
43
- kSignNotInitialised,
44
- kSignUpdate,
45
- kSignPrivateKey,
46
- kSignPublicKey,
47
- kSignMalformedSignature
48
- } Error;
49
-
50
- struct SignResult {
51
- Error error;
52
- std::optional<jsi::Value> signature;
53
-
54
- explicit SignResult(Error err, std::optional<jsi::Value> sig = std::nullopt)
55
- : error(err), signature(std::move(sig)) {}
56
- };
57
-
58
- void InstallMethods(mode);
59
-
60
- SignResult SignFinal(jsi::Runtime& runtime, const ManagedEVPPKey& pkey,
61
- int padding, std::optional<int>& salt_len,
62
- DSASigEnc dsa_sig_enc);
63
-
64
- Error VerifyFinal(const ManagedEVPPKey& pkey, const ByteSource& sig,
65
- int padding, std::optional<int>& saltlen,
66
- bool* verify_result);
67
-
68
- protected:
69
- EVPMDPointer mdctx_;
70
- };
71
-
72
- struct SignConfiguration final { // : public MemoryRetainer
73
- enum Mode {
74
- kSign,
75
- kVerify
76
- };
77
- enum Flags {
78
- kHasNone = 0,
79
- kHasSaltLength = 1,
80
- kHasPadding = 2
81
- };
82
-
83
- // CryptoJobMode job_mode; // all async for now
84
- Mode mode;
85
- ManagedEVPPKey key;
86
- ByteSource data;
87
- ByteSource signature;
88
- const EVP_MD* digest = nullptr;
89
- int flags = SignConfiguration::kHasNone;
90
- int padding = 0;
91
- int salt_length = 0;
92
- DSASigEnc dsa_encoding = kSigEncDER;
93
-
94
- SignConfiguration() = default;
95
-
96
- // explicit SignConfiguration(SignConfiguration&& other) noexcept;
97
-
98
- // SignConfiguration& operator=(SignConfiguration&& other) noexcept;
99
-
100
- // void MemoryInfo(MemoryTracker* tracker) const override;
101
- // SET_MEMORY_INFO_NAME(SignConfiguration)
102
- // SET_SELF_SIZE(SignConfiguration)
103
- };
104
-
105
- class SubtleSignVerify {
106
- public:
107
- SignConfiguration GetParamsFromJS(jsi::Runtime &rt, const jsi::Value *args);
108
- void DoSignVerify(jsi::Runtime &rt, const SignConfiguration &params, ByteSource &out);
109
- jsi::Value EncodeOutput(jsi::Runtime &rt,const SignConfiguration &params, ByteSource &out);
110
- };
111
-
112
- class MGLSignHostObject : public SignBase {
113
- public:
114
- explicit MGLSignHostObject(
115
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
116
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
117
- };
118
-
119
- class MGLVerifyHostObject : public SignBase {
120
- public:
121
- explicit MGLVerifyHostObject(
122
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
123
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
124
- };
125
-
126
- } // namespace margelo
127
-
128
- #endif /* MGLSignHostObjects_h */
@@ -1,24 +0,0 @@
1
- #include "MGLSignInstaller.h"
2
-
3
- #include "MGLSignHostObjects.h"
4
- #ifdef ANDROID
5
- #include "JSIUtils/MGLJSIMacros.h"
6
- #else
7
- #include "MGLJSIMacros.h"
8
- #include "logs.h"
9
- #endif
10
-
11
- namespace margelo {
12
-
13
- FieldDefinition getSignFieldDefinition(
14
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
15
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue) {
16
- return buildPair(
17
- "createSign", JSIF([=]) {
18
- auto hostObject =
19
- std::make_shared<MGLSignHostObject>(jsCallInvoker, workerQueue);
20
- return jsi::Object::createFromHostObject(runtime, hostObject);
21
- });
22
- }
23
-
24
- } // namespace margelo
@@ -1,29 +0,0 @@
1
- //
2
- // MGLSignInstaller.hpp
3
- // DoubleConversion
4
- //
5
- // Created by Oscar on 30.06.22.
6
- //
7
-
8
- #ifndef MGLSignInstaller_h
9
- #define MGLSignInstaller_h
10
-
11
- #include <jsi/jsi.h>
12
-
13
- #include <memory>
14
-
15
- #ifdef ANDROID
16
- #include "JSIUtils/MGLSmartHostObject.h"
17
- #else
18
- #include "MGLSmartHostObject.h"
19
- #endif
20
-
21
- namespace margelo {
22
- namespace jsi = facebook::jsi;
23
-
24
- FieldDefinition getSignFieldDefinition(
25
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
26
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
27
- } // namespace margelo
28
-
29
- #endif /* MGLSignInstaller_h */
@@ -1,24 +0,0 @@
1
- #include "MGLVerifyInstaller.h"
2
-
3
- #include "MGLSignHostObjects.h"
4
- #ifdef ANDROID
5
- #include "JSIUtils/MGLJSIMacros.h"
6
- #else
7
- #include "MGLJSIMacros.h"
8
- #include "logs.h"
9
- #endif
10
-
11
- namespace margelo {
12
-
13
- FieldDefinition getVerifyFieldDefinition(
14
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
15
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue) {
16
- return buildPair(
17
- "createVerify", JSIF([=]) {
18
- auto hostObject =
19
- std::make_shared<MGLVerifyHostObject>(jsCallInvoker, workerQueue);
20
- return jsi::Object::createFromHostObject(runtime, hostObject);
21
- });
22
- }
23
-
24
- } // namespace margelo
@@ -1,22 +0,0 @@
1
- #ifndef MGLVerifyInstaller_h
2
- #define MGLVerifyInstaller_h
3
-
4
- #include <jsi/jsi.h>
5
-
6
- #include <memory>
7
-
8
- #ifdef ANDROID
9
- #include "JSIUtils/MGLSmartHostObject.h"
10
- #else
11
- #include "MGLSmartHostObject.h"
12
- #endif
13
-
14
- namespace margelo {
15
- namespace jsi = facebook::jsi;
16
-
17
- FieldDefinition getVerifyFieldDefinition(
18
- std::shared_ptr<react::CallInvoker> jsCallInvoker,
19
- std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
20
- } // namespace margelo
21
-
22
- #endif /* MGLVerifyInstaller_h */
@@ -1,75 +0,0 @@
1
- //
2
- // Created by Szymon on 23/02/2022.
3
- //
4
-
5
- #include "MGLDispatchQueue.h"
6
-
7
- #include <utility>
8
-
9
- namespace margelo {
10
-
11
- namespace DispatchQueue {
12
-
13
- dispatch_queue::dispatch_queue(std::string name, size_t thread_cnt)
14
- : name_{std::move(name)}, threads_(thread_cnt) {
15
- printf("Creating dispatch queue: %s\n", name_.c_str());
16
- printf("Dispatch threads: %zu\n", thread_cnt);
17
-
18
- for (size_t i = 0; i < threads_.size(); i++) {
19
- threads_[i] = std::thread(&dispatch_queue::dispatch_thread_handler, this);
20
- }
21
- }
22
-
23
- dispatch_queue::~dispatch_queue() {
24
- printf("Destructor: Destroying dispatch threads...\n");
25
-
26
- // Signal to dispatch threads that it's time to wrap up
27
- std::unique_lock<std::mutex> lock(lock_);
28
- quit_ = true;
29
- cv_.notify_all();
30
- lock.unlock();
31
-
32
- // Wait for threads to finish before we exit
33
- for (size_t i = 0; i < threads_.size(); i++) {
34
- if (threads_[i].joinable()) {
35
- printf("Destructor: Joining thread %zu until completion\n", i);
36
- threads_[i].join();
37
- }
38
- }
39
- }
40
-
41
- void dispatch_queue::dispatch(const fp_t &op) {
42
- std::unique_lock<std::mutex> lock(lock_);
43
- q_.push(op);
44
- cv_.notify_one();
45
- }
46
-
47
- void dispatch_queue::dispatch(fp_t &&op) {
48
- std::unique_lock<std::mutex> lock(lock_);
49
- q_.push(std::move(op));
50
- cv_.notify_one();
51
- }
52
-
53
- void dispatch_queue::dispatch_thread_handler(void) {
54
- std::unique_lock<std::mutex> lock(lock_);
55
-
56
- do {
57
- // Wait until we have data or a quit signal
58
- cv_.wait(lock, [this] { return (q_.size() || quit_); });
59
-
60
- // after wait, we own the lock
61
- if (!quit_ && q_.size()) {
62
- auto op = std::move(q_.front());
63
- q_.pop();
64
-
65
- // unlock now that we're done messing with the queue
66
- lock.unlock();
67
-
68
- op();
69
-
70
- lock.lock();
71
- }
72
- } while (!quit_);
73
- }
74
- } // namespace DispatchQueue
75
- } // namespace margelo
@@ -1,55 +0,0 @@
1
- //
2
- // Created by Szymon on 23/02/2022.
3
- //
4
-
5
- #ifndef MGL_DISPATCHQUEUE_H
6
- #define MGL_DISPATCHQUEUE_H
7
-
8
- #include <condition_variable>
9
- #include <cstdint>
10
- #include <cstdio>
11
- #include <functional>
12
- #include <mutex>
13
- #include <queue>
14
- #include <string>
15
- #include <thread>
16
- #include <vector>
17
-
18
- namespace margelo {
19
-
20
- // taken from
21
- // https://github.com/embeddedartistry/embedded-resources/blob/master/examples/cpp/dispatch.cpp
22
- namespace DispatchQueue {
23
- class dispatch_queue {
24
- typedef std::function<void(void)> fp_t;
25
-
26
- public:
27
- explicit dispatch_queue(std::string name, size_t thread_cnt = 1);
28
- ~dispatch_queue();
29
-
30
- // dispatch and copy
31
- void dispatch(const fp_t &op);
32
- // dispatch and move
33
- void dispatch(fp_t &&op);
34
-
35
- // Deleted operations
36
- dispatch_queue(const dispatch_queue &rhs) = delete;
37
- dispatch_queue &operator=(const dispatch_queue &rhs) = delete;
38
- dispatch_queue(dispatch_queue &&rhs) = delete;
39
- dispatch_queue &operator=(dispatch_queue &&rhs) = delete;
40
-
41
- private:
42
- std::string name_;
43
- std::mutex lock_;
44
- std::vector<std::thread> threads_;
45
- std::queue<fp_t> q_;
46
- std::condition_variable cv_;
47
- bool quit_ = false;
48
-
49
- void dispatch_thread_handler(void);
50
- };
51
- } // namespace DispatchQueue
52
-
53
- } // namespace margelo
54
-
55
- #endif // MGL_DISPATCHQUEUE_H
@@ -1,295 +0,0 @@
1
- #include "MGLUtils.h"
2
-
3
- #include <jsi/jsi.h>
4
-
5
- #include <iostream>
6
- #include <optional>
7
- #include <string>
8
-
9
- #include "base64.h"
10
-
11
- #ifdef ANDROID
12
- #include "JSIUtils/MGLJSIMacros.h"
13
- #else
14
- #include "MGLJSIMacros.h"
15
- #endif
16
-
17
- namespace margelo {
18
-
19
- namespace jsi = facebook::jsi;
20
-
21
- ByteSource ArrayBufferToByteSource(jsi::Runtime& runtime,
22
- const jsi::ArrayBuffer& buffer) {
23
- if (buffer.size(runtime) == 0) return ByteSource();
24
- char* buf = MallocOpenSSL<char>(buffer.size(runtime));
25
- CHECK_NOT_NULL(buf);
26
- // const cast artificially removes the const qualifier, but you cannot still
27
- // modify the data in this case, this is safe because we are just memcopying
28
- // to the buffer
29
- memcpy(buf, const_cast<jsi::ArrayBuffer&>(buffer).data(runtime),
30
- buffer.size(runtime));
31
- return ByteSource::Allocated(buf, buffer.size(runtime));
32
- }
33
-
34
- ByteSource ArrayBufferToNTCByteSource(jsi::Runtime& runtime,
35
- const jsi::ArrayBuffer& buffer) {
36
- if (buffer.size(runtime) == 0) return ByteSource();
37
- char* buf = MallocOpenSSL<char>(buffer.size(runtime) + 1);
38
- CHECK_NOT_NULL(buf);
39
- buf[buffer.size(runtime)] = 0;
40
- // const cast artificially removes the const qualifier, but you cannot still
41
- // modify the data in this case, this is safe because we are just memcopying
42
- // to the buffer
43
- memcpy(buf, const_cast<jsi::ArrayBuffer&>(buffer).data(runtime),
44
- buffer.size(runtime));
45
- return ByteSource::Allocated(buf, buffer.size(runtime));
46
- }
47
-
48
- ByteSource::ByteSource(ByteSource&& other) noexcept
49
- : data_(other.data_),
50
- allocated_data_(other.allocated_data_),
51
- size_(other.size_) {
52
- other.allocated_data_ = nullptr;
53
- }
54
-
55
- ByteSource::~ByteSource() { OPENSSL_clear_free(allocated_data_, size_); }
56
-
57
- ByteSource& ByteSource::operator=(ByteSource&& other) noexcept {
58
- if (&other != this) {
59
- OPENSSL_clear_free(allocated_data_, size_);
60
- data_ = other.data_;
61
- allocated_data_ = other.allocated_data_;
62
- other.allocated_data_ = nullptr;
63
- size_ = other.size_;
64
- }
65
- return *this;
66
- }
67
-
68
- // std::unique_ptr<BackingStore> ByteSource::ReleaseToBackingStore() {
69
- // // It's ok for allocated_data_ to be nullptr but
70
- // // only if size_ is zero.
71
- // CHECK_IMPLIES(size_ > 0, allocated_data_ != nullptr);
72
- // std::unique_ptr<BackingStore> ptr = ArrayBuffer::NewBackingStore(
73
- // allocated_data_,
74
- // size(),
75
- // [](void*
76
- // data,
77
- // size_t
78
- // length,
79
- // void*
80
- // deleter_data)
81
- // {
82
- // OPENSSL_clear_free(deleter_data,
83
- // length);
84
- // },
85
- // allocated_data_);
86
- // CHECK(ptr);
87
- // allocated_data_ = nullptr;
88
- // data_ = nullptr;
89
- // size_ = 0;
90
- // return ptr;
91
- // }
92
- //
93
- // Local<ArrayBuffer> ByteSource::ToArrayBuffer(Environment* env) {
94
- // std::unique_ptr<BackingStore> store = ReleaseToBackingStore();
95
- // return ArrayBuffer::New(env->isolate(), std::move(store));
96
- // }
97
- //
98
- // MaybeLocal<Uint8Array> ByteSource::ToBuffer(Environment* env) {
99
- // Local<ArrayBuffer> ab = ToArrayBuffer(env);
100
- // return Buffer::New(env, ab, 0, ab->ByteLength());
101
- // }
102
-
103
- ByteSource ByteSource::FromBIO(const BIOPointer& bio) {
104
- // CHECK(bio);
105
- BUF_MEM* bptr;
106
- BIO_get_mem_ptr(bio.get(), &bptr);
107
- ByteSource::Builder out(bptr->length);
108
- memcpy(out.data<void>(), bptr->data, bptr->length);
109
- return std::move(out).release();
110
- }
111
-
112
- ByteSource ByteSource::FromEncodedString(jsi::Runtime &rt,
113
- const std::string key,
114
- enum encoding enc) {
115
- // memcpy & size together properly handle strings containing \0 characters
116
- std::string result = StringBytesWrite(rt, key, enc);
117
- size_t size = result.size();
118
- ByteSource::Builder out(size);
119
- memcpy(out.data<void>(), result.data(), size);
120
- return std::move(out).release(size);
121
- }
122
-
123
- ByteSource ByteSource::FromStringOrBuffer(jsi::Runtime& runtime,
124
- const jsi::Value& value) {
125
- return value.isString()
126
- ? FromString(value.asString(runtime).utf8(runtime))
127
- : FromBuffer(runtime,
128
- value.asObject(runtime).getArrayBuffer(runtime));
129
- }
130
-
131
- // ntc = null terminated copy
132
- ByteSource ByteSource::FromString(std::string str, bool ntc) {
133
- // CHECK(str->IsString());
134
- size_t size = str.size();
135
- size_t alloc_size = ntc ? size + 1 : size;
136
- ByteSource::Builder out(alloc_size);
137
- if (ntc) {
138
- strcpy(out.data<char>(), str.data());
139
- } else {
140
- strncpy(out.data<char>(), str.data(), alloc_size);
141
- }
142
-
143
- return std::move(out).release(alloc_size);
144
- }
145
-
146
- ByteSource ByteSource::FromBuffer(jsi::Runtime& runtime,
147
- const jsi::ArrayBuffer& buffer, bool ntc) {
148
- return ntc ? ArrayBufferToNTCByteSource(runtime, buffer)
149
- : ArrayBufferToByteSource(runtime, buffer);
150
- }
151
- //
152
- // ByteSource ByteSource::FromSecretKeyBytes(
153
- // Environment* env,
154
- // Local<Value> value) {
155
- // // A key can be passed as a string, buffer or KeyObject with type
156
- // 'secret'.
157
- // // If it is a string, we need to convert it to a buffer. We are not doing
158
- // that
159
- // // in JS to avoid creating an unprotected copy on the heap.
160
- // return value->IsString() || IsAnyByteSource(value) ?
161
- // ByteSource::FromStringOrBuffer(env, value) :
162
- // ByteSource::FromSymmetricKeyObjectHandle(value);
163
- // }
164
-
165
- // ByteSource ByteSource::NullTerminatedCopy(Environment* env,
166
- // Local<Value> value) {
167
- // return Buffer::HasInstance(value) ? FromBuffer(value, true)
168
- // : FromString(env, value.As<String>(), true);
169
- // }
170
-
171
- // ByteSource ByteSource::FromSymmetricKeyObjectHandle(Local<Value> handle) {
172
- // CHECK(handle->IsObject());
173
- // KeyObjectHandle* key = Unwrap<KeyObjectHandle>(handle.As<Object>());
174
- // CHECK_NOT_NULL(key);
175
- // return Foreign(key->Data()->GetSymmetricKey(),
176
- // key->Data()->GetSymmetricKeySize());
177
- // }
178
-
179
- ByteSource ByteSource::Allocated(void* data, size_t size) {
180
- return ByteSource(data, data, size);
181
- }
182
-
183
- ByteSource ByteSource::Foreign(const void* data, size_t size) {
184
- return ByteSource(data, nullptr, size);
185
- }
186
-
187
- ByteSource ByteSource::FromBN(const BIGNUM* bn, size_t size) {
188
- std::vector<uint8_t> buf(size);
189
- CHECK_EQ(BN_bn2binpad(bn, buf.data(), size), size);
190
- ByteSource::Builder out(size);
191
- memcpy(out.data<void>(), buf.data(), size);
192
- return std::move(out).release();
193
- }
194
-
195
- ByteSource GetByteSourceFromJS(jsi::Runtime &rt,
196
- const jsi::Value &value,
197
- std::string name) {
198
- if (!value.isObject() || !value.asObject(rt).isArrayBuffer(rt)) {
199
- throw jsi::JSError(rt, "arg is not an array buffer: " + name);
200
- }
201
- ByteSource data = ByteSource::FromStringOrBuffer(rt, value);
202
- if (data.size() > INT_MAX) {
203
- throw jsi::JSError(rt, "arg is too big (> int32): " + name);
204
- }
205
- return data;
206
- }
207
-
208
- std::string EncodeBignum(const BIGNUM* bn,
209
- size_t size,
210
- bool url) {
211
- if (size == 0)
212
- size = BN_num_bytes(bn);
213
- std::vector<uint8_t> buf(size);
214
- CHECK_EQ(BN_bn2binpad(bn, buf.data(), size), size);
215
- std::string data(buf.begin(), buf.end());
216
- return EncodeBase64(data, url);
217
- }
218
-
219
- // loosely based on Node src/string_bytes.cc - StringBytes::Write()
220
- std::string StringBytesWrite(jsi::Runtime &rt,
221
- const std::string val,
222
- enum encoding encoding) {
223
- std::string result;
224
-
225
- switch (encoding) {
226
- case BASE64:
227
- // fallthrough
228
- case BASE64URL:
229
- result = DecodeBase64(val);
230
- break;
231
- default:
232
- throw jsi::JSError(rt, "Encoding not supported");
233
- }
234
-
235
- return result;
236
- }
237
-
238
- std::string EncodeBase64(const std::string data, bool url) {
239
- return base64_encode(data, url);
240
- }
241
-
242
- std::string DecodeBase64(const std::string &in, bool remove_linebreaks) {
243
- return base64_decode(in, remove_linebreaks);
244
- }
245
-
246
- MUST_USE_RESULT CSPRNGResult CSPRNG(void* buffer, size_t length) {
247
- unsigned char* buf = static_cast<unsigned char*>(buffer);
248
- do {
249
- if (1 == RAND_status()) {
250
- #if OPENSSL_VERSION_MAJOR >= 3
251
- if (1 == RAND_bytes_ex(nullptr, buf, length, 0)) return {true};
252
- #else
253
- while (length > INT_MAX && 1 == RAND_bytes(buf, INT_MAX)) {
254
- buf += INT_MAX;
255
- length -= INT_MAX;
256
- }
257
- if (length <= INT_MAX && 1 == RAND_bytes(buf, static_cast<int>(length)))
258
- return {true};
259
- #endif
260
- }
261
- #if OPENSSL_VERSION_MAJOR >= 3
262
- const auto code = ERR_peek_last_error();
263
- // A misconfigured OpenSSL 3 installation may report 1 from RAND_poll()
264
- // and RAND_status() but fail in RAND_bytes() if it cannot look up
265
- // a matching algorithm for the CSPRNG.
266
- if (ERR_GET_LIB(code) == ERR_LIB_RAND) {
267
- const auto reason = ERR_GET_REASON(code);
268
- if (reason == RAND_R_ERROR_INSTANTIATING_DRBG ||
269
- reason == RAND_R_UNABLE_TO_FETCH_DRBG ||
270
- reason == RAND_R_UNABLE_TO_CREATE_DRBG) {
271
- return {false};
272
- }
273
- }
274
- #endif
275
- } while (1 == RAND_poll());
276
-
277
- return {false};
278
- }
279
-
280
- bool SetRsaOaepLabel(const EVPKeyCtxPointer& ctx, const ByteSource& label) {
281
- if (label.size() != 0) {
282
- // OpenSSL takes ownership of the label, so we need to create a copy.
283
- void* label_copy = OPENSSL_memdup(label.data(), label.size());
284
- CHECK_NOT_NULL(label_copy);
285
- int ret = EVP_PKEY_CTX_set0_rsa_oaep_label(
286
- ctx.get(), static_cast<unsigned char*>(label_copy), label.size());
287
- if (ret <= 0) {
288
- OPENSSL_free(label_copy);
289
- return false;
290
- }
291
- }
292
- return true;
293
- }
294
-
295
- } // namespace margelo