react-native-quick-crypto 1.0.0-beta.3 → 1.0.0-beta.5
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 +4 -0
- package/README.md +2 -0
- package/android/CMakeLists.txt +26 -13
- package/android/build.gradle +4 -0
- package/android/src/main/cpp/cpp-adapter.cpp +3 -10
- package/android/src/main/java/com/margelo/nitro/quickcrypto/QuickCryptoPackage.java +15 -10
- package/cpp/pbkdf2/HybridPbkdf2.cpp +71 -0
- package/cpp/pbkdf2/HybridPbkdf2.hpp +35 -0
- package/cpp/random/HybridRandom.cpp +42 -18
- package/cpp/random/HybridRandom.hpp +13 -28
- package/cpp/utils/Utils.hpp +12 -1
- package/deps/fastpbkdf2/fastpbkdf2.c +352 -0
- package/deps/fastpbkdf2/fastpbkdf2.h +68 -0
- package/lib/commonjs/index.js +24 -5
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/keys/index.js +86 -0
- package/lib/commonjs/keys/index.js.map +1 -0
- package/lib/commonjs/pbkdf2.js +89 -0
- package/lib/commonjs/pbkdf2.js.map +1 -0
- package/lib/commonjs/random.js +3 -3
- package/lib/commonjs/random.js.map +1 -1
- package/lib/commonjs/specs/keyObjectHandle.nitro.js +6 -0
- package/lib/commonjs/specs/keyObjectHandle.nitro.js.map +1 -0
- package/lib/commonjs/specs/pbkdf2.nitro.js +6 -0
- package/lib/commonjs/specs/pbkdf2.nitro.js.map +1 -0
- package/lib/commonjs/utils/conversion.js +74 -0
- package/lib/commonjs/utils/conversion.js.map +1 -1
- package/lib/commonjs/utils/errors.js +14 -0
- package/lib/commonjs/utils/errors.js.map +1 -0
- package/lib/commonjs/utils/hashnames.js +90 -0
- package/lib/commonjs/utils/hashnames.js.map +1 -0
- package/lib/commonjs/utils/index.js +43 -5
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/types.js +27 -0
- package/lib/commonjs/utils/types.js.map +1 -1
- package/lib/module/index.js +9 -4
- package/lib/module/index.js.map +1 -1
- package/lib/module/keys/index.js +81 -0
- package/lib/module/keys/index.js.map +1 -0
- package/lib/module/pbkdf2.js +83 -0
- package/lib/module/pbkdf2.js.map +1 -0
- package/lib/module/random.js +1 -1
- package/lib/module/random.js.map +1 -1
- package/lib/module/specs/keyObjectHandle.nitro.js +4 -0
- package/lib/module/specs/keyObjectHandle.nitro.js.map +1 -0
- package/lib/module/specs/pbkdf2.nitro.js +4 -0
- package/lib/module/specs/pbkdf2.nitro.js.map +1 -0
- package/lib/module/utils/conversion.js +71 -0
- package/lib/module/utils/conversion.js.map +1 -1
- package/lib/module/utils/errors.js +10 -0
- package/lib/module/utils/errors.js.map +1 -0
- package/lib/module/utils/hashnames.js +88 -0
- package/lib/module/utils/hashnames.js.map +1 -0
- package/lib/module/utils/index.js +4 -5
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/types.js +26 -0
- package/lib/module/utils/types.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/typescript/index.d.ts +26 -9
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/keys/index.d.ts +22 -0
- package/lib/typescript/keys/index.d.ts.map +1 -0
- package/lib/typescript/pbkdf2.d.ts +12 -0
- package/lib/typescript/pbkdf2.d.ts.map +1 -0
- package/lib/typescript/random.d.ts +1 -1
- package/lib/typescript/random.d.ts.map +1 -1
- package/lib/typescript/specs/keyObjectHandle.nitro.d.ts +15 -0
- package/lib/typescript/specs/keyObjectHandle.nitro.d.ts.map +1 -0
- package/lib/typescript/specs/pbkdf2.nitro.d.ts +9 -0
- package/lib/typescript/specs/pbkdf2.nitro.d.ts.map +1 -0
- package/lib/typescript/utils/conversion.d.ts +7 -1
- package/lib/typescript/utils/conversion.d.ts.map +1 -1
- package/lib/typescript/utils/errors.d.ts +7 -0
- package/lib/typescript/utils/errors.d.ts.map +1 -0
- package/lib/typescript/utils/hashnames.d.ts +11 -0
- package/lib/typescript/utils/hashnames.d.ts.map +1 -0
- package/lib/typescript/utils/index.d.ts +4 -5
- package/lib/typescript/utils/index.d.ts.map +1 -1
- package/lib/typescript/utils/types.d.ts +101 -0
- package/lib/typescript/utils/types.d.ts.map +1 -1
- package/nitrogen/generated/android/QuickCrypto+autolinking.cmake +19 -3
- package/nitrogen/generated/android/QuickCrypto+autolinking.gradle +1 -2
- package/nitrogen/generated/android/QuickCryptoOnLoad.cpp +50 -0
- package/nitrogen/generated/android/QuickCryptoOnLoad.hpp +25 -0
- package/nitrogen/generated/android/QuickCryptoOnLoad.kt +1 -0
- package/nitrogen/generated/ios/QuickCrypto+autolinking.rb +7 -6
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp +10 -2
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp +4 -2
- package/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp +12 -6
- package/nitrogen/generated/ios/QuickCryptoAutolinking.mm +45 -0
- package/nitrogen/generated/ios/QuickCryptoAutolinking.swift +12 -0
- package/nitrogen/generated/shared/c++/AsymmetricKeyType.hpp +86 -0
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.cpp +27 -0
- package/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.hpp +93 -0
- package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.cpp +22 -0
- package/nitrogen/generated/shared/c++/HybridPbkdf2Spec.hpp +66 -0
- package/nitrogen/generated/shared/c++/HybridRandomSpec.cpp +1 -2
- package/nitrogen/generated/shared/c++/HybridRandomSpec.hpp +7 -4
- package/nitrogen/generated/shared/c++/JWK.hpp +162 -0
- package/nitrogen/generated/shared/c++/JWKkty.hpp +86 -0
- package/nitrogen/generated/shared/c++/JWKuse.hpp +78 -0
- package/nitrogen/generated/shared/c++/KFormatType.hpp +65 -0
- package/nitrogen/generated/shared/c++/KeyDetail.hpp +93 -0
- package/nitrogen/generated/shared/c++/KeyEncoding.hpp +66 -0
- package/nitrogen/generated/shared/c++/KeyType.hpp +65 -0
- package/nitrogen/generated/shared/c++/KeyUsage.hpp +102 -0
- package/nitrogen/generated/shared/c++/NamedCurve.hpp +82 -0
- package/package.json +13 -12
- package/src/index.ts +8 -4
- package/src/keys/index.ts +99 -0
- package/src/pbkdf2.ts +154 -0
- package/src/random.ts +14 -14
- package/src/specs/keyObjectHandle.nitro.ts +32 -0
- package/src/specs/pbkdf2.nitro.ts +18 -0
- package/src/specs/random.nitro.ts +2 -2
- package/src/utils/conversion.ts +83 -1
- package/src/utils/errors.ts +15 -0
- package/src/utils/hashnames.ts +96 -0
- package/src/utils/index.ts +4 -6
- package/src/utils/types.ts +178 -2
- package/ios/QuickCryptoOnLoad.mm +0 -19
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridKeyObjectHandleSpec.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2024 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
// Forward declaration of `ArrayBuffer` to properly resolve imports.
|
|
17
|
+
namespace NitroModules { class ArrayBuffer; }
|
|
18
|
+
// Forward declaration of `KFormatType` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::crypto { enum class KFormatType; }
|
|
20
|
+
// Forward declaration of `KeyEncoding` to properly resolve imports.
|
|
21
|
+
namespace margelo::nitro::crypto { enum class KeyEncoding; }
|
|
22
|
+
// Forward declaration of `JWK` to properly resolve imports.
|
|
23
|
+
namespace margelo::nitro::crypto { struct JWK; }
|
|
24
|
+
// Forward declaration of `AsymmetricKeyType` to properly resolve imports.
|
|
25
|
+
namespace margelo::nitro::crypto { enum class AsymmetricKeyType; }
|
|
26
|
+
// Forward declaration of `KeyType` to properly resolve imports.
|
|
27
|
+
namespace margelo::nitro::crypto { enum class KeyType; }
|
|
28
|
+
// Forward declaration of `NamedCurve` to properly resolve imports.
|
|
29
|
+
namespace margelo::nitro::crypto { enum class NamedCurve; }
|
|
30
|
+
// Forward declaration of `KeyDetail` to properly resolve imports.
|
|
31
|
+
namespace margelo::nitro::crypto { struct KeyDetail; }
|
|
32
|
+
|
|
33
|
+
#include <NitroModules/ArrayBuffer.hpp>
|
|
34
|
+
#include <optional>
|
|
35
|
+
#include "KFormatType.hpp"
|
|
36
|
+
#include "KeyEncoding.hpp"
|
|
37
|
+
#include <string>
|
|
38
|
+
#include "JWK.hpp"
|
|
39
|
+
#include "AsymmetricKeyType.hpp"
|
|
40
|
+
#include "KeyType.hpp"
|
|
41
|
+
#include <variant>
|
|
42
|
+
#include "NamedCurve.hpp"
|
|
43
|
+
#include "KeyDetail.hpp"
|
|
44
|
+
|
|
45
|
+
namespace margelo::nitro::crypto {
|
|
46
|
+
|
|
47
|
+
using namespace margelo::nitro;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* An abstract base class for `KeyObjectHandle`
|
|
51
|
+
* Inherit this class to create instances of `HybridKeyObjectHandleSpec` in C++.
|
|
52
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
53
|
+
* @example
|
|
54
|
+
* ```cpp
|
|
55
|
+
* class HybridKeyObjectHandle: public HybridKeyObjectHandleSpec {
|
|
56
|
+
* public:
|
|
57
|
+
* HybridKeyObjectHandle(...): HybridObject(TAG) { ... }
|
|
58
|
+
* // ...
|
|
59
|
+
* };
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
class HybridKeyObjectHandleSpec: public virtual HybridObject {
|
|
63
|
+
public:
|
|
64
|
+
// Constructor
|
|
65
|
+
explicit HybridKeyObjectHandleSpec(): HybridObject(TAG) { }
|
|
66
|
+
|
|
67
|
+
// Destructor
|
|
68
|
+
virtual ~HybridKeyObjectHandleSpec() { }
|
|
69
|
+
|
|
70
|
+
public:
|
|
71
|
+
// Properties
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
public:
|
|
75
|
+
// Methods
|
|
76
|
+
virtual std::shared_ptr<ArrayBuffer> exportKey(std::optional<KFormatType> format, std::optional<KeyEncoding> type, const std::optional<std::string>& cipher, const std::optional<std::shared_ptr<ArrayBuffer>>& passphrase) = 0;
|
|
77
|
+
virtual JWK exportJwk(const JWK& key, bool handleRsaPss) = 0;
|
|
78
|
+
virtual AsymmetricKeyType getAsymmetricKeyType() = 0;
|
|
79
|
+
virtual bool init(KeyType keyType, const std::variant<std::string, std::shared_ptr<ArrayBuffer>>& key, std::optional<KFormatType> format, std::optional<KeyEncoding> type, const std::optional<std::shared_ptr<ArrayBuffer>>& passphrase) = 0;
|
|
80
|
+
virtual bool initECRaw(const std::string& curveName, const std::shared_ptr<ArrayBuffer>& keyData) = 0;
|
|
81
|
+
virtual std::optional<KeyType> initJwk(const JWK& keyData, std::optional<NamedCurve> namedCurve) = 0;
|
|
82
|
+
virtual KeyDetail keyDetail() = 0;
|
|
83
|
+
|
|
84
|
+
protected:
|
|
85
|
+
// Hybrid Setup
|
|
86
|
+
void loadHybridMethods() override;
|
|
87
|
+
|
|
88
|
+
protected:
|
|
89
|
+
// Tag for logging
|
|
90
|
+
static constexpr auto TAG = "KeyObjectHandle";
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
} // namespace margelo::nitro::crypto
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridPbkdf2Spec.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2024 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include "HybridPbkdf2Spec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::crypto {
|
|
11
|
+
|
|
12
|
+
void HybridPbkdf2Spec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridMethod("pbkdf2", &HybridPbkdf2Spec::pbkdf2);
|
|
18
|
+
prototype.registerHybridMethod("pbkdf2Sync", &HybridPbkdf2Spec::pbkdf2Sync);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
} // namespace margelo::nitro::crypto
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridPbkdf2Spec.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2024 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
// Forward declaration of `ArrayBuffer` to properly resolve imports.
|
|
17
|
+
namespace NitroModules { class ArrayBuffer; }
|
|
18
|
+
|
|
19
|
+
#include <future>
|
|
20
|
+
#include <NitroModules/ArrayBuffer.hpp>
|
|
21
|
+
#include <string>
|
|
22
|
+
|
|
23
|
+
namespace margelo::nitro::crypto {
|
|
24
|
+
|
|
25
|
+
using namespace margelo::nitro;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* An abstract base class for `Pbkdf2`
|
|
29
|
+
* Inherit this class to create instances of `HybridPbkdf2Spec` in C++.
|
|
30
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
31
|
+
* @example
|
|
32
|
+
* ```cpp
|
|
33
|
+
* class HybridPbkdf2: public HybridPbkdf2Spec {
|
|
34
|
+
* public:
|
|
35
|
+
* HybridPbkdf2(...): HybridObject(TAG) { ... }
|
|
36
|
+
* // ...
|
|
37
|
+
* };
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
class HybridPbkdf2Spec: public virtual HybridObject {
|
|
41
|
+
public:
|
|
42
|
+
// Constructor
|
|
43
|
+
explicit HybridPbkdf2Spec(): HybridObject(TAG) { }
|
|
44
|
+
|
|
45
|
+
// Destructor
|
|
46
|
+
virtual ~HybridPbkdf2Spec() { }
|
|
47
|
+
|
|
48
|
+
public:
|
|
49
|
+
// Properties
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
public:
|
|
53
|
+
// Methods
|
|
54
|
+
virtual std::future<std::shared_ptr<ArrayBuffer>> pbkdf2(const std::shared_ptr<ArrayBuffer>& password, const std::shared_ptr<ArrayBuffer>& salt, double iterations, double keylen, const std::string& digest) = 0;
|
|
55
|
+
virtual std::shared_ptr<ArrayBuffer> pbkdf2Sync(const std::shared_ptr<ArrayBuffer>& password, const std::shared_ptr<ArrayBuffer>& salt, double iterations, double keylen, const std::string& digest) = 0;
|
|
56
|
+
|
|
57
|
+
protected:
|
|
58
|
+
// Hybrid Setup
|
|
59
|
+
void loadHybridMethods() override;
|
|
60
|
+
|
|
61
|
+
protected:
|
|
62
|
+
// Tag for logging
|
|
63
|
+
static constexpr auto TAG = "Pbkdf2";
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
} // namespace margelo::nitro::crypto
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
///
|
|
2
2
|
/// HybridRandomSpec.cpp
|
|
3
|
-
/// Tue Aug 13 2024
|
|
4
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
5
|
-
/// https://github.com/mrousavy/
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
6
5
|
/// Copyright © 2024 Marc Rousavy @ Margelo
|
|
7
6
|
///
|
|
8
7
|
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
///
|
|
2
2
|
/// HybridRandomSpec.hpp
|
|
3
|
-
/// Tue Aug 13 2024
|
|
4
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
5
|
-
/// https://github.com/mrousavy/
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
6
5
|
/// Copyright © 2024 Marc Rousavy @ Margelo
|
|
7
6
|
///
|
|
8
7
|
|
|
@@ -17,6 +16,7 @@
|
|
|
17
16
|
// Forward declaration of `ArrayBuffer` to properly resolve imports.
|
|
18
17
|
namespace NitroModules { class ArrayBuffer; }
|
|
19
18
|
|
|
19
|
+
#include <future>
|
|
20
20
|
#include <NitroModules/ArrayBuffer.hpp>
|
|
21
21
|
|
|
22
22
|
namespace margelo::nitro::crypto {
|
|
@@ -26,20 +26,23 @@ namespace margelo::nitro::crypto {
|
|
|
26
26
|
/**
|
|
27
27
|
* An abstract base class for `Random`
|
|
28
28
|
* Inherit this class to create instances of `HybridRandomSpec` in C++.
|
|
29
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
29
30
|
* @example
|
|
30
31
|
* ```cpp
|
|
31
32
|
* class HybridRandom: public HybridRandomSpec {
|
|
33
|
+
* public:
|
|
34
|
+
* HybridRandom(...): HybridObject(TAG) { ... }
|
|
32
35
|
* // ...
|
|
33
36
|
* };
|
|
34
37
|
* ```
|
|
35
38
|
*/
|
|
36
|
-
class HybridRandomSpec: public HybridObject {
|
|
39
|
+
class HybridRandomSpec: public virtual HybridObject {
|
|
37
40
|
public:
|
|
38
41
|
// Constructor
|
|
39
42
|
explicit HybridRandomSpec(): HybridObject(TAG) { }
|
|
40
43
|
|
|
41
44
|
// Destructor
|
|
42
|
-
~HybridRandomSpec() { }
|
|
45
|
+
virtual ~HybridRandomSpec() { }
|
|
43
46
|
|
|
44
47
|
public:
|
|
45
48
|
// Properties
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JWK.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2024 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
|
|
21
|
+
// Forward declaration of `JWKkty` to properly resolve imports.
|
|
22
|
+
namespace margelo::nitro::crypto { enum class JWKkty; }
|
|
23
|
+
// Forward declaration of `JWKuse` to properly resolve imports.
|
|
24
|
+
namespace margelo::nitro::crypto { enum class JWKuse; }
|
|
25
|
+
// Forward declaration of `KeyUsage` to properly resolve imports.
|
|
26
|
+
namespace margelo::nitro::crypto { enum class KeyUsage; }
|
|
27
|
+
|
|
28
|
+
#include <optional>
|
|
29
|
+
#include "JWKkty.hpp"
|
|
30
|
+
#include "JWKuse.hpp"
|
|
31
|
+
#include <vector>
|
|
32
|
+
#include "KeyUsage.hpp"
|
|
33
|
+
#include <string>
|
|
34
|
+
|
|
35
|
+
namespace margelo::nitro::crypto {
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A struct which can be represented as a JavaScript object (JWK).
|
|
39
|
+
*/
|
|
40
|
+
struct JWK {
|
|
41
|
+
public:
|
|
42
|
+
std::optional<JWKkty> kty SWIFT_PRIVATE;
|
|
43
|
+
std::optional<JWKuse> use SWIFT_PRIVATE;
|
|
44
|
+
std::optional<std::vector<KeyUsage>> key_ops SWIFT_PRIVATE;
|
|
45
|
+
std::optional<std::string> alg SWIFT_PRIVATE;
|
|
46
|
+
std::optional<std::string> crv SWIFT_PRIVATE;
|
|
47
|
+
std::optional<std::string> kid SWIFT_PRIVATE;
|
|
48
|
+
std::optional<std::string> x5u SWIFT_PRIVATE;
|
|
49
|
+
std::optional<std::vector<std::string>> x5c SWIFT_PRIVATE;
|
|
50
|
+
std::optional<std::string> x5t SWIFT_PRIVATE;
|
|
51
|
+
std::optional<std::string> x5t_256 SWIFT_PRIVATE;
|
|
52
|
+
std::optional<std::string> n SWIFT_PRIVATE;
|
|
53
|
+
std::optional<std::string> e SWIFT_PRIVATE;
|
|
54
|
+
std::optional<std::string> d SWIFT_PRIVATE;
|
|
55
|
+
std::optional<std::string> p SWIFT_PRIVATE;
|
|
56
|
+
std::optional<std::string> q SWIFT_PRIVATE;
|
|
57
|
+
std::optional<std::string> x SWIFT_PRIVATE;
|
|
58
|
+
std::optional<std::string> y SWIFT_PRIVATE;
|
|
59
|
+
std::optional<std::string> k SWIFT_PRIVATE;
|
|
60
|
+
std::optional<std::string> dp SWIFT_PRIVATE;
|
|
61
|
+
std::optional<std::string> dq SWIFT_PRIVATE;
|
|
62
|
+
std::optional<std::string> qi SWIFT_PRIVATE;
|
|
63
|
+
std::optional<bool> ext SWIFT_PRIVATE;
|
|
64
|
+
|
|
65
|
+
public:
|
|
66
|
+
explicit JWK(std::optional<JWKkty> kty, std::optional<JWKuse> use, std::optional<std::vector<KeyUsage>> key_ops, std::optional<std::string> alg, std::optional<std::string> crv, std::optional<std::string> kid, std::optional<std::string> x5u, std::optional<std::vector<std::string>> x5c, std::optional<std::string> x5t, std::optional<std::string> x5t_256, std::optional<std::string> n, std::optional<std::string> e, std::optional<std::string> d, std::optional<std::string> p, std::optional<std::string> q, std::optional<std::string> x, std::optional<std::string> y, std::optional<std::string> k, std::optional<std::string> dp, std::optional<std::string> dq, std::optional<std::string> qi, std::optional<bool> ext): kty(kty), use(use), key_ops(key_ops), alg(alg), crv(crv), kid(kid), x5u(x5u), x5c(x5c), x5t(x5t), x5t_256(x5t_256), n(n), e(e), d(d), p(p), q(q), x(x), y(y), k(k), dp(dp), dq(dq), qi(qi), ext(ext) {}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
} // namespace margelo::nitro::crypto
|
|
70
|
+
|
|
71
|
+
namespace margelo::nitro {
|
|
72
|
+
|
|
73
|
+
using namespace margelo::nitro::crypto;
|
|
74
|
+
|
|
75
|
+
// C++ JWK <> JS JWK (object)
|
|
76
|
+
template <>
|
|
77
|
+
struct JSIConverter<JWK> {
|
|
78
|
+
static inline JWK fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
79
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
80
|
+
return JWK(
|
|
81
|
+
JSIConverter<std::optional<JWKkty>>::fromJSI(runtime, obj.getProperty(runtime, "kty")),
|
|
82
|
+
JSIConverter<std::optional<JWKuse>>::fromJSI(runtime, obj.getProperty(runtime, "use")),
|
|
83
|
+
JSIConverter<std::optional<std::vector<KeyUsage>>>::fromJSI(runtime, obj.getProperty(runtime, "key_ops")),
|
|
84
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "alg")),
|
|
85
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "crv")),
|
|
86
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "kid")),
|
|
87
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "x5u")),
|
|
88
|
+
JSIConverter<std::optional<std::vector<std::string>>>::fromJSI(runtime, obj.getProperty(runtime, "x5c")),
|
|
89
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "x5t")),
|
|
90
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "x5t#256")),
|
|
91
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "n")),
|
|
92
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "e")),
|
|
93
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "d")),
|
|
94
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "p")),
|
|
95
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "q")),
|
|
96
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "x")),
|
|
97
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "y")),
|
|
98
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "k")),
|
|
99
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "dp")),
|
|
100
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "dq")),
|
|
101
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "qi")),
|
|
102
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "ext"))
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const JWK& arg) {
|
|
106
|
+
jsi::Object obj(runtime);
|
|
107
|
+
obj.setProperty(runtime, "kty", JSIConverter<std::optional<JWKkty>>::toJSI(runtime, arg.kty));
|
|
108
|
+
obj.setProperty(runtime, "use", JSIConverter<std::optional<JWKuse>>::toJSI(runtime, arg.use));
|
|
109
|
+
obj.setProperty(runtime, "key_ops", JSIConverter<std::optional<std::vector<KeyUsage>>>::toJSI(runtime, arg.key_ops));
|
|
110
|
+
obj.setProperty(runtime, "alg", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.alg));
|
|
111
|
+
obj.setProperty(runtime, "crv", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.crv));
|
|
112
|
+
obj.setProperty(runtime, "kid", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.kid));
|
|
113
|
+
obj.setProperty(runtime, "x5u", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.x5u));
|
|
114
|
+
obj.setProperty(runtime, "x5c", JSIConverter<std::optional<std::vector<std::string>>>::toJSI(runtime, arg.x5c));
|
|
115
|
+
obj.setProperty(runtime, "x5t", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.x5t));
|
|
116
|
+
obj.setProperty(runtime, "x5t#256", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.x5t_256));
|
|
117
|
+
obj.setProperty(runtime, "n", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.n));
|
|
118
|
+
obj.setProperty(runtime, "e", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.e));
|
|
119
|
+
obj.setProperty(runtime, "d", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.d));
|
|
120
|
+
obj.setProperty(runtime, "p", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.p));
|
|
121
|
+
obj.setProperty(runtime, "q", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.q));
|
|
122
|
+
obj.setProperty(runtime, "x", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.x));
|
|
123
|
+
obj.setProperty(runtime, "y", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.y));
|
|
124
|
+
obj.setProperty(runtime, "k", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.k));
|
|
125
|
+
obj.setProperty(runtime, "dp", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.dp));
|
|
126
|
+
obj.setProperty(runtime, "dq", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.dq));
|
|
127
|
+
obj.setProperty(runtime, "qi", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.qi));
|
|
128
|
+
obj.setProperty(runtime, "ext", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.ext));
|
|
129
|
+
return obj;
|
|
130
|
+
}
|
|
131
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
132
|
+
if (!value.isObject()) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
jsi::Object obj = value.getObject(runtime);
|
|
136
|
+
if (!JSIConverter<std::optional<JWKkty>>::canConvert(runtime, obj.getProperty(runtime, "kty"))) return false;
|
|
137
|
+
if (!JSIConverter<std::optional<JWKuse>>::canConvert(runtime, obj.getProperty(runtime, "use"))) return false;
|
|
138
|
+
if (!JSIConverter<std::optional<std::vector<KeyUsage>>>::canConvert(runtime, obj.getProperty(runtime, "key_ops"))) return false;
|
|
139
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "alg"))) return false;
|
|
140
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "crv"))) return false;
|
|
141
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "kid"))) return false;
|
|
142
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "x5u"))) return false;
|
|
143
|
+
if (!JSIConverter<std::optional<std::vector<std::string>>>::canConvert(runtime, obj.getProperty(runtime, "x5c"))) return false;
|
|
144
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "x5t"))) return false;
|
|
145
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "x5t#256"))) return false;
|
|
146
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "n"))) return false;
|
|
147
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "e"))) return false;
|
|
148
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "d"))) return false;
|
|
149
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "p"))) return false;
|
|
150
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "q"))) return false;
|
|
151
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "x"))) return false;
|
|
152
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "y"))) return false;
|
|
153
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "k"))) return false;
|
|
154
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "dp"))) return false;
|
|
155
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "dq"))) return false;
|
|
156
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "qi"))) return false;
|
|
157
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "ext"))) return false;
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JWKkty.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2024 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/NitroHash.hpp>)
|
|
11
|
+
#include <NitroModules/NitroHash.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
16
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
21
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
namespace margelo::nitro::crypto {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An enum which can be represented as a JavaScript union (JWKkty).
|
|
30
|
+
*/
|
|
31
|
+
enum class JWKkty {
|
|
32
|
+
AES SWIFT_NAME(aes) = 0,
|
|
33
|
+
RSA SWIFT_NAME(rsa) = 1,
|
|
34
|
+
EC SWIFT_NAME(ec) = 2,
|
|
35
|
+
OCT SWIFT_NAME(oct) = 3,
|
|
36
|
+
} CLOSED_ENUM;
|
|
37
|
+
|
|
38
|
+
} // namespace margelo::nitro::crypto
|
|
39
|
+
|
|
40
|
+
namespace margelo::nitro {
|
|
41
|
+
|
|
42
|
+
using namespace margelo::nitro::crypto;
|
|
43
|
+
|
|
44
|
+
// C++ JWKkty <> JS JWKkty (union)
|
|
45
|
+
template <>
|
|
46
|
+
struct JSIConverter<JWKkty> {
|
|
47
|
+
static inline JWKkty fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
48
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
|
|
49
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
50
|
+
case hashString("AES"): return JWKkty::AES;
|
|
51
|
+
case hashString("RSA"): return JWKkty::RSA;
|
|
52
|
+
case hashString("EC"): return JWKkty::EC;
|
|
53
|
+
case hashString("oct"): return JWKkty::OCT;
|
|
54
|
+
default: [[unlikely]]
|
|
55
|
+
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum JWKkty - invalid value!");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, JWKkty arg) {
|
|
59
|
+
switch (arg) {
|
|
60
|
+
case JWKkty::AES: return JSIConverter<std::string>::toJSI(runtime, "AES");
|
|
61
|
+
case JWKkty::RSA: return JSIConverter<std::string>::toJSI(runtime, "RSA");
|
|
62
|
+
case JWKkty::EC: return JSIConverter<std::string>::toJSI(runtime, "EC");
|
|
63
|
+
case JWKkty::OCT: return JSIConverter<std::string>::toJSI(runtime, "oct");
|
|
64
|
+
default: [[unlikely]]
|
|
65
|
+
throw std::invalid_argument("Cannot convert JWKkty to JS - invalid value: "
|
|
66
|
+
+ std::to_string(static_cast<int>(arg)) + "!");
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
70
|
+
if (!value.isString()) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
|
|
74
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
75
|
+
case hashString("AES"):
|
|
76
|
+
case hashString("RSA"):
|
|
77
|
+
case hashString("EC"):
|
|
78
|
+
case hashString("oct"):
|
|
79
|
+
return true;
|
|
80
|
+
default:
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JWKuse.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2024 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/NitroHash.hpp>)
|
|
11
|
+
#include <NitroModules/NitroHash.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
16
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
21
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
namespace margelo::nitro::crypto {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An enum which can be represented as a JavaScript union (JWKuse).
|
|
30
|
+
*/
|
|
31
|
+
enum class JWKuse {
|
|
32
|
+
SIG SWIFT_NAME(sig) = 0,
|
|
33
|
+
ENC SWIFT_NAME(enc) = 1,
|
|
34
|
+
} CLOSED_ENUM;
|
|
35
|
+
|
|
36
|
+
} // namespace margelo::nitro::crypto
|
|
37
|
+
|
|
38
|
+
namespace margelo::nitro {
|
|
39
|
+
|
|
40
|
+
using namespace margelo::nitro::crypto;
|
|
41
|
+
|
|
42
|
+
// C++ JWKuse <> JS JWKuse (union)
|
|
43
|
+
template <>
|
|
44
|
+
struct JSIConverter<JWKuse> {
|
|
45
|
+
static inline JWKuse fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
46
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
|
|
47
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
48
|
+
case hashString("sig"): return JWKuse::SIG;
|
|
49
|
+
case hashString("enc"): return JWKuse::ENC;
|
|
50
|
+
default: [[unlikely]]
|
|
51
|
+
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum JWKuse - invalid value!");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, JWKuse arg) {
|
|
55
|
+
switch (arg) {
|
|
56
|
+
case JWKuse::SIG: return JSIConverter<std::string>::toJSI(runtime, "sig");
|
|
57
|
+
case JWKuse::ENC: return JSIConverter<std::string>::toJSI(runtime, "enc");
|
|
58
|
+
default: [[unlikely]]
|
|
59
|
+
throw std::invalid_argument("Cannot convert JWKuse to JS - invalid value: "
|
|
60
|
+
+ std::to_string(static_cast<int>(arg)) + "!");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
64
|
+
if (!value.isString()) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
|
|
68
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
69
|
+
case hashString("sig"):
|
|
70
|
+
case hashString("enc"):
|
|
71
|
+
return true;
|
|
72
|
+
default:
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// KFormatType.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2024 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <cmath>
|
|
11
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
12
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
13
|
+
#else
|
|
14
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
15
|
+
#endif
|
|
16
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
17
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
18
|
+
#else
|
|
19
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
20
|
+
#endif
|
|
21
|
+
|
|
22
|
+
namespace margelo::nitro::crypto {
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* An enum which can be represented as a JavaScript enum (KFormatType).
|
|
26
|
+
*/
|
|
27
|
+
enum class KFormatType {
|
|
28
|
+
KKEYFORMATDER SWIFT_NAME(kkeyformatder) = 0,
|
|
29
|
+
KKEYFORMATPEM SWIFT_NAME(kkeyformatpem) = 1,
|
|
30
|
+
KKEYFORMATJWK SWIFT_NAME(kkeyformatjwk) = 2,
|
|
31
|
+
} CLOSED_ENUM;
|
|
32
|
+
|
|
33
|
+
} // namespace margelo::nitro::crypto
|
|
34
|
+
|
|
35
|
+
namespace margelo::nitro {
|
|
36
|
+
|
|
37
|
+
using namespace margelo::nitro::crypto;
|
|
38
|
+
|
|
39
|
+
// C++ KFormatType <> JS KFormatType (enum)
|
|
40
|
+
template <>
|
|
41
|
+
struct JSIConverter<KFormatType> {
|
|
42
|
+
static inline KFormatType fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
43
|
+
int enumValue = JSIConverter<int>::fromJSI(runtime, arg);
|
|
44
|
+
return static_cast<KFormatType>(enumValue);
|
|
45
|
+
}
|
|
46
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, KFormatType arg) {
|
|
47
|
+
int enumValue = static_cast<int>(arg);
|
|
48
|
+
return JSIConverter<int>::toJSI(runtime, enumValue);
|
|
49
|
+
}
|
|
50
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
51
|
+
if (!value.isNumber()) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
double integer;
|
|
55
|
+
double fraction = modf(value.getNumber(), &integer);
|
|
56
|
+
if (fraction != 0.0) {
|
|
57
|
+
// It is some kind of floating point number - our enums are ints.
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
// Check if we are within the bounds of the enum.
|
|
61
|
+
return integer >= 0 && integer <= 2;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
} // namespace margelo::nitro
|