react-native-quick-crypto 0.7.3 → 1.0.0-beta.2
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.
- package/QuickCrypto.podspec +34 -0
- package/README.md +13 -46
- package/android/CMakeLists.txt +32 -64
- package/android/build.gradle +52 -125
- package/android/gradle.properties +4 -4
- package/android/src/main/cpp/cpp-adapter.cpp +9 -54
- package/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.java +38 -0
- package/cpp/random/HybridRandom.cpp +34 -0
- package/cpp/random/HybridRandom.hpp +44 -0
- package/cpp/utils/Utils.hpp +9 -0
- package/ios/QuickCryptoOnLoad.mm +19 -0
- package/lib/commonjs/index.js +39 -39
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/random.js +26 -12
- package/lib/commonjs/random.js.map +1 -1
- package/lib/commonjs/{NativeQuickCrypto/rsa.js → specs/random.nitro.js} +1 -1
- package/lib/commonjs/{NativeQuickCrypto/aes.js.map → specs/random.nitro.js.map} +1 -1
- package/lib/commonjs/utils/conversion.js +22 -0
- package/lib/commonjs/utils/conversion.js.map +1 -0
- package/lib/commonjs/utils/index.js +12 -0
- package/lib/commonjs/utils/index.js.map +1 -0
- package/lib/commonjs/utils/types.js +2 -0
- package/lib/{module/NativeQuickCrypto/aes.js.map → commonjs/utils/types.js.map} +1 -1
- package/lib/module/index.js +38 -38
- package/lib/module/index.js.map +1 -1
- package/lib/module/random.js +26 -12
- package/lib/module/random.js.map +1 -1
- package/lib/module/specs/random.nitro.js +4 -0
- package/lib/module/{NativeQuickCrypto/rsa.js.map → specs/random.nitro.js.map} +1 -1
- package/lib/module/utils/conversion.js +16 -0
- package/lib/module/utils/conversion.js.map +1 -0
- package/lib/module/utils/index.js +8 -0
- package/lib/module/utils/index.js.map +1 -0
- package/lib/module/utils/types.js +2 -0
- package/lib/{commonjs/NativeQuickCrypto/rsa.js.map → module/utils/types.js.map} +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/typescript/index.d.ts +10 -141
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/random.d.ts +4 -5
- package/lib/typescript/random.d.ts.map +1 -1
- package/lib/typescript/specs/random.nitro.d.ts +9 -0
- package/lib/typescript/specs/random.nitro.d.ts.map +1 -0
- package/lib/typescript/utils/conversion.d.ts +4 -0
- package/lib/typescript/utils/conversion.d.ts.map +1 -0
- package/lib/typescript/utils/index.d.ts +6 -0
- package/lib/typescript/utils/index.d.ts.map +1 -0
- package/lib/typescript/utils/types.d.ts +5 -0
- package/lib/typescript/utils/types.d.ts.map +1 -0
- package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +45 -0
- package/nitrogen/generated/android/QuickCrypto+autolinking.gradle +26 -0
- package/nitrogen/generated/ios/QuickCrypto+autolinking.rb +57 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp +9 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp +25 -0
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp +29 -0
- package/nitrogen/generated/shared/c++/HybridRandomSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridRandomSpec.hpp +62 -0
- package/package.json +50 -106
- package/src/index.ts +38 -48
- package/src/random.ts +51 -48
- package/src/specs/random.nitro.ts +14 -0
- package/src/utils/conversion.ts +16 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/types.ts +15 -0
- package/LICENSE +0 -27
- package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoModule.java +0 -70
- package/android/src/main/java/com/margelo/quickcrypto/QuickCryptoPackage.java +0 -25
- package/cpp/Cipher/MGLCipherHostObject.cpp +0 -663
- package/cpp/Cipher/MGLCipherHostObject.h +0 -90
- package/cpp/Cipher/MGLCreateCipherInstaller.cpp +0 -75
- package/cpp/Cipher/MGLCreateCipherInstaller.h +0 -22
- package/cpp/Cipher/MGLCreateDecipherInstaller.cpp +0 -77
- package/cpp/Cipher/MGLCreateDecipherInstaller.h +0 -17
- package/cpp/Cipher/MGLGenerateKeyPairInstaller.cpp +0 -134
- package/cpp/Cipher/MGLGenerateKeyPairInstaller.h +0 -35
- package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.cpp +0 -63
- package/cpp/Cipher/MGLGenerateKeyPairSyncInstaller.h +0 -37
- package/cpp/Cipher/MGLPublicCipher.h +0 -124
- package/cpp/Cipher/MGLPublicCipherInstaller.h +0 -107
- package/cpp/Cipher/MGLRsa.cpp +0 -573
- package/cpp/Cipher/MGLRsa.h +0 -109
- package/cpp/HMAC/MGLHmacHostObject.cpp +0 -95
- package/cpp/HMAC/MGLHmacHostObject.h +0 -39
- package/cpp/HMAC/MGLHmacInstaller.cpp +0 -43
- package/cpp/HMAC/MGLHmacInstaller.h +0 -20
- package/cpp/Hash/MGLHashHostObject.cpp +0 -147
- package/cpp/Hash/MGLHashHostObject.h +0 -53
- package/cpp/Hash/MGLHashInstaller.cpp +0 -44
- package/cpp/Hash/MGLHashInstaller.h +0 -20
- package/cpp/JSIUtils/MGLJSIMacros.h +0 -110
- package/cpp/JSIUtils/MGLJSIUtils.h +0 -41
- package/cpp/JSIUtils/MGLSmartHostObject.cpp +0 -43
- package/cpp/JSIUtils/MGLSmartHostObject.h +0 -46
- package/cpp/JSIUtils/MGLThreadAwareHostObject.cpp +0 -24
- package/cpp/JSIUtils/MGLThreadAwareHostObject.h +0 -43
- package/cpp/JSIUtils/MGLTypedArray.cpp +0 -325
- package/cpp/JSIUtils/MGLTypedArray.h +0 -160
- package/cpp/MGLKeys.cpp +0 -1426
- package/cpp/MGLKeys.h +0 -203
- package/cpp/MGLQuickCryptoHostObject.cpp +0 -127
- package/cpp/MGLQuickCryptoHostObject.h +0 -30
- package/cpp/Random/MGLRandomHostObject.cpp +0 -96
- package/cpp/Random/MGLRandomHostObject.h +0 -27
- package/cpp/Sig/MGLSignHostObjects.cpp +0 -757
- package/cpp/Sig/MGLSignHostObjects.h +0 -128
- package/cpp/Sig/MGLSignInstaller.cpp +0 -24
- package/cpp/Sig/MGLSignInstaller.h +0 -29
- package/cpp/Sig/MGLVerifyInstaller.cpp +0 -24
- package/cpp/Sig/MGLVerifyInstaller.h +0 -22
- package/cpp/Utils/MGLDispatchQueue.cpp +0 -75
- package/cpp/Utils/MGLDispatchQueue.h +0 -55
- package/cpp/Utils/MGLUtils.cpp +0 -295
- package/cpp/Utils/MGLUtils.h +0 -358
- package/cpp/Utils/base64.h +0 -320
- package/cpp/Utils/logs.h +0 -38
- package/cpp/Utils/node.h +0 -13
- package/cpp/fastpbkdf2/MGLPbkdf2HostObject.cpp +0 -164
- package/cpp/fastpbkdf2/MGLPbkdf2HostObject.h +0 -29
- package/cpp/fastpbkdf2/fastpbkdf2.c +0 -352
- package/cpp/fastpbkdf2/fastpbkdf2.h +0 -68
- package/cpp/webcrypto/MGLWebCrypto.cpp +0 -125
- package/cpp/webcrypto/MGLWebCrypto.h +0 -32
- package/cpp/webcrypto/crypto_aes.cpp +0 -516
- package/cpp/webcrypto/crypto_aes.h +0 -79
- package/cpp/webcrypto/crypto_ec.cpp +0 -424
- package/cpp/webcrypto/crypto_ec.h +0 -78
- package/cpp/webcrypto/crypto_keygen.cpp +0 -86
- package/cpp/webcrypto/crypto_keygen.h +0 -38
- package/ios/QuickCrypto.xcodeproj/project.pbxproj +0 -274
- package/ios/QuickCryptoModule.h +0 -5
- package/ios/QuickCryptoModule.mm +0 -42
- package/lib/commonjs/Cipher.js +0 -502
- package/lib/commonjs/Cipher.js.map +0 -1
- package/lib/commonjs/Hash.js +0 -99
- package/lib/commonjs/Hash.js.map +0 -1
- package/lib/commonjs/Hashnames.js +0 -87
- package/lib/commonjs/Hashnames.js.map +0 -1
- package/lib/commonjs/Hmac.js +0 -79
- package/lib/commonjs/Hmac.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/Cipher.js +0 -30
- package/lib/commonjs/NativeQuickCrypto/Cipher.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js +0 -52
- package/lib/commonjs/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/aes.js +0 -6
- package/lib/commonjs/NativeQuickCrypto/hash.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/hash.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/hmac.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/hmac.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/keygen.js +0 -6
- package/lib/commonjs/NativeQuickCrypto/keygen.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/pbkdf2.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/pbkdf2.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/random.js +0 -2
- package/lib/commonjs/NativeQuickCrypto/random.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/sig.js +0 -19
- package/lib/commonjs/NativeQuickCrypto/sig.js.map +0 -1
- package/lib/commonjs/NativeQuickCrypto/webcrypto.js +0 -6
- package/lib/commonjs/NativeQuickCrypto/webcrypto.js.map +0 -1
- package/lib/commonjs/Utils.js +0 -608
- package/lib/commonjs/Utils.js.map +0 -1
- package/lib/commonjs/aes.js +0 -281
- package/lib/commonjs/aes.js.map +0 -1
- package/lib/commonjs/constants.js +0 -85
- package/lib/commonjs/constants.js.map +0 -1
- package/lib/commonjs/ec.js +0 -276
- package/lib/commonjs/ec.js.map +0 -1
- package/lib/commonjs/keygen.js +0 -56
- package/lib/commonjs/keygen.js.map +0 -1
- package/lib/commonjs/keys.js +0 -492
- package/lib/commonjs/keys.js.map +0 -1
- package/lib/commonjs/pbkdf2.js +0 -90
- package/lib/commonjs/pbkdf2.js.map +0 -1
- package/lib/commonjs/rsa.js +0 -248
- package/lib/commonjs/rsa.js.map +0 -1
- package/lib/commonjs/sig.js +0 -129
- package/lib/commonjs/sig.js.map +0 -1
- package/lib/commonjs/subtle.js +0 -448
- package/lib/commonjs/subtle.js.map +0 -1
- package/lib/commonjs/webcrypto.js +0 -14
- package/lib/commonjs/webcrypto.js.map +0 -1
- package/lib/module/Cipher.js +0 -491
- package/lib/module/Cipher.js.map +0 -1
- package/lib/module/Hash.js +0 -93
- package/lib/module/Hash.js.map +0 -1
- package/lib/module/Hashnames.js +0 -85
- package/lib/module/Hashnames.js.map +0 -1
- package/lib/module/Hmac.js +0 -74
- package/lib/module/Hmac.js.map +0 -1
- package/lib/module/NativeQuickCrypto/Cipher.js +0 -26
- package/lib/module/NativeQuickCrypto/Cipher.js.map +0 -1
- package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js +0 -49
- package/lib/module/NativeQuickCrypto/NativeQuickCrypto.js.map +0 -1
- package/lib/module/NativeQuickCrypto/aes.js +0 -4
- package/lib/module/NativeQuickCrypto/hash.js +0 -2
- package/lib/module/NativeQuickCrypto/hash.js.map +0 -1
- package/lib/module/NativeQuickCrypto/hmac.js +0 -2
- package/lib/module/NativeQuickCrypto/hmac.js.map +0 -1
- package/lib/module/NativeQuickCrypto/keygen.js +0 -4
- package/lib/module/NativeQuickCrypto/keygen.js.map +0 -1
- package/lib/module/NativeQuickCrypto/pbkdf2.js +0 -2
- package/lib/module/NativeQuickCrypto/pbkdf2.js.map +0 -1
- package/lib/module/NativeQuickCrypto/random.js +0 -2
- package/lib/module/NativeQuickCrypto/random.js.map +0 -1
- package/lib/module/NativeQuickCrypto/rsa.js +0 -4
- package/lib/module/NativeQuickCrypto/sig.js +0 -17
- package/lib/module/NativeQuickCrypto/sig.js.map +0 -1
- package/lib/module/NativeQuickCrypto/webcrypto.js +0 -4
- package/lib/module/NativeQuickCrypto/webcrypto.js.map +0 -1
- package/lib/module/Utils.js +0 -539
- package/lib/module/Utils.js.map +0 -1
- package/lib/module/aes.js +0 -274
- package/lib/module/aes.js.map +0 -1
- package/lib/module/constants.js +0 -81
- package/lib/module/constants.js.map +0 -1
- package/lib/module/ec.js +0 -267
- package/lib/module/ec.js.map +0 -1
- package/lib/module/keygen.js +0 -49
- package/lib/module/keygen.js.map +0 -1
- package/lib/module/keys.js +0 -477
- package/lib/module/keys.js.map +0 -1
- package/lib/module/pbkdf2.js +0 -84
- package/lib/module/pbkdf2.js.map +0 -1
- package/lib/module/rsa.js +0 -242
- package/lib/module/rsa.js.map +0 -1
- package/lib/module/sig.js +0 -124
- package/lib/module/sig.js.map +0 -1
- package/lib/module/subtle.js +0 -443
- package/lib/module/subtle.js.map +0 -1
- package/lib/module/webcrypto.js +0 -10
- package/lib/module/webcrypto.js.map +0 -1
- package/lib/typescript/Cipher.d.ts +0 -81
- package/lib/typescript/Cipher.d.ts.map +0 -1
- package/lib/typescript/Hash.d.ts +0 -44
- package/lib/typescript/Hash.d.ts.map +0 -1
- package/lib/typescript/Hashnames.d.ts +0 -11
- package/lib/typescript/Hashnames.d.ts.map +0 -1
- package/lib/typescript/Hmac.d.ts +0 -37
- package/lib/typescript/Hmac.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/Cipher.d.ts +0 -44
- package/lib/typescript/NativeQuickCrypto/Cipher.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts +0 -33
- package/lib/typescript/NativeQuickCrypto/NativeQuickCrypto.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/aes.d.ts +0 -5
- package/lib/typescript/NativeQuickCrypto/aes.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/hash.d.ts +0 -7
- package/lib/typescript/NativeQuickCrypto/hash.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/hmac.d.ts +0 -6
- package/lib/typescript/NativeQuickCrypto/hmac.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/keygen.d.ts +0 -4
- package/lib/typescript/NativeQuickCrypto/keygen.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts +0 -5
- package/lib/typescript/NativeQuickCrypto/pbkdf2.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/random.d.ts +0 -5
- package/lib/typescript/NativeQuickCrypto/random.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/rsa.d.ts +0 -5
- package/lib/typescript/NativeQuickCrypto/rsa.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/sig.d.ts +0 -23
- package/lib/typescript/NativeQuickCrypto/sig.d.ts.map +0 -1
- package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts +0 -39
- package/lib/typescript/NativeQuickCrypto/webcrypto.d.ts.map +0 -1
- package/lib/typescript/Utils.d.ts +0 -48
- package/lib/typescript/Utils.d.ts.map +0 -1
- package/lib/typescript/aes.d.ts +0 -22
- package/lib/typescript/aes.d.ts.map +0 -1
- package/lib/typescript/constants.d.ts +0 -76
- package/lib/typescript/constants.d.ts.map +0 -1
- package/lib/typescript/ec.d.ts +0 -7
- package/lib/typescript/ec.d.ts.map +0 -1
- package/lib/typescript/keygen.d.ts +0 -6
- package/lib/typescript/keygen.d.ts.map +0 -1
- package/lib/typescript/keys.d.ts +0 -206
- package/lib/typescript/keys.d.ts.map +0 -1
- package/lib/typescript/pbkdf2.d.ts +0 -12
- package/lib/typescript/pbkdf2.d.ts.map +0 -1
- package/lib/typescript/rsa.d.ts +0 -12
- package/lib/typescript/rsa.d.ts.map +0 -1
- package/lib/typescript/sig.d.ts +0 -21
- package/lib/typescript/sig.d.ts.map +0 -1
- package/lib/typescript/subtle.d.ts +0 -15
- package/lib/typescript/subtle.d.ts.map +0 -1
- package/lib/typescript/webcrypto.d.ts +0 -9
- package/lib/typescript/webcrypto.d.ts.map +0 -1
- package/react-native-quick-crypto.podspec +0 -40
- package/src/Cipher.ts +0 -832
- package/src/Hash.ts +0 -132
- package/src/Hashnames.ts +0 -93
- package/src/Hmac.ts +0 -106
- package/src/NativeQuickCrypto/Cipher.ts +0 -102
- package/src/NativeQuickCrypto/NativeQuickCrypto.ts +0 -102
- package/src/NativeQuickCrypto/aes.ts +0 -14
- package/src/NativeQuickCrypto/hash.ts +0 -10
- package/src/NativeQuickCrypto/hmac.ts +0 -9
- package/src/NativeQuickCrypto/keygen.ts +0 -7
- package/src/NativeQuickCrypto/pbkdf2.ts +0 -16
- package/src/NativeQuickCrypto/random.ts +0 -12
- package/src/NativeQuickCrypto/rsa.ts +0 -12
- package/src/NativeQuickCrypto/sig.ts +0 -44
- package/src/NativeQuickCrypto/webcrypto.ts +0 -72
- package/src/Utils.ts +0 -777
- package/src/aes.ts +0 -402
- package/src/constants.ts +0 -79
- package/src/ec.ts +0 -375
- package/src/keygen.ts +0 -80
- package/src/keys.ts +0 -787
- package/src/pbkdf2.ts +0 -169
- package/src/rsa.ts +0 -370
- package/src/sig.ts +0 -164
- package/src/subtle.ts +0 -639
- package/src/webcrypto.ts +0 -8
- /package/android/src/main/{AndroidManifestNew.xml → AndroidManifest.xml} +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 ¶ms, ByteSource &out);
|
|
109
|
-
jsi::Value EncodeOutput(jsi::Runtime &rt,const SignConfiguration ¶ms, 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
|
package/cpp/Utils/MGLUtils.cpp
DELETED
|
@@ -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
|