diff --git a/bun.lock b/bun.lock index 0b2684a7e..14467ca71 100644 --- a/bun.lock +++ b/bun.lock @@ -20,7 +20,7 @@ "eslint-plugin-react-native": "5.0.0", "husky": "9.1.7", "lint-staged": "16.1.6", - "nitrogen": "0.33.2", + "nitrogen": "1.0.0-alpha.nightly.138.g43e09c161101", "prettier": "3.5.3", "release-it": "20.0.1", "typescript": "5.8.3", @@ -42,11 +42,11 @@ "crypto-browserify": "3.12.0", "event-target-polyfill": "0.0.4", "events": "3.3.0", + "nitro-core": "1.0.0-alpha.nightly.138.g43e09c161101", "react": "19.3.0", "react-native": "0.88.1", "react-native-bouncy-checkbox": "2.1.10", - "react-native-mmkv": "4.3.2", - "react-native-nitro-modules": "0.36.5", + "react-native-nitro-modules": "1.0.0-alpha.nightly.138.g43e09c161101", "react-native-quick-base64": "3.0.0", "react-native-quick-crypto": "workspace:*", "react-native-safe-area-context": "5.11.1", @@ -106,19 +106,23 @@ "dpdm": "^4.0.1", "expo": "^54.0.25", "jest": "29.7.0", - "nitrogen": "0.33.2", + "nitro-core": "1.0.0-alpha.nightly.138.g43e09c161101", + "nitrogen": "1.0.0-alpha.nightly.138.g43e09c161101", "react-native-builder-bob": "0.40.15", - "react-native-nitro-modules": "0.36.5", + "react-native-nitro-modules": "1.0.0-alpha.nightly.138.g43e09c161101", }, "peerDependencies": { "expo": ">=48.0.0", + "nitro-core": "1.0.0-alpha.nightly.138.g43e09c161101", "react": "*", "react-native": "*", - "react-native-nitro-modules": ">=0.31.2", + "react-native-nitro-modules": "1.0.0-alpha.nightly.138.g43e09c161101", "react-native-quick-base64": ">=3.0.0", }, "optionalPeers": [ "expo", + "nitro-core", + "react-native-nitro-modules", ], }, }, @@ -694,7 +698,7 @@ "@sinonjs/fake-timers": ["@sinonjs/fake-timers@10.3.0", "", { "dependencies": { "@sinonjs/commons": "^3.0.0" } }, "sha512-V4BG07kuYSUkTCSBHG8G8TNhM+F19jXFWnQtzj+we8DrkpSBCee9Z3Ms8yiGer/dlmhe35/Xdgyo3/0rQKg7YA=="], - "@ts-morph/common": ["@ts-morph/common@0.28.1", "", { "dependencies": { "minimatch": "^10.0.1", "path-browserify": "^1.0.1", "tinyglobby": "^0.2.14" } }, "sha512-W74iWf7ILp1ZKNYXY5qbddNaml7e9Sedv5lvU1V8lftlitkc9Pq1A+jlH23ltDgWYeZFFEqGCD1Ies9hqu3O+g=="], + "@ts-morph/common": ["@ts-morph/common@0.29.1", "", { "dependencies": { "minimatch": "^11.0.1", "path-browserify": "^1.0.1", "tinyglobby": "^0.2.14" } }, "sha512-P6hGYQ+taPsxmoY4svs0uFNiaLdOPDE+F5FqTBwoA76x8HmEggQXbEhSo78ZsyrGzUxbQfdr/5P7lHYUHF0r2Q=="], "@tsconfig/react-native": ["@tsconfig/react-native@3.0.5", "", {}, "sha512-0+pmYzHccvwWpFz2Tv5AJxp6UroLALmAy+SX34tKlwaCie1mNbtCv6uOJp7x8pKchgNA9/n6BGrx7uLQvw8p9A=="], @@ -1398,7 +1402,7 @@ "get-caller-file": ["get-caller-file@2.0.5", "", {}, "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg=="], - "get-east-asian-width": ["get-east-asian-width@1.4.0", "", {}, "sha512-QZjmEOC+IT1uk6Rx0sX22V6uHWVwbdbxf1faPqJ1QhLdGgsRGCZoyaQBm/piRdJy/D2um6hM1UP7ZEeQ4EkP+Q=="], + "get-east-asian-width": ["get-east-asian-width@1.7.0", "", {}, "sha512-XjH1AECxf0giL2V1aU8vKyRR2ppRUb5c0EvT7zuJTokQ74bNo52zOtghqdWIqrhUD79fo3x0WfKZdOqxF6LG1Q=="], "get-intrinsic": ["get-intrinsic@1.3.0", "", { "dependencies": { "call-bind-apply-helpers": "^1.0.2", "es-define-property": "^1.0.1", "es-errors": "^1.3.0", "es-object-atoms": "^1.1.1", "function-bind": "^1.1.2", "get-proto": "^1.0.1", "gopd": "^1.2.0", "has-symbols": "^1.1.0", "hasown": "^2.0.2", "math-intrinsics": "^1.1.0" } }, "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ=="], @@ -1888,7 +1892,9 @@ "new-github-release-url": ["new-github-release-url@2.0.0", "", { "dependencies": { "type-fest": "^2.5.1" } }, "sha512-NHDDGYudnvRutt/VhKFlX26IotXe1w0cmkDm6JGquh5bz/bDTw0LufSmH/GxTjEdpHEO+bVKFTwdrcGa/9XlKQ=="], - "nitrogen": ["nitrogen@0.33.2", "", { "dependencies": { "chalk": "^5.3.0", "react-native-nitro-modules": "^0.33.2", "ts-morph": "^27.0.0", "yargs": "^18.0.0", "zod": "^4.0.5" }, "bin": { "nitrogen": "lib/index.js" } }, "sha512-1fypSMqDU2vnRDmI8PYH0F3/ICLgRqsKCtOyNSMX7rQsG9D7G6zINvZH0Vk0unjzTude5SN8XNFO5im4LrGCvQ=="], + "nitro-core": ["nitro-core@1.0.0-alpha.nightly.138.g43e09c161101", "", {}, "sha512-PTOpc4jUIzfsyWUWJgXT+3of9xqbOBCenS6dkhrEmYPvHsZ+VKMK61RO+ph38UKVZLAd/zLij3uh2ZU0g1AtYQ=="], + + "nitrogen": ["nitrogen@1.0.0-alpha.nightly.138.g43e09c161101", "", { "dependencies": { "chalk": "^5.3.0", "nitro-core": "1.0.0-alpha.nightly.138.g43e09c161101", "ts-morph": "^28.0.0", "yargs": "^18.1.0", "zod": "^4.4.3" }, "bin": { "nitrogen": "bin/nitrogen.js" } }, "sha512-cFf+u0MQqy7e1uipRBoipkYVHMxN8KaB2LUs/9G0BHQPMZJu7KjVt7t1moPicBtrMPfZPDW/aClpUylYfNDpkA=="], "nocache": ["nocache@3.0.4", "", {}, "sha512-WDD0bdg9mbq6F4mRxEYcPWwfA1vxd0mrvKOyxI7Xj/atfRHVeutzuWByG//jfm4uPzp0y4Kj051EORCBSQMycw=="], @@ -2108,11 +2114,9 @@ "react-native-builder-bob": ["react-native-builder-bob@0.40.15", "", { "dependencies": { "@babel/core": "^7.25.2", "@babel/plugin-transform-flow-strip-types": "^7.26.5", "@babel/plugin-transform-strict-mode": "^7.24.7", "@babel/preset-env": "^7.25.2", "@babel/preset-react": "^7.24.7", "@babel/preset-typescript": "^7.24.7", "arktype": "^2.1.15", "babel-plugin-syntax-hermes-parser": "^0.28.0", "browserslist": "^4.20.4", "cross-spawn": "^7.0.3", "dedent": "^0.7.0", "del": "^6.1.1", "escape-string-regexp": "^4.0.0", "fs-extra": "^10.1.0", "glob": "^8.0.3", "is-git-dirty": "^2.0.1", "json5": "^2.2.1", "kleur": "^4.1.4", "prompts": "^2.4.2", "react-native-monorepo-config": "^0.1.8", "which": "^2.0.2", "yargs": "^17.5.1" }, "bin": { "bob": "bin/bob" } }, "sha512-p70LXlYOe53bZeEQchbK1hIhBGQsuB13bT81E7KkOe4dQABwMV6c585A4np0c3nwTTaqQMDYUat4x7J0oLnjxQ=="], - "react-native-mmkv": ["react-native-mmkv@4.3.2", "", { "peerDependencies": { "react": "*", "react-native": "*", "react-native-nitro-modules": "*" } }, "sha512-49OAyfkg0/TMWiWELZN6VuVQPZPhizwL4DTmp8b7B1md3dB/s3LH3mGfC3T+lp9W0y/rqxZMEnotLFTIbOAenQ=="], - "react-native-monorepo-config": ["react-native-monorepo-config@0.1.10", "", { "dependencies": { "escape-string-regexp": "^5.0.0", "fast-glob": "^3.3.3" } }, "sha512-v0rlaLZiCUg95Mpw6xNRQce5k9yio0qscKjNQaPtFYMNL75YugS2UPUItIPLIRbZubK+s2/LRzBjX+mdyUgh4g=="], - "react-native-nitro-modules": ["react-native-nitro-modules@0.36.5", "", { "peerDependencies": { "react": "*", "react-native": "*" } }, "sha512-SJby84+hovD70JmQ1fq+56tw3oapJeChehUqXA4Gqjm+ktJhMAcj8LGwoAjStSOUwRaK7czbzBPB0Widj+EDoQ=="], + "react-native-nitro-modules": ["react-native-nitro-modules@1.0.0-alpha.nightly.138.g43e09c161101", "", { "dependencies": { "nitro-core": "1.0.0-alpha.nightly.138.g43e09c161101" }, "peerDependencies": { "react": "*", "react-native": ">=0.88.0" } }, "sha512-wMBTgHxy6WyzIVnccmXGjbQGTJWbix7kTYAP9BJWy6Cp6Dcdy0A+QWujGL/t6W/0smD1rYyLx1u7PQBJp8UjvA=="], "react-native-quick-base64": ["react-native-quick-base64@3.0.0", "", { "peerDependencies": { "react": "*", "react-native": "*" } }, "sha512-gnJhA4a/QIGrptZQJv0hLLne8yyJPkdXtn33LHEzq3nhzsv+jRhrxr07wYwYX+CKCRXmuNkZ3Wo7LapSrFVmQg=="], @@ -2304,7 +2308,7 @@ "string-natural-compare": ["string-natural-compare@3.0.1", "", {}, "sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw=="], - "string-width": ["string-width@7.2.0", "", { "dependencies": { "emoji-regex": "^10.3.0", "get-east-asian-width": "^1.0.0", "strip-ansi": "^7.1.0" } }, "sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ=="], + "string-width": ["string-width@8.3.0", "", { "dependencies": { "get-east-asian-width": "^1.5.0", "strip-ansi": "^7.1.2" } }, "sha512-ZbmZM0JCihQN91dWnxoipT2KOEyHqEyfRXUyjuRhW8b/xnqPDoq4gWEVApTVa9db2wN8mmoikgFBbjh71+cGeQ=="], "string.prototype.matchall": ["string.prototype.matchall@4.0.12", "", { "dependencies": { "call-bind": "^1.0.8", "call-bound": "^1.0.3", "define-properties": "^1.2.1", "es-abstract": "^1.23.6", "es-errors": "^1.3.0", "es-object-atoms": "^1.0.0", "get-intrinsic": "^1.2.6", "gopd": "^1.2.0", "has-symbols": "^1.1.0", "internal-slot": "^1.1.0", "regexp.prototype.flags": "^1.5.3", "set-function-name": "^2.0.2", "side-channel": "^1.1.0" } }, "sha512-6CC9uyBL+/48dYizRf7H7VAYCMCNTBeM78x/VTUe9bFEaxBepPJDa1Ow99LqI/1yF7kuy7Q3cQsYMrcjGUcskA=="], @@ -2374,7 +2378,7 @@ "ts-interface-checker": ["ts-interface-checker@0.1.13", "", {}, "sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA=="], - "ts-morph": ["ts-morph@27.0.2", "", { "dependencies": { "@ts-morph/common": "~0.28.1", "code-block-writer": "^13.0.3" } }, "sha512-fhUhgeljcrdZ+9DZND1De1029PrE+cMkIP7ooqkLRTrRLTqcki2AstsyJm0vRNbTbVCNJ0idGlbBrfqc7/nA8w=="], + "ts-morph": ["ts-morph@28.0.0", "", { "dependencies": { "@ts-morph/common": "~0.29.0", "code-block-writer": "^13.0.3" } }, "sha512-Wp3tnZ2bzwxyTZMtgWVzXDfm7lB1Drz+y9DmmYH/L702PQhPyVrp3pkou3yIz4qjS14GY9kcpmLiOOMvl8oG1g=="], "tslib": ["tslib@2.8.1", "", {}, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="], @@ -2518,7 +2522,7 @@ "yaml": ["yaml@2.8.2", "", { "bin": { "yaml": "bin.mjs" } }, "sha512-mplynKqc1C2hTVYxd0PU2xQAc22TI1vShAYGksCCfxbn/dFwnHTNi1bvYsBTkhdUNtGIf5xNOg938rrSSYvS9A=="], - "yargs": ["yargs@18.0.0", "", { "dependencies": { "cliui": "^9.0.1", "escalade": "^3.1.1", "get-caller-file": "^2.0.5", "string-width": "^7.2.0", "y18n": "^5.0.5", "yargs-parser": "^22.0.0" } }, "sha512-4UEqdc2RYGHZc7Doyqkrqiln3p9X2DZVxaGbwhn2pi7MrRagKaOcIKe8L3OxYcbhXLgLFUS3zAYuQjKBQgmuNg=="], + "yargs": ["yargs@18.2.0", "", { "dependencies": { "cliui": "^9.0.1", "escalade": "^3.1.1", "get-caller-file": "^2.0.5", "string-width": "^8.2.1", "y18n": "^5.0.5", "yargs-parser": "^22.0.0" } }, "sha512-9OpKOLeaoNFecEp7P6iYbzze/5CqWoH7N3SMs/6y1XF4nMvFMspEGZzJ6uFi9MmQwXhyzqYoSEKO3tvA3Z/o2w=="], "yargs-parser": ["yargs-parser@22.0.0", "", {}, "sha512-rwu/ClNdSMpkSrUb+d6BRsSkLUq1fmfsY6TOpYzTwvwkg1/NRG85KBy3kq++A8LKQwX6lsu+aWad+2khvuXrqw=="], @@ -2526,7 +2530,7 @@ "yoctocolors": ["yoctocolors@2.1.2", "", {}, "sha512-CzhO+pFNo8ajLM2d2IW/R93ipy99LWjtwblvC1RsoSUMZgyLbYFr221TnSNT7GjGdYui6P459mw9JH/g/zW2ug=="], - "zod": ["zod@4.3.6", "", {}, "sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg=="], + "zod": ["zod@4.6.7", "", {}, "sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg=="], "zod-validation-error": ["zod-validation-error@4.0.2", "", { "peerDependencies": { "zod": "^3.25.0 || ^4.0.0" } }, "sha512-Q6/nZLe6jxuU80qb/4uJ4t5v2VEZ44lzQjPDhYJNztRQ4wyWc6VF3D3Kb/fAuPetZQnhS3hnajCf9CsWesghLQ=="], @@ -2658,7 +2662,7 @@ "@react-navigation/core/react-is": ["react-is@19.2.4", "", {}, "sha512-W+EWGn2v0ApPKgKKCy/7s7WHXkboGcsrXE+2joLyVxkbyVQfO3MUEaUQDHoSmb8TFFrSKYa9mw64WZHNHSDzYA=="], - "@ts-morph/common/minimatch": ["minimatch@10.1.1", "", { "dependencies": { "@isaacs/brace-expansion": "^5.0.0" } }, "sha512-enIvLvRAFZYXJzkCYG5RKmPfrFArdLv+R+lbQ53BmIMLIry74bjKzX6iHAm8WYamJkhSSEabrWN5D97XnKObjQ=="], + "@ts-morph/common/minimatch": ["minimatch@11.0.9", "", { "dependencies": { "@isaacs/nonrecursive-glob-match": "^1.1.0", "brace-expansion": "^5.0.12" } }, "sha512-KCFkfyjqerNlSstjlhIGNXIKZGA/6O4V4RlhZ+Dsr621SPPw0mzlypE9D9ZOoPiVefHID+j7/XuMMlqfD/F60Q=="], "@types/react-native/@types/react": ["@types/react@19.2.0", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-1LOH8xovvsKsCBq1wnT4ntDUdCJKmnEakhsuoUSy6ExlHCkGP2hqnatagYTgFk6oeL0VU31u7SNjunPN+GchtA=="], @@ -2712,6 +2716,8 @@ "cli-truncate/string-width": ["string-width@8.1.1", "", { "dependencies": { "get-east-asian-width": "^1.3.0", "strip-ansi": "^7.1.0" } }, "sha512-KpqHIdDL9KwYk22wEOg/VIqYbrnLeSApsKT/bSj6Ez7pn3CftUiLAv2Lccpq1ALcpLV9UX1Ppn92npZWu2w/aw=="], + "cliui/string-width": ["string-width@7.2.0", "", { "dependencies": { "emoji-regex": "^10.3.0", "get-east-asian-width": "^1.0.0", "strip-ansi": "^7.1.0" } }, "sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ=="], + "cliui/strip-ansi": ["strip-ansi@7.1.2", "", { "dependencies": { "ansi-regex": "^6.0.1" } }, "sha512-gmBGslpoQJtgnMAvOVqGZpEz9dyoKTCzy2nfz/n8aIFhN/jCE/rCmcxabB6jOOHV+0WNnylOxaxBQPSvcWklhA=="], "compression/debug": ["debug@2.6.9", "", { "dependencies": { "ms": "2.0.0" } }, "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA=="], @@ -2742,6 +2748,8 @@ "dpdm/typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="], + "dpdm/yargs": ["yargs@18.0.0", "", { "dependencies": { "cliui": "^9.0.1", "escalade": "^3.1.1", "get-caller-file": "^2.0.5", "string-width": "^7.2.0", "y18n": "^5.0.5", "yargs-parser": "^22.0.0" } }, "sha512-4UEqdc2RYGHZc7Doyqkrqiln3p9X2DZVxaGbwhn2pi7MrRagKaOcIKe8L3OxYcbhXLgLFUS3zAYuQjKBQgmuNg=="], + "elliptic/bn.js": ["bn.js@4.12.2", "", {}, "sha512-n4DSx829VRTRByMRGdjQ9iqsN0Bh4OolPsFnaZBLcbi8iXcB+kJ9s7EnRt4wILZNV3kPLHkRVfOc/HvhC3ovDw=="], "error-ex/is-arrayish": ["is-arrayish@0.2.1", "", {}, "sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg=="], @@ -2762,6 +2770,8 @@ "eslint-plugin-react-hooks/hermes-parser": ["hermes-parser@0.25.1", "", { "dependencies": { "hermes-estree": "0.25.1" } }, "sha512-6pEjquH3rqaI6cYAXYPcz9MS4rY6R4ngRgrgfDshRptUZIc3lw0MCIJIGDj9++mfySOuPTHB4nrSW99BCvOPIA=="], + "eslint-plugin-react-hooks/zod": ["zod@4.3.6", "", {}, "sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg=="], + "expo-modules-autolinking/commander": ["commander@7.2.0", "", {}, "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw=="], "fast-glob/glob-parent": ["glob-parent@5.1.2", "", { "dependencies": { "is-glob": "^4.0.1" } }, "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow=="], @@ -2868,8 +2878,6 @@ "nitrogen/chalk": ["chalk@5.6.2", "", {}, "sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA=="], - "nitrogen/react-native-nitro-modules": ["react-native-nitro-modules@0.33.2", "", { "peerDependencies": { "react": "*", "react-native": "*" } }, "sha512-ZlfOe6abODeHv/eZf8PxeSkrxIUhEKha6jaAAA9oXy7I6VPr7Ff4dUsAq3cyF3kX0L6qt2Dh9nzD2NdSsDwGpA=="], - "nypm/citty": ["citty@0.2.0", "", {}, "sha512-8csy5IBFI2ex2hTVpaHN2j+LNE199AgiI7y4dMintrr8i0lQiFn+0AWMZrWdHKIgMOer65f8IThysYhoReqjWA=="], "ora/chalk": ["chalk@5.6.2", "", {}, "sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA=="], @@ -2984,6 +2992,8 @@ "wrap-ansi/ansi-styles": ["ansi-styles@6.2.3", "", {}, "sha512-4Dj6M28JB+oAH8kFkTLUo+a2jwOFkuqb3yucU0CANcRRUbxS0cP0nZYCGjcc3BNXwRIsUVmDGgzawme7zvJHvg=="], + "wrap-ansi/string-width": ["string-width@7.2.0", "", { "dependencies": { "emoji-regex": "^10.3.0", "get-east-asian-width": "^1.0.0", "strip-ansi": "^7.1.0" } }, "sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ=="], + "wrap-ansi/strip-ansi": ["strip-ansi@7.1.2", "", { "dependencies": { "ansi-regex": "^6.0.1" } }, "sha512-gmBGslpoQJtgnMAvOVqGZpEz9dyoKTCzy2nfz/n8aIFhN/jCE/rCmcxabB6jOOHV+0WNnylOxaxBQPSvcWklhA=="], "xml2js/xmlbuilder": ["xmlbuilder@11.0.1", "", {}, "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA=="], @@ -3122,6 +3132,8 @@ "@react-native/eslint-config/@typescript-eslint/parser/@typescript-eslint/visitor-keys": ["@typescript-eslint/visitor-keys@8.74.0", "", { "dependencies": { "@typescript-eslint/types": "8.74.0", "eslint-visitor-keys": "^5.0.0" } }, "sha512-XSZmOtMUbWCBIM+2BK134FyMFxmll1mW2mPLk/PSwYQYzGIPMgJAqL929U4qXVizLv7Xq5b7r41/o7Ombuwk0g=="], + "@ts-morph/common/minimatch/brace-expansion": ["brace-expansion@5.1.0", "", { "dependencies": { "balanced-match": "^4.0.2" } }, "sha512-aa11Dv491GKnYqxaul3aRJ0szew7yMJMfZPnqD44NjGrZXoj62l41OEDDpdpC4eE2P88vBFfLuSyRhpG91NUvg=="], + "@typescript-eslint/typescript-estree/minimatch/brace-expansion": ["brace-expansion@2.0.2", "", { "dependencies": { "balanced-match": "^1.0.0" } }, "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ=="], "accepts/mime-types/mime-db": ["mime-db@1.52.0", "", {}, "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg=="], @@ -3156,14 +3168,20 @@ "chromium-edge-launcher/is-wsl/is-docker": ["is-docker@2.2.1", "", { "bin": { "is-docker": "cli.js" } }, "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ=="], + "cli-truncate/string-width/get-east-asian-width": ["get-east-asian-width@1.4.0", "", {}, "sha512-QZjmEOC+IT1uk6Rx0sX22V6uHWVwbdbxf1faPqJ1QhLdGgsRGCZoyaQBm/piRdJy/D2um6hM1UP7ZEeQ4EkP+Q=="], + "cli-truncate/string-width/strip-ansi": ["strip-ansi@7.1.2", "", { "dependencies": { "ansi-regex": "^6.0.1" } }, "sha512-gmBGslpoQJtgnMAvOVqGZpEz9dyoKTCzy2nfz/n8aIFhN/jCE/rCmcxabB6jOOHV+0WNnylOxaxBQPSvcWklhA=="], + "cliui/string-width/get-east-asian-width": ["get-east-asian-width@1.4.0", "", {}, "sha512-QZjmEOC+IT1uk6Rx0sX22V6uHWVwbdbxf1faPqJ1QhLdGgsRGCZoyaQBm/piRdJy/D2um6hM1UP7ZEeQ4EkP+Q=="], + "cliui/strip-ansi/ansi-regex": ["ansi-regex@6.2.2", "", {}, "sha512-Bq3SmSpyFHaWjPk8If9yc6svM8c56dB5BAtW4Qbw5jHTwwXXcTLoRMkpDJp6VL0XzlWaCHTXrkFURMYmD0sLqg=="], "compression/debug/ms": ["ms@2.0.0", "", {}, "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="], "connect/debug/ms": ["ms@2.0.0", "", {}, "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="], + "dpdm/yargs/string-width": ["string-width@7.2.0", "", { "dependencies": { "emoji-regex": "^10.3.0", "get-east-asian-width": "^1.0.0", "strip-ansi": "^7.1.0" } }, "sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ=="], + "eslint-plugin-react-hooks/hermes-parser/hermes-estree": ["hermes-estree@0.25.1", "", {}, "sha512-0wUoCcLp+5Ev5pDW2OriHC2MJCbwLwuRx+gAqMTOkGKJJiBCLjtrvy4PWUGn6MIVefecRpzoOZ/UV6iGdOr+Cw=="], "finalhandler/debug/ms": ["ms@2.0.0", "", {}, "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="], @@ -3268,6 +3286,8 @@ "metro/yargs/yargs-parser": ["yargs-parser@21.1.1", "", {}, "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw=="], + "ora/string-width/get-east-asian-width": ["get-east-asian-width@1.4.0", "", {}, "sha512-QZjmEOC+IT1uk6Rx0sX22V6uHWVwbdbxf1faPqJ1QhLdGgsRGCZoyaQBm/piRdJy/D2um6hM1UP7ZEeQ4EkP+Q=="], + "ora/string-width/strip-ansi": ["strip-ansi@7.1.2", "", { "dependencies": { "ansi-regex": "^6.0.1" } }, "sha512-gmBGslpoQJtgnMAvOVqGZpEz9dyoKTCzy2nfz/n8aIFhN/jCE/rCmcxabB6jOOHV+0WNnylOxaxBQPSvcWklhA=="], "pkg-dir/find-up/locate-path": ["locate-path@5.0.0", "", { "dependencies": { "p-locate": "^4.1.0" } }, "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g=="], @@ -3308,8 +3328,12 @@ "send/debug/ms": ["ms@2.0.0", "", {}, "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="], + "slice-ansi/is-fullwidth-code-point/get-east-asian-width": ["get-east-asian-width@1.4.0", "", {}, "sha512-QZjmEOC+IT1uk6Rx0sX22V6uHWVwbdbxf1faPqJ1QhLdGgsRGCZoyaQBm/piRdJy/D2um6hM1UP7ZEeQ4EkP+Q=="], + "string-width/strip-ansi/ansi-regex": ["ansi-regex@6.2.2", "", {}, "sha512-Bq3SmSpyFHaWjPk8If9yc6svM8c56dB5BAtW4Qbw5jHTwwXXcTLoRMkpDJp6VL0XzlWaCHTXrkFURMYmD0sLqg=="], + "wrap-ansi/string-width/get-east-asian-width": ["get-east-asian-width@1.4.0", "", {}, "sha512-QZjmEOC+IT1uk6Rx0sX22V6uHWVwbdbxf1faPqJ1QhLdGgsRGCZoyaQBm/piRdJy/D2um6hM1UP7ZEeQ4EkP+Q=="], + "wrap-ansi/strip-ansi/ansi-regex": ["ansi-regex@6.2.2", "", {}, "sha512-Bq3SmSpyFHaWjPk8If9yc6svM8c56dB5BAtW4Qbw5jHTwwXXcTLoRMkpDJp6VL0XzlWaCHTXrkFURMYmD0sLqg=="], "@babel/highlight/chalk/ansi-styles/color-convert": ["color-convert@1.9.3", "", { "dependencies": { "color-name": "1.1.3" } }, "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg=="], @@ -3404,6 +3428,8 @@ "@react-native/eslint-config/@typescript-eslint/parser/@typescript-eslint/visitor-keys/eslint-visitor-keys": ["eslint-visitor-keys@5.0.1", "", {}, "sha512-tD40eHxA35h0PEIZNeIjkHoDR4YjjJp34biM0mDvplBe//mB+IHCqHDGV7pxF+7MklTvighcCPPZC7ynWyjdTA=="], + "@ts-morph/common/minimatch/brace-expansion/balanced-match": ["balanced-match@4.0.4", "", {}, "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA=="], + "ansi-fragments/slice-ansi/ansi-styles/color-convert": ["color-convert@1.9.3", "", { "dependencies": { "color-name": "1.1.3" } }, "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg=="], "babel-plugin-module-resolver/glob/minimatch/brace-expansion": ["brace-expansion@2.0.2", "", { "dependencies": { "balanced-match": "^1.0.0" } }, "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ=="], @@ -3416,6 +3442,10 @@ "cli-truncate/string-width/strip-ansi/ansi-regex": ["ansi-regex@6.2.2", "", {}, "sha512-Bq3SmSpyFHaWjPk8If9yc6svM8c56dB5BAtW4Qbw5jHTwwXXcTLoRMkpDJp6VL0XzlWaCHTXrkFURMYmD0sLqg=="], + "dpdm/yargs/string-width/get-east-asian-width": ["get-east-asian-width@1.4.0", "", {}, "sha512-QZjmEOC+IT1uk6Rx0sX22V6uHWVwbdbxf1faPqJ1QhLdGgsRGCZoyaQBm/piRdJy/D2um6hM1UP7ZEeQ4EkP+Q=="], + + "dpdm/yargs/string-width/strip-ansi": ["strip-ansi@7.1.2", "", { "dependencies": { "ansi-regex": "^6.0.1" } }, "sha512-gmBGslpoQJtgnMAvOVqGZpEz9dyoKTCzy2nfz/n8aIFhN/jCE/rCmcxabB6jOOHV+0WNnylOxaxBQPSvcWklhA=="], + "jest-cli/yargs/cliui/wrap-ansi": ["wrap-ansi@7.0.0", "", { "dependencies": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", "strip-ansi": "^6.0.0" } }, "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q=="], "jest-cli/yargs/string-width/emoji-regex": ["emoji-regex@8.0.0", "", {}, "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="], @@ -3530,6 +3560,8 @@ "babel-preset-expo/@react-native/babel-preset/@react-native/babel-plugin-codegen/@react-native/codegen/yargs": ["yargs@17.7.2", "", { "dependencies": { "cliui": "^8.0.1", "escalade": "^3.1.1", "get-caller-file": "^2.0.5", "require-directory": "^2.1.1", "string-width": "^4.2.3", "y18n": "^5.0.5", "yargs-parser": "^21.1.1" } }, "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w=="], + "dpdm/yargs/string-width/strip-ansi/ansi-regex": ["ansi-regex@6.2.2", "", {}, "sha512-Bq3SmSpyFHaWjPk8If9yc6svM8c56dB5BAtW4Qbw5jHTwwXXcTLoRMkpDJp6VL0XzlWaCHTXrkFURMYmD0sLqg=="], + "logkitty/yargs/find-up/locate-path/p-locate": ["p-locate@4.1.0", "", { "dependencies": { "p-limit": "^2.2.0" } }, "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A=="], "metro-config/metro/@babel/traverse/@babel/code-frame/@babel/helper-validator-identifier": ["@babel/helper-validator-identifier@7.29.7", "", {}, "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg=="], diff --git a/example/babel.config.cjs b/example/babel.config.cjs index 142bc3ed5..cdddf85c0 100644 --- a/example/babel.config.cjs +++ b/example/babel.config.cjs @@ -1,5 +1,6 @@ module.exports = { presets: ['module:@react-native/babel-preset', '@babel/preset-typescript'], + parserOpts: { plugins: ['decorators'] }, plugins: [ ['@babel/plugin-transform-class-static-block'], [ diff --git a/example/package.json b/example/package.json index d3ffc2df7..67da73348 100644 --- a/example/package.json +++ b/example/package.json @@ -36,11 +36,11 @@ "crypto-browserify": "3.12.0", "event-target-polyfill": "0.0.4", "events": "3.3.0", + "nitro-core": "1.0.0-alpha.nightly.138.g43e09c161101", "react": "19.3.0", "react-native": "0.88.1", "react-native-bouncy-checkbox": "2.1.10", - "react-native-mmkv": "4.3.2", - "react-native-nitro-modules": "0.36.5", + "react-native-nitro-modules": "1.0.0-alpha.nightly.138.g43e09c161101", "react-native-quick-base64": "3.0.0", "react-native-quick-crypto": "workspace:*", "react-native-safe-area-context": "5.11.1", diff --git a/example/src/tests/slhdsa/raw_private_validation.ts b/example/src/tests/slhdsa/raw_private_validation.ts index 07ba674a4..050d5f4d4 100644 --- a/example/src/tests/slhdsa/raw_private_validation.ts +++ b/example/src/tests/slhdsa/raw_private_validation.ts @@ -6,10 +6,10 @@ import { sign, verify, type SlhDsaKeyPairType, + isSlhDsaPrivateKeyFactoryHandle, type KeyObjectHandle, - type SlhDsaPrivateKeyFactoryHandle, } from 'react-native-quick-crypto'; -import { NitroModules } from 'react-native-nitro-modules'; +import { KeyObjectHandle as NativeKeyObjectHandle } from 'react-native-quick-crypto/src/specs/keyObjectHandle.nitro'; import { expect } from 'chai'; import { assertThrowsAsync, test } from '../util'; @@ -198,10 +198,10 @@ test(SUITE, 'imports validated handles with bounded admission', async () => { 'SLH-DSA raw private keys require createPrivateKeyAsync()', ); - const factory = - NitroModules.createHybridObject( - 'KeyObjectHandle', - ); + const factory = new NativeKeyObjectHandle(); + if (!isSlhDsaPrivateKeyFactoryHandle(factory)) { + throw new Error('SLH-DSA raw private key import is unavailable'); + } try { for (const value of [null, 1, {}, new Uint8Array(64)]) { await assertThrowsAsync( diff --git a/example/tsconfig.json b/example/tsconfig.json index e1499f150..bae9fcb51 100644 --- a/example/tsconfig.json +++ b/example/tsconfig.json @@ -1,5 +1,8 @@ { "extends": ["@react-native/typescript-config", "../config/tsconfig.json"], + "compilerOptions": { + "resolvePackageJsonImports": true + }, "include": [ "index.ts", "app.json", diff --git a/package.json b/package.json index 3a96a328c..c67004734 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "eslint-plugin-react-native": "5.0.0", "husky": "9.1.7", "lint-staged": "16.1.6", - "nitrogen": "0.33.2", + "nitrogen": "1.0.0-alpha.nightly.138.g43e09c161101", "prettier": "3.5.3", "release-it": "20.0.1", "typescript": "5.8.3", diff --git a/packages/react-native-quick-crypto/android/CMakeLists.txt b/packages/react-native-quick-crypto/android/CMakeLists.txt index 4cb275971..0cbd2a0ca 100644 --- a/packages/react-native-quick-crypto/android/CMakeLists.txt +++ b/packages/react-native-quick-crypto/android/CMakeLists.txt @@ -74,7 +74,8 @@ add_library( target_compile_definitions(${PACKAGE_NAME} PRIVATE NCRYPTO_EVP_ONLY=1) -# add Nitrogen specs +# add Nitrogen specs (bare output links nitro-core, which RN hosts provide via the shim) +set(nitro-core_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake/nitro-core") include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/QuickCrypto+autolinking.cmake) # local includes diff --git a/packages/react-native-quick-crypto/android/cmake/nitro-core/nitro-core-config.cmake b/packages/react-native-quick-crypto/android/cmake/nitro-core/nitro-core-config.cmake new file mode 100644 index 000000000..f1086817f --- /dev/null +++ b/packages/react-native-quick-crypto/android/cmake/nitro-core/nitro-core-config.cmake @@ -0,0 +1,14 @@ +# React Native hosts have no nitro-core prefab package. Map the bare target name onto +# react-native-nitro-modules so Nitrogen's "bare" +autolinking.cmake links unchanged. +find_package(react-native-nitro-modules REQUIRED CONFIG) +find_package(ReactAndroid REQUIRED CONFIG) +if(NOT TARGET nitro-core::NitroModules) + add_library(nitro-core::NitroModules INTERFACE IMPORTED) + target_link_libraries(nitro-core::NitroModules INTERFACE + react-native-nitro-modules::NitroModules ReactAndroid::jsi ReactAndroid::reactnative) + target_compile_definitions(nitro-core::NitroModules INTERFACE + RN_SERIALIZABLE_STATE FOLLY_NO_CONFIG=1 FOLLY_HAVE_CLOCK_GETTIME=1 FOLLY_USE_LIBCPP=1 + FOLLY_CFG_NO_COROUTINES=1 FOLLY_MOBILE=1 FOLLY_HAVE_RECVMMSG=1 FOLLY_HAVE_PTHREAD=1 + FOLLY_HAVE_XSI_STRERROR_R=1) +endif() +set(nitro-core_FOUND TRUE) diff --git a/packages/react-native-quick-crypto/android/src/main/cpp/cpp-adapter.cpp b/packages/react-native-quick-crypto/android/src/main/cpp/cpp-adapter.cpp index f19aeba19..4231adece 100644 --- a/packages/react-native-quick-crypto/android/src/main/cpp/cpp-adapter.cpp +++ b/packages/react-native-quick-crypto/android/src/main/cpp/cpp-adapter.cpp @@ -1,8 +1,8 @@ #include #include -#include "QuickCryptoOnLoad.hpp" +#include JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) { - return facebook::jni::initialize(vm, [=] { margelo::nitro::crypto::initialize(vm); }); + return facebook::jni::initialize(vm, [] { margelo::nitro::crypto::registerAllNatives(); }); } diff --git a/packages/react-native-quick-crypto/babel.config.js b/packages/react-native-quick-crypto/babel.config.js index f7b3da3b3..0ec1cd85c 100644 --- a/packages/react-native-quick-crypto/babel.config.js +++ b/packages/react-native-quick-crypto/babel.config.js @@ -1,3 +1,4 @@ module.exports = { - presets: ['module:@react-native/babel-preset'], + presets: ['module:react-native-builder-bob/babel-preset'], + parserOpts: { plugins: ['decorators'] }, }; diff --git a/packages/react-native-quick-crypto/cpp/argon2/HybridArgon2.cpp b/packages/react-native-quick-crypto/cpp/argon2/HybridArgon2.cpp index 2163d7b8b..792935fc3 100644 --- a/packages/react-native-quick-crypto/cpp/argon2/HybridArgon2.cpp +++ b/packages/react-native-quick-crypto/cpp/argon2/HybridArgon2.cpp @@ -23,10 +23,9 @@ static ncrypto::Argon2Type parseAlgorithm(const std::string& algo) { throw std::runtime_error("Unknown argon2 algorithm: " + algo); } -static std::shared_ptr hashImpl(const std::string& algorithm, const std::shared_ptr& message, - const std::shared_ptr& nonce, double parallelism, double tagLength, double memory, - double passes, double version, const std::optional>& secret, - const std::optional>& associatedData) { +static ArrayBuffer hashImpl(const std::string& algorithm, const ArrayBuffer& message, const ArrayBuffer& nonce, double parallelism, + double tagLength, double memory, double passes, double version, const std::optional& secret, + const std::optional& associatedData) { auto type = parseAlgorithm(algorithm); @@ -39,20 +38,19 @@ static std::shared_ptr hashImpl(const std::string& algorithm, const uint32_t passesU = validateUInt(passes, "Argon2 passes"); uint32_t versionU = validateUInt(version, "Argon2 version"); - ncrypto::Buffer passBuf{message->size() > 0 ? reinterpret_cast(message->data()) : "", message->size()}; + ncrypto::Buffer passBuf{message.size() > 0 ? reinterpret_cast(message.data()) : "", message.size()}; - ncrypto::Buffer saltBuf{nonce->size() > 0 ? reinterpret_cast(nonce->data()) - : reinterpret_cast(""), - nonce->size()}; + ncrypto::Buffer saltBuf{ + nonce.size() > 0 ? reinterpret_cast(nonce.data()) : reinterpret_cast(""), nonce.size()}; ncrypto::Buffer secretBuf{nullptr, 0}; - if (secret.has_value() && secret.value()->size() > 0) { - secretBuf = {reinterpret_cast(secret.value()->data()), secret.value()->size()}; + if (secret.has_value() && secret.value().size() > 0) { + secretBuf = {reinterpret_cast(secret.value().data()), secret.value().size()}; } ncrypto::Buffer adBuf{nullptr, 0}; - if (associatedData.has_value() && associatedData.value()->size() > 0) { - adBuf = {reinterpret_cast(associatedData.value()->data()), associatedData.value()->size()}; + if (associatedData.has_value() && associatedData.value().size() > 0) { + adBuf = {reinterpret_cast(associatedData.value().data()), associatedData.value().size()}; } auto result = ncrypto::argon2(passBuf, saltBuf, parallelismU, tagLengthU, memoryU, passesU, versionU, secretBuf, adBuf, type); @@ -69,25 +67,23 @@ static std::shared_ptr hashImpl(const std::string& algorithm, const #endif // OPENSSL_NO_ARGON2 #endif // OPENSSL_VERSION_NUMBER -std::shared_ptr>> -HybridArgon2::hash(const std::string& algorithm, const std::shared_ptr& message, const std::shared_ptr& nonce, - double parallelism, double tagLength, double memory, double passes, double version, - const std::optional>& secret, - const std::optional>& associatedData) { +Promise HybridArgon2::hash(const std::string& algorithm, const ArrayBuffer& message, const ArrayBuffer& nonce, + double parallelism, double tagLength, double memory, double passes, double version, + const std::optional& secret, const std::optional& associatedData) { #if OPENSSL_VERSION_NUMBER >= 0x30200000L && !defined(OPENSSL_NO_ARGON2) auto nativeMessage = ToNativeArrayBuffer(message); auto nativeNonce = ToNativeArrayBuffer(nonce); - std::optional> nativeSecret; + std::optional nativeSecret; if (secret.has_value()) { nativeSecret = ToNativeArrayBuffer(secret.value()); } - std::optional> nativeAd; + std::optional nativeAd; if (associatedData.has_value()) { nativeAd = ToNativeArrayBuffer(associatedData.value()); } - return Promise>::async([algorithm, nativeMessage, nativeNonce, parallelism, tagLength, memory, passes, - version, nativeSecret = std::move(nativeSecret), nativeAd = std::move(nativeAd)]() { + return Promise::async([algorithm, nativeMessage, nativeNonce, parallelism, tagLength, memory, passes, version, + nativeSecret = std::move(nativeSecret), nativeAd = std::move(nativeAd)]() { return hashImpl(algorithm, nativeMessage, nativeNonce, parallelism, tagLength, memory, passes, version, nativeSecret, nativeAd); }); #else @@ -95,11 +91,9 @@ HybridArgon2::hash(const std::string& algorithm, const std::shared_ptr HybridArgon2::hashSync(const std::string& algorithm, const std::shared_ptr& message, - const std::shared_ptr& nonce, double parallelism, double tagLength, - double memory, double passes, double version, - const std::optional>& secret, - const std::optional>& associatedData) { +ArrayBuffer HybridArgon2::hashSync(const std::string& algorithm, const ArrayBuffer& message, const ArrayBuffer& nonce, double parallelism, + double tagLength, double memory, double passes, double version, const std::optional& secret, + const std::optional& associatedData) { #if OPENSSL_VERSION_NUMBER >= 0x30200000L && !defined(OPENSSL_NO_ARGON2) return hashImpl(algorithm, message, nonce, parallelism, tagLength, memory, passes, version, secret, associatedData); #else diff --git a/packages/react-native-quick-crypto/cpp/argon2/HybridArgon2.hpp b/packages/react-native-quick-crypto/cpp/argon2/HybridArgon2.hpp index c8a4325e5..71feb068a 100644 --- a/packages/react-native-quick-crypto/cpp/argon2/HybridArgon2.hpp +++ b/packages/react-native-quick-crypto/cpp/argon2/HybridArgon2.hpp @@ -6,7 +6,7 @@ #include #include -#include "HybridArgon2Spec.hpp" +#include namespace margelo::nitro::crypto { @@ -14,19 +14,13 @@ using namespace facebook; class HybridArgon2 : public HybridArgon2Spec { public: - HybridArgon2() : HybridObject(TAG) {} + static Promise hash(const std::string& algorithm, const ArrayBuffer& message, const ArrayBuffer& nonce, double parallelism, + double tagLength, double memory, double passes, double version, const std::optional& secret, + const std::optional& associatedData); - public: - std::shared_ptr>> hash(const std::string& algorithm, const std::shared_ptr& message, - const std::shared_ptr& nonce, double parallelism, - double tagLength, double memory, double passes, double version, - const std::optional>& secret, - const std::optional>& associatedData) override; - - std::shared_ptr hashSync(const std::string& algorithm, const std::shared_ptr& message, - const std::shared_ptr& nonce, double parallelism, double tagLength, double memory, - double passes, double version, const std::optional>& secret, - const std::optional>& associatedData) override; + static ArrayBuffer hashSync(const std::string& algorithm, const ArrayBuffer& message, const ArrayBuffer& nonce, double parallelism, + double tagLength, double memory, double passes, double version, const std::optional& secret, + const std::optional& associatedData); }; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/cpp/blake3/HybridBlake3.cpp b/packages/react-native-quick-crypto/cpp/blake3/HybridBlake3.cpp index 176a533fa..7cda4929d 100644 --- a/packages/react-native-quick-crypto/cpp/blake3/HybridBlake3.cpp +++ b/packages/react-native-quick-crypto/cpp/blake3/HybridBlake3.cpp @@ -17,13 +17,13 @@ void HybridBlake3::initHash() { initialized = true; } -void HybridBlake3::initKeyed(const std::shared_ptr& keyBuffer) { - if (!keyBuffer || keyBuffer->size() != BLAKE3_KEY_LEN) { +void HybridBlake3::initKeyed(const ArrayBuffer& keyBuffer) { + if (keyBuffer.size() != BLAKE3_KEY_LEN) { throw std::runtime_error("BLAKE3 key must be exactly 32 bytes"); } std::array keyArray; - std::memcpy(keyArray.data(), keyBuffer->data(), BLAKE3_KEY_LEN); + std::memcpy(keyArray.data(), keyBuffer.data(), BLAKE3_KEY_LEN); blake3_hasher_init_keyed(&hasher, keyArray.data()); mode = Mode::Keyed; @@ -44,17 +44,14 @@ void HybridBlake3::initDeriveKey(const std::string& ctx) { initialized = true; } -void HybridBlake3::update(const std::shared_ptr& data) { +void HybridBlake3::update(const ArrayBuffer& data) { if (!initialized) { throw std::runtime_error("BLAKE3 hasher not initialized"); } - if (!data) { - return; - } - blake3_hasher_update(&hasher, data->data(), data->size()); + blake3_hasher_update(&hasher, dataOrEmpty(data), data.size()); } -std::shared_ptr HybridBlake3::digest(std::optional length) { +ArrayBuffer HybridBlake3::digest(const std::optional& length) { if (!initialized) { throw std::runtime_error("BLAKE3 hasher not initialized"); } @@ -72,7 +69,7 @@ std::shared_ptr HybridBlake3::digest(std::optional length) blake3_hasher_finalize(&hasher, output.get(), outLen); uint8_t* raw_ptr = output.get(); - return std::make_shared(output.release(), outLen, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(output.release(), outLen, [raw_ptr]() { delete[] raw_ptr; }); } void HybridBlake3::reset() { diff --git a/packages/react-native-quick-crypto/cpp/blake3/HybridBlake3.hpp b/packages/react-native-quick-crypto/cpp/blake3/HybridBlake3.hpp index 92d15c483..a7d55b5f6 100644 --- a/packages/react-native-quick-crypto/cpp/blake3/HybridBlake3.hpp +++ b/packages/react-native-quick-crypto/cpp/blake3/HybridBlake3.hpp @@ -4,25 +4,25 @@ #include #include -#include "HybridBlake3Spec.hpp" #include "blake3.h" +#include namespace margelo::nitro::crypto { class HybridBlake3 : public HybridBlake3Spec { public: - HybridBlake3() : HybridObject(TAG) {} + HybridBlake3() = default; ~HybridBlake3() = default; public: void initHash() override; - void initKeyed(const std::shared_ptr& key) override; + void initKeyed(const ArrayBuffer& key) override; void initDeriveKey(const std::string& context) override; - void update(const std::shared_ptr& data) override; - std::shared_ptr digest(std::optional length) override; + void update(const ArrayBuffer& data) override; + ArrayBuffer digest(const std::optional& length) override; void reset() override; std::shared_ptr copy() override; - std::string getVersion() override; + static std::string getVersion(); private: blake3_hasher hasher; diff --git a/packages/react-native-quick-crypto/cpp/certificate/HybridCertificate.cpp b/packages/react-native-quick-crypto/cpp/certificate/HybridCertificate.cpp index 2cf78a53d..d866e2aa6 100644 --- a/packages/react-native-quick-crypto/cpp/certificate/HybridCertificate.cpp +++ b/packages/react-native-quick-crypto/cpp/certificate/HybridCertificate.cpp @@ -5,33 +5,30 @@ namespace margelo::nitro::crypto { -bool HybridCertificate::verifySpkac(const std::shared_ptr& spkac) { - return ncrypto::VerifySpkac(reinterpret_cast(spkac->data()), spkac->size()); +bool HybridCertificate::verifySpkac(const ArrayBuffer& spkac) { + return ncrypto::VerifySpkac(reinterpret_cast(dataOrEmpty(spkac)), spkac.size()); } -std::shared_ptr HybridCertificate::exportPublicKey(const std::shared_ptr& spkac) { - auto bio = ncrypto::ExportPublicKey(reinterpret_cast(spkac->data()), spkac->size()); +ArrayBuffer HybridCertificate::exportPublicKey(const ArrayBuffer& spkac) { + auto bio = ncrypto::ExportPublicKey(reinterpret_cast(dataOrEmpty(spkac)), spkac.size()); if (!bio) { - auto empty = new uint8_t[0]; - return std::make_shared(empty, 0, [empty]() { delete[] empty; }); + return ArrayBuffer::empty(); } BUF_MEM* mem = bio; if (!mem || mem->length == 0) { - auto empty = new uint8_t[0]; - return std::make_shared(empty, 0, [empty]() { delete[] empty; }); + return ArrayBuffer::empty(); } return ToNativeArrayBuffer(reinterpret_cast(mem->data), mem->length); } -std::shared_ptr HybridCertificate::exportChallenge(const std::shared_ptr& spkac) { - auto buf = ncrypto::ExportChallenge(reinterpret_cast(spkac->data()), spkac->size()); +ArrayBuffer HybridCertificate::exportChallenge(const ArrayBuffer& spkac) { + auto buf = ncrypto::ExportChallenge(reinterpret_cast(dataOrEmpty(spkac)), spkac.size()); if (buf.data == nullptr) { - auto empty = new uint8_t[0]; - return std::make_shared(empty, 0, [empty]() { delete[] empty; }); + return ArrayBuffer::empty(); } auto result = ToNativeArrayBuffer(reinterpret_cast(buf.data), buf.len); diff --git a/packages/react-native-quick-crypto/cpp/certificate/HybridCertificate.hpp b/packages/react-native-quick-crypto/cpp/certificate/HybridCertificate.hpp index f8884db34..fefe73b24 100644 --- a/packages/react-native-quick-crypto/cpp/certificate/HybridCertificate.hpp +++ b/packages/react-native-quick-crypto/cpp/certificate/HybridCertificate.hpp @@ -1,16 +1,14 @@ #pragma once -#include "HybridCertificateSpec.hpp" +#include namespace margelo::nitro::crypto { class HybridCertificate : public HybridCertificateSpec { public: - HybridCertificate() : HybridObject(TAG) {} - - bool verifySpkac(const std::shared_ptr& spkac) override; - std::shared_ptr exportPublicKey(const std::shared_ptr& spkac) override; - std::shared_ptr exportChallenge(const std::shared_ptr& spkac) override; + static bool verifySpkac(const ArrayBuffer& spkac); + static ArrayBuffer exportPublicKey(const ArrayBuffer& spkac); + static ArrayBuffer exportChallenge(const ArrayBuffer& spkac); }; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/cpp/cipher/CCMCipher.cpp b/packages/react-native-quick-crypto/cpp/cipher/CCMCipher.cpp index 211e6cab8..434cebe4b 100644 --- a/packages/react-native-quick-crypto/cpp/cipher/CCMCipher.cpp +++ b/packages/react-native-quick-crypto/cpp/cipher/CCMCipher.cpp @@ -6,7 +6,7 @@ namespace margelo::nitro::crypto { -void CCMCipher::init(const std::shared_ptr cipher_key, const std::shared_ptr iv) { +void CCMCipher::init(const ArrayBuffer& cipher_key, const ArrayBuffer& iv) { // 1. Call the base class initializer first try { HybridCipher::init(cipher_key, iv); @@ -18,7 +18,7 @@ void CCMCipher::init(const std::shared_ptr cipher_key, const std::s checkCtx(); // 2. Perform CCM-specific initialization - size_t iv_len = iv->size(); + size_t iv_len = iv.size(); // Set the IV length using CCM-specific control if (EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_CCM_SET_IVLEN, iv_len, nullptr) != 1) { @@ -38,8 +38,8 @@ void CCMCipher::init(const std::shared_ptr cipher_key, const std::s } // Finally, initialize the key and IV using the parameters passed to this function. - const unsigned char* key_ptr = reinterpret_cast(cipher_key->data()); - const unsigned char* iv_ptr = reinterpret_cast(iv->data()); + const unsigned char* key_ptr = dataOrEmpty(cipher_key); + const unsigned char* iv_ptr = dataOrEmpty(iv); // The last argument (is_cipher) should be consistent with the initial setup call. if (EVP_CipherInit_ex(ctx.get(), nullptr, nullptr, key_ptr, iv_ptr, is_cipher) != 1) { @@ -50,11 +50,11 @@ void CCMCipher::init(const std::shared_ptr cipher_key, const std::s } } -std::shared_ptr CCMCipher::update(const std::shared_ptr& data) { +ArrayBuffer CCMCipher::update(const ArrayBuffer& data) { checkCtx(); checkNotFinalized(); has_update_called = true; - size_t in_len = data->size(); + size_t in_len = data.size(); if (in_len < 0 || in_len > INT_MAX) { throw std::runtime_error("Invalid message length"); } @@ -74,7 +74,7 @@ std::shared_ptr CCMCipher::update(const std::shared_ptr(out_len); - const uint8_t* in = reinterpret_cast(data->data()); + const uint8_t* in = dataOrEmpty(data); int actual_out_len = 0; int ret = EVP_CipherUpdate(ctx.get(), out_buf.get(), &actual_out_len, in, in_len); @@ -102,10 +102,10 @@ std::shared_ptr CCMCipher::update(const std::shared_ptr(final_output, actual_out_len, [=]() { delete[] final_output; }); + return ArrayBuffer::wrap(final_output, actual_out_len, [=]() { delete[] final_output; }); } -std::shared_ptr CCMCipher::final() { +ArrayBuffer CCMCipher::final() { checkCtx(); checkNotFinalized(); @@ -118,9 +118,7 @@ std::shared_ptr CCMCipher::final() { if (auth_tag_state == kAuthTagUnknown || pending_auth_failed) { throw std::runtime_error("Unsupported state or unable to authenticate data"); } - auto empty_output = std::make_unique(0); - unsigned char* raw_ptr = empty_output.get(); - return std::make_shared(empty_output.release(), 0, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::empty(); } // Proceed only for encryption @@ -152,10 +150,10 @@ std::shared_ptr CCMCipher::final() { is_finalized = true; unsigned char* final_output = out_buf.release(); - return std::make_shared(final_output, out_len, [=]() { delete[] final_output; }); + return ArrayBuffer::wrap(final_output, out_len, [=]() { delete[] final_output; }); } -bool CCMCipher::setAAD(const std::shared_ptr& data, std::optional plaintextLength) { +bool CCMCipher::setAAD(const ArrayBuffer& data, const std::optional& plaintextLength) { checkCtx(); checkAADBeforeUpdate(); if (!plaintextLength.has_value()) { @@ -182,7 +180,7 @@ bool CCMCipher::setAAD(const std::shared_ptr& data, std::optionalsize(); + size_t aad_len = data.size(); // 1. Set the total *ciphertext* length. This seems necessary based on examples, // BUT the wiki says "(only needed if AAD is passed)". Let's skip if decrypting and AAD length is 0. @@ -199,7 +197,7 @@ bool CCMCipher::setAAD(const std::shared_ptr& data, std::optionaldata(), aad_len) != 1) { + if (EVP_CipherUpdate(ctx.get(), nullptr, &out_len, dataOrEmpty(data), aad_len) != 1) { unsigned long err = ERR_get_error(); char err_buf[256]; ERR_error_string_n(err, err_buf, sizeof(err_buf)); diff --git a/packages/react-native-quick-crypto/cpp/cipher/CCMCipher.hpp b/packages/react-native-quick-crypto/cpp/cipher/CCMCipher.hpp index 1a34697a6..288bd5a66 100644 --- a/packages/react-native-quick-crypto/cpp/cipher/CCMCipher.hpp +++ b/packages/react-native-quick-crypto/cpp/cipher/CCMCipher.hpp @@ -6,14 +6,14 @@ namespace margelo::nitro::crypto { class CCMCipher : public HybridCipher { public: - CCMCipher() : HybridObject(TAG) {} + CCMCipher() = default; // Destructor defaulted: HybridCipher's unique_ptr ctx frees itself. ~CCMCipher() override = default; - void init(const std::shared_ptr cipher_key, const std::shared_ptr iv) override; - std::shared_ptr update(const std::shared_ptr& data) override; - std::shared_ptr final() override; - bool setAAD(const std::shared_ptr& data, std::optional plaintextLength) override; + void init(const ArrayBuffer& cipher_key, const ArrayBuffer& iv) override; + ArrayBuffer update(const ArrayBuffer& data) override; + ArrayBuffer final() override; + bool setAAD(const ArrayBuffer& data, const std::optional& plaintextLength) override; private: // CCM mode supports messages up to 2^(8L) - 1 bytes where L is the length of nonce diff --git a/packages/react-native-quick-crypto/cpp/cipher/ChaCha20Cipher.cpp b/packages/react-native-quick-crypto/cpp/cipher/ChaCha20Cipher.cpp index bd335773a..6610473ea 100644 --- a/packages/react-native-quick-crypto/cpp/cipher/ChaCha20Cipher.cpp +++ b/packages/react-native-quick-crypto/cpp/cipher/ChaCha20Cipher.cpp @@ -6,7 +6,7 @@ namespace margelo::nitro::crypto { -void ChaCha20Cipher::init(const std::shared_ptr cipher_key, const std::shared_ptr iv) { +void ChaCha20Cipher::init(const ArrayBuffer& cipher_key, const ArrayBuffer& iv) { // Resetting the unique_ptr frees any previous context. ctx.reset(); @@ -33,17 +33,17 @@ void ChaCha20Cipher::init(const std::shared_ptr cipher_key, const s // Set key and IV // Validate key size - if (cipher_key->size() != kKeySize) { + if (cipher_key.size() != kKeySize) { throw std::runtime_error("ChaCha20 key must be 32 bytes"); } // Validate IV size - if (iv->size() != kIVSize) { + if (iv.size() != kIVSize) { throw std::runtime_error("ChaCha20 IV must be 16 bytes"); } - const unsigned char* key_ptr = reinterpret_cast(cipher_key->data()); - const unsigned char* iv_ptr = reinterpret_cast(iv->data()); + const unsigned char* key_ptr = dataOrEmpty(cipher_key); + const unsigned char* iv_ptr = dataOrEmpty(iv); if (EVP_CipherInit_ex(ctx.get(), nullptr, nullptr, key_ptr, iv_ptr, is_cipher) != 1) { unsigned long err = ERR_get_error(); @@ -54,10 +54,10 @@ void ChaCha20Cipher::init(const std::shared_ptr cipher_key, const s } } -std::shared_ptr ChaCha20Cipher::update(const std::shared_ptr& data) { +ArrayBuffer ChaCha20Cipher::update(const ArrayBuffer& data) { checkCtx(); checkNotFinalized(); - size_t in_len = data->size(); + size_t in_len = data.size(); if (in_len > INT_MAX) { throw std::runtime_error("Message too long"); } @@ -67,7 +67,7 @@ std::shared_ptr ChaCha20Cipher::update(const std::shared_ptr(out_len); // Perform the cipher update operation - if (EVP_CipherUpdate(ctx.get(), out_buf.get(), &out_len, data->data(), in_len) != 1) { + if (EVP_CipherUpdate(ctx.get(), out_buf.get(), &out_len, dataOrEmpty(data), in_len) != 1) { unsigned long err = ERR_get_error(); char err_buf[256]; ERR_error_string_n(err, err_buf, sizeof(err_buf)); @@ -76,16 +76,14 @@ std::shared_ptr ChaCha20Cipher::update(const std::shared_ptr(out_buf.release(), out_len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(out_buf.release(), out_len, [raw_ptr]() { delete[] raw_ptr; }); } -std::shared_ptr ChaCha20Cipher::final() { +ArrayBuffer ChaCha20Cipher::final() { checkCtx(); checkNotFinalized(); is_finalized = true; - auto empty_buf = std::make_unique(0); - unsigned char* raw_ptr = empty_buf.get(); - return std::make_shared(empty_buf.release(), 0, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::empty(); } } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/cpp/cipher/ChaCha20Cipher.hpp b/packages/react-native-quick-crypto/cpp/cipher/ChaCha20Cipher.hpp index 92b7e75ac..92fb7ea0b 100644 --- a/packages/react-native-quick-crypto/cpp/cipher/ChaCha20Cipher.hpp +++ b/packages/react-native-quick-crypto/cpp/cipher/ChaCha20Cipher.hpp @@ -6,13 +6,13 @@ namespace margelo::nitro::crypto { class ChaCha20Cipher : public HybridCipher { public: - ChaCha20Cipher() : HybridObject(TAG) {} + ChaCha20Cipher() = default; // Destructor defaulted: HybridCipher's unique_ptr ctx frees itself. ~ChaCha20Cipher() override = default; - void init(const std::shared_ptr cipher_key, const std::shared_ptr iv) override; - std::shared_ptr update(const std::shared_ptr& data) override; - std::shared_ptr final() override; + void init(const ArrayBuffer& cipher_key, const ArrayBuffer& iv) override; + ArrayBuffer update(const ArrayBuffer& data) override; + ArrayBuffer final() override; private: // ChaCha20 uses a 256-bit key (32 bytes) and a 128-bit IV (16 bytes) diff --git a/packages/react-native-quick-crypto/cpp/cipher/ChaCha20Poly1305Cipher.cpp b/packages/react-native-quick-crypto/cpp/cipher/ChaCha20Poly1305Cipher.cpp index 6069cc075..bcb606181 100644 --- a/packages/react-native-quick-crypto/cpp/cipher/ChaCha20Poly1305Cipher.cpp +++ b/packages/react-native-quick-crypto/cpp/cipher/ChaCha20Poly1305Cipher.cpp @@ -6,7 +6,7 @@ namespace margelo::nitro::crypto { -void ChaCha20Poly1305Cipher::init(const std::shared_ptr cipher_key, const std::shared_ptr iv) { +void ChaCha20Poly1305Cipher::init(const ArrayBuffer& cipher_key, const ArrayBuffer& iv) { // Resetting the unique_ptr frees any previous context. ctx.reset(); @@ -33,17 +33,17 @@ void ChaCha20Poly1305Cipher::init(const std::shared_ptr cipher_key, // Set key and IV // Validate key size - if (cipher_key->size() != kKeySize) { + if (cipher_key.size() != kKeySize) { throw std::runtime_error("ChaCha20-Poly1305 key must be 32 bytes"); } // Validate nonce size - if (iv->size() != kNonceSize) { + if (iv.size() != kNonceSize) { throw std::runtime_error("ChaCha20-Poly1305 nonce must be 12 bytes"); } - const unsigned char* key_ptr = reinterpret_cast(cipher_key->data()); - const unsigned char* iv_ptr = reinterpret_cast(iv->data()); + const unsigned char* key_ptr = dataOrEmpty(cipher_key); + const unsigned char* iv_ptr = dataOrEmpty(iv); if (EVP_CipherInit_ex(ctx.get(), nullptr, nullptr, key_ptr, iv_ptr, is_cipher) != 1) { unsigned long err = ERR_get_error(); @@ -59,11 +59,11 @@ void ChaCha20Poly1305Cipher::init(const std::shared_ptr cipher_key, auth_tag_state = kAuthTagUnknown; } -std::shared_ptr ChaCha20Poly1305Cipher::update(const std::shared_ptr& data) { +ArrayBuffer ChaCha20Poly1305Cipher::update(const ArrayBuffer& data) { checkCtx(); checkNotFinalized(); has_update_called = true; - size_t in_len = data->size(); + size_t in_len = data.size(); if (in_len > INT_MAX) { throw std::runtime_error("Message too long"); } @@ -73,7 +73,7 @@ std::shared_ptr ChaCha20Poly1305Cipher::update(const std::shared_pt auto out_buf = std::make_unique(out_len); // Perform the cipher update operation - if (EVP_CipherUpdate(ctx.get(), out_buf.get(), &out_len, data->data(), in_len) != 1) { + if (EVP_CipherUpdate(ctx.get(), out_buf.get(), &out_len, dataOrEmpty(data), in_len) != 1) { unsigned long err = ERR_get_error(); char err_buf[256]; ERR_error_string_n(err, err_buf, sizeof(err_buf)); @@ -82,10 +82,10 @@ std::shared_ptr ChaCha20Poly1305Cipher::update(const std::shared_pt // Create and return a new buffer of exact size needed uint8_t* raw_ptr = out_buf.get(); - return std::make_shared(out_buf.release(), out_len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(out_buf.release(), out_len, [raw_ptr]() { delete[] raw_ptr; }); } -std::shared_ptr ChaCha20Poly1305Cipher::final() { +ArrayBuffer ChaCha20Poly1305Cipher::final() { checkCtx(); checkNotFinalized(); @@ -111,17 +111,17 @@ std::shared_ptr ChaCha20Poly1305Cipher::final() { is_finalized = true; unsigned char* raw_ptr = out_buf.get(); - return std::make_shared(out_buf.release(), out_len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(out_buf.release(), out_len, [raw_ptr]() { delete[] raw_ptr; }); } -bool ChaCha20Poly1305Cipher::setAAD(const std::shared_ptr& data, std::optional plaintextLength) { +bool ChaCha20Poly1305Cipher::setAAD(const ArrayBuffer& data, const std::optional& plaintextLength) { checkCtx(); checkAADBeforeUpdate(); - size_t aad_len = data->size(); + size_t aad_len = data.size(); // Set AAD data int out_len = 0; - if (EVP_CipherUpdate(ctx.get(), nullptr, &out_len, data->data(), aad_len) != 1) { + if (EVP_CipherUpdate(ctx.get(), nullptr, &out_len, dataOrEmpty(data), aad_len) != 1) { unsigned long err = ERR_get_error(); char err_buf[256]; ERR_error_string_n(err, err_buf, sizeof(err_buf)); @@ -130,7 +130,7 @@ bool ChaCha20Poly1305Cipher::setAAD(const std::shared_ptr& data, st return true; } -std::shared_ptr ChaCha20Poly1305Cipher::getAuthTag() { +ArrayBuffer ChaCha20Poly1305Cipher::getAuthTag() { checkCtx(); if (!is_cipher) { throw std::runtime_error("getAuthTag can only be called during encryption"); @@ -149,20 +149,20 @@ std::shared_ptr ChaCha20Poly1305Cipher::getAuthTag() { } uint8_t* raw_ptr = tag_buf.get(); - return std::make_shared(tag_buf.release(), kTagSize, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(tag_buf.release(), kTagSize, [raw_ptr]() { delete[] raw_ptr; }); } -bool ChaCha20Poly1305Cipher::setAuthTag(const std::shared_ptr& tag) { +bool ChaCha20Poly1305Cipher::setAuthTag(const ArrayBuffer& tag) { checkCtx(); if (is_cipher) { throw std::runtime_error("setAuthTag can only be called during decryption"); } - if (tag->size() != kTagSize) { + if (tag.size() != kTagSize) { throw std::runtime_error("ChaCha20-Poly1305 tag must be 16 bytes"); } - if (EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_AEAD_SET_TAG, kTagSize, tag->data()) != 1) { + if (EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_AEAD_SET_TAG, kTagSize, tag.data()) != 1) { unsigned long err = ERR_get_error(); char err_buf[256]; ERR_error_string_n(err, err_buf, sizeof(err_buf)); diff --git a/packages/react-native-quick-crypto/cpp/cipher/ChaCha20Poly1305Cipher.hpp b/packages/react-native-quick-crypto/cpp/cipher/ChaCha20Poly1305Cipher.hpp index 853dc1843..0fd238364 100644 --- a/packages/react-native-quick-crypto/cpp/cipher/ChaCha20Poly1305Cipher.hpp +++ b/packages/react-native-quick-crypto/cpp/cipher/ChaCha20Poly1305Cipher.hpp @@ -6,16 +6,16 @@ namespace margelo::nitro::crypto { class ChaCha20Poly1305Cipher : public HybridCipher { public: - ChaCha20Poly1305Cipher() : HybridObject(TAG) {} + ChaCha20Poly1305Cipher() = default; // Destructor defaulted: HybridCipher's unique_ptr ctx frees itself. ~ChaCha20Poly1305Cipher() override = default; - void init(const std::shared_ptr cipher_key, const std::shared_ptr iv) override; - std::shared_ptr update(const std::shared_ptr& data) override; - std::shared_ptr final() override; - bool setAAD(const std::shared_ptr& data, std::optional plaintextLength) override; - std::shared_ptr getAuthTag() override; - bool setAuthTag(const std::shared_ptr& tag) override; + void init(const ArrayBuffer& cipher_key, const ArrayBuffer& iv) override; + ArrayBuffer update(const ArrayBuffer& data) override; + ArrayBuffer final() override; + bool setAAD(const ArrayBuffer& data, const std::optional& plaintextLength) override; + ArrayBuffer getAuthTag() override; + bool setAuthTag(const ArrayBuffer& tag) override; private: // ChaCha20-Poly1305 uses a 256-bit key (32 bytes) and a 96-bit nonce (12 bytes) diff --git a/packages/react-native-quick-crypto/cpp/cipher/GCMCipher.cpp b/packages/react-native-quick-crypto/cpp/cipher/GCMCipher.cpp index 88172cf8d..28b7562ef 100644 --- a/packages/react-native-quick-crypto/cpp/cipher/GCMCipher.cpp +++ b/packages/react-native-quick-crypto/cpp/cipher/GCMCipher.cpp @@ -6,7 +6,7 @@ namespace margelo::nitro::crypto { -void GCMCipher::init(const std::shared_ptr cipher_key, const std::shared_ptr iv) { +void GCMCipher::init(const ArrayBuffer& cipher_key, const ArrayBuffer& iv) { // Resetting the unique_ptr frees any previous context. ctx.reset(); is_finalized = false; @@ -37,7 +37,7 @@ void GCMCipher::init(const std::shared_ptr cipher_key, const std::s } // 4. Set IV length for non-standard IV sizes (GCM default is 96 bits/12 bytes) - size_t iv_len = iv->size(); + size_t iv_len = iv.size(); if (iv_len != 12) { // Only set if not the default length if (EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_GCM_SET_IVLEN, static_cast(iv_len), nullptr) != 1) { @@ -50,8 +50,8 @@ void GCMCipher::init(const std::shared_ptr cipher_key, const std::s } // 5. Now set the key and IV - const unsigned char* key_ptr = reinterpret_cast(cipher_key->data()); - const unsigned char* iv_ptr = reinterpret_cast(iv->data()); + const unsigned char* key_ptr = dataOrEmpty(cipher_key); + const unsigned char* iv_ptr = dataOrEmpty(iv); if (EVP_CipherInit_ex(ctx.get(), nullptr, nullptr, key_ptr, iv_ptr, is_cipher) != 1) { unsigned long err = ERR_get_error(); diff --git a/packages/react-native-quick-crypto/cpp/cipher/GCMCipher.hpp b/packages/react-native-quick-crypto/cpp/cipher/GCMCipher.hpp index 65ce8e637..34fc5b89d 100644 --- a/packages/react-native-quick-crypto/cpp/cipher/GCMCipher.hpp +++ b/packages/react-native-quick-crypto/cpp/cipher/GCMCipher.hpp @@ -6,9 +6,9 @@ namespace margelo::nitro::crypto { class GCMCipher : public HybridCipher { public: - GCMCipher() : HybridObject(TAG) {} + GCMCipher() = default; - void init(const std::shared_ptr cipher_key, const std::shared_ptr iv) override; + void init(const ArrayBuffer& cipher_key, const ArrayBuffer& iv) override; }; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/cpp/cipher/HybridCipher.cpp b/packages/react-native-quick-crypto/cpp/cipher/HybridCipher.cpp index 59e8919e1..23b292a66 100644 --- a/packages/react-native-quick-crypto/cpp/cipher/HybridCipher.cpp +++ b/packages/react-native-quick-crypto/cpp/cipher/HybridCipher.cpp @@ -51,7 +51,7 @@ bool HybridCipher::maybePassAuthTagToOpenSSL() { return true; } -void HybridCipher::init(const std::shared_ptr cipher_key, const std::shared_ptr iv) { +void HybridCipher::init(const ArrayBuffer& cipher_key, const ArrayBuffer& iv) { // Resetting the unique_ptr frees any previous context. ctx.reset(); is_finalized = false; @@ -83,8 +83,8 @@ void HybridCipher::init(const std::shared_ptr cipher_key, const std // For base hybrid cipher, set key and IV immediately. // Derived classes like CCM might override init and handle this differently. - const unsigned char* key_ptr = reinterpret_cast(cipher_key->data()); - const unsigned char* iv_ptr = reinterpret_cast(iv->data()); + const unsigned char* key_ptr = dataOrEmpty(cipher_key); + const unsigned char* iv_ptr = dataOrEmpty(iv); if (EVP_CipherInit_ex(ctx.get(), nullptr, nullptr, key_ptr, iv_ptr, is_cipher) != 1) { unsigned long err = ERR_get_error(); @@ -103,11 +103,11 @@ void HybridCipher::init(const std::shared_ptr cipher_key, const std } } -std::shared_ptr HybridCipher::update(const std::shared_ptr& data) { +ArrayBuffer HybridCipher::update(const ArrayBuffer& data) { checkCtx(); checkNotFinalized(); has_update_called = true; - size_t in_len = data->size(); + size_t in_len = data.size(); if (in_len > INT_MAX) { throw std::runtime_error("Message too long"); } @@ -116,7 +116,7 @@ std::shared_ptr HybridCipher::update(const std::shared_ptr(out_len); // Perform the cipher update operation. The real size of the output is // returned in out_len - int ret = EVP_CipherUpdate(ctx.get(), out_buf.get(), &out_len, data->data(), in_len); + int ret = EVP_CipherUpdate(ctx.get(), out_buf.get(), &out_len, dataOrEmpty(data), in_len); if (!ret) { unsigned long err = ERR_get_error(); @@ -127,10 +127,10 @@ std::shared_ptr HybridCipher::update(const std::shared_ptr(out_buf.release(), out_len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(out_buf.release(), out_len, [raw_ptr]() { delete[] raw_ptr; }); } -std::shared_ptr HybridCipher::final() { +ArrayBuffer HybridCipher::final() { checkCtx(); checkNotFinalized(); // Block size is max output size for final, unless EVP_CIPH_NO_PADDING is set @@ -152,8 +152,7 @@ std::shared_ptr HybridCipher::final() { // Get raw pointer before releasing unique_ptr uint8_t* raw_ptr = out_buf.get(); // Create the specific NativeArrayBuffer first, using full namespace - auto native_final_chunk = std::make_shared(out_buf.release(), static_cast(out_len), - [raw_ptr]() { delete[] raw_ptr; }); + auto native_final_chunk = ArrayBuffer::wrap(out_buf.release(), static_cast(out_len), [raw_ptr]() { delete[] raw_ptr; }); // Context should NOT be freed here. It might be needed for getAuthTag() for GCM/OCB. // The context will be freed by the destructor (~HybridCipher) when the object goes out of scope. @@ -162,12 +161,12 @@ std::shared_ptr HybridCipher::final() { return native_final_chunk; } -bool HybridCipher::setAAD(const std::shared_ptr& data, std::optional plaintextLength) { +bool HybridCipher::setAAD(const ArrayBuffer& data, const std::optional& plaintextLength) { checkCtx(); checkAADBeforeUpdate(); // Set the AAD int out_len; - if (!EVP_CipherUpdate(ctx.get(), nullptr, &out_len, data->data(), data->size())) { + if (!EVP_CipherUpdate(ctx.get(), nullptr, &out_len, dataOrEmpty(data), data.size())) { return false; } @@ -180,15 +179,15 @@ bool HybridCipher::setAutoPadding(bool autoPad) { return EVP_CIPHER_CTX_set_padding(ctx.get(), autoPad) == 1; } -bool HybridCipher::setAuthTag(const std::shared_ptr& tag) { +bool HybridCipher::setAuthTag(const ArrayBuffer& tag) { checkCtx(); if (is_cipher) { throw std::runtime_error("setAuthTag can only be called during decryption."); } - size_t tag_len = tag->size(); - uint8_t* tag_ptr = tag->data(); + size_t tag_len = tag.size(); + uint8_t* tag_ptr = tag.data(); int mode = EVP_CIPHER_CTX_mode(ctx.get()); @@ -229,7 +228,7 @@ bool HybridCipher::setAuthTag(const std::shared_ptr& tag) { } } -std::shared_ptr HybridCipher::getAuthTag() { +ArrayBuffer HybridCipher::getAuthTag() { checkCtx(); int mode = EVP_CIPHER_CTX_mode(ctx.get()); @@ -253,8 +252,7 @@ std::shared_ptr HybridCipher::getAuthTag() { } uint8_t* raw_ptr = tag_buf.get(); - auto final_tag_buffer = - std::make_shared(tag_buf.release(), auth_tag_len, [raw_ptr]() { delete[] raw_ptr; }); + auto final_tag_buffer = ArrayBuffer::wrap(tag_buf.release(), auth_tag_len, [raw_ptr]() { delete[] raw_ptr; }); return final_tag_buffer; } else if (mode == EVP_CIPH_CCM_MODE) { @@ -264,8 +262,7 @@ std::shared_ptr HybridCipher::getAuthTag() { auto tag_buf = std::make_unique(auth_tag_len); std::memcpy(tag_buf.get(), auth_tag, auth_tag_len); uint8_t* raw_ptr = tag_buf.get(); - auto final_tag_buffer = - std::make_shared(tag_buf.release(), auth_tag_len, [raw_ptr]() { delete[] raw_ptr; }); + auto final_tag_buffer = ArrayBuffer::wrap(tag_buf.release(), auth_tag_len, [raw_ptr]() { delete[] raw_ptr; }); return final_tag_buffer; } else { throw std::runtime_error("CCM: Auth tag not available. Ensure encryption is finalized before calling getAuthTag."); @@ -343,8 +340,8 @@ std::vector HybridCipher::getSupportedCiphers() { return cipher_names; } -std::optional HybridCipher::getCipherInfo(const std::string& name, std::optional keyLength, - std::optional ivLength) { +std::optional HybridCipher::getCipherInfo(const std::string& name, const std::optional& keyLength, + const std::optional& ivLength) { auto cipher = ncrypto::Cipher::FromName(name.c_str()); if (!cipher) return std::nullopt; diff --git a/packages/react-native-quick-crypto/cpp/cipher/HybridCipher.hpp b/packages/react-native-quick-crypto/cpp/cipher/HybridCipher.hpp index 9bc0fe8af..cfdd36fe0 100644 --- a/packages/react-native-quick-crypto/cpp/cipher/HybridCipher.hpp +++ b/packages/react-native-quick-crypto/cpp/cipher/HybridCipher.hpp @@ -9,8 +9,8 @@ #include #include -#include "CipherInfo.hpp" -#include "HybridCipherSpec.hpp" +#include +#include namespace margelo::nitro::crypto { @@ -28,31 +28,31 @@ constexpr unsigned kDefaultAuthTagLength = 16; class HybridCipher : public HybridCipherSpec { public: - HybridCipher() : HybridObject(TAG) {} + HybridCipher() = default; ~HybridCipher() override; public: // Methods - std::shared_ptr update(const std::shared_ptr& data) override; + ArrayBuffer update(const ArrayBuffer& data) override; - std::shared_ptr final() override; + ArrayBuffer final() override; - virtual void init(const std::shared_ptr cipher_key, const std::shared_ptr iv); + virtual void init(const ArrayBuffer& cipher_key, const ArrayBuffer& iv); void setArgs(const CipherArgs& args) override; - bool setAAD(const std::shared_ptr& data, std::optional plaintextLength) override; + bool setAAD(const ArrayBuffer& data, const std::optional& plaintextLength) override; bool setAutoPadding(bool autoPad) override; - bool setAuthTag(const std::shared_ptr& tag) override; + bool setAuthTag(const ArrayBuffer& tag) override; - std::shared_ptr getAuthTag() override; + ArrayBuffer getAuthTag() override; - std::vector getSupportedCiphers() override; + static std::vector getSupportedCiphers(); - std::optional getCipherInfo(const std::string& name, std::optional keyLength, - std::optional ivLength) override; + static std::optional getCipherInfo(const std::string& name, const std::optional& keyLength, + const std::optional& ivLength); protected: // Protected enums for state management diff --git a/packages/react-native-quick-crypto/cpp/cipher/HybridCipherFactory.hpp b/packages/react-native-quick-crypto/cpp/cipher/HybridCipherFactory.hpp index e7309ce1d..3eab2e499 100644 --- a/packages/react-native-quick-crypto/cpp/cipher/HybridCipherFactory.hpp +++ b/packages/react-native-quick-crypto/cpp/cipher/HybridCipherFactory.hpp @@ -8,25 +8,21 @@ #include "ChaCha20Cipher.hpp" #include "ChaCha20Poly1305Cipher.hpp" #include "GCMCipher.hpp" -#include "HybridCipherFactorySpec.hpp" #include "OCBCipher.hpp" #include "QuickCryptoUtils.hpp" #include "XChaCha20Poly1305Cipher.hpp" #include "XSalsa20Cipher.hpp" #include "XSalsa20Poly1305Cipher.hpp" +#include namespace margelo::nitro::crypto { using namespace facebook; class HybridCipherFactory : public HybridCipherFactorySpec { - public: - HybridCipherFactory() : HybridObject(TAG) {} - ~HybridCipherFactory() = default; - public: // Factory method exposed to JS - inline std::shared_ptr createCipher(const CipherArgs& args) { + static inline std::shared_ptr createCipher(const CipherArgs& args) { // Create the appropriate cipher instance based on mode std::shared_ptr cipherInstance; diff --git a/packages/react-native-quick-crypto/cpp/cipher/HybridRsaCipher.cpp b/packages/react-native-quick-crypto/cpp/cipher/HybridRsaCipher.cpp index 0c753b83f..8c593187b 100644 --- a/packages/react-native-quick-crypto/cpp/cipher/HybridRsaCipher.cpp +++ b/packages/react-native-quick-crypto/cpp/cipher/HybridRsaCipher.cpp @@ -9,8 +9,6 @@ namespace margelo::nitro::crypto { -using margelo::nitro::NativeArrayBuffer; - constexpr int kRsaPkcs1Padding = 1; constexpr int kRsaOaepPadding = 4; @@ -57,10 +55,8 @@ int toOpenSSLPadding(int padding) { throw std::runtime_error("RSA decryption failed"); } -std::shared_ptr HybridRsaCipher::encrypt(const std::shared_ptr& keyHandle, - const std::shared_ptr& data, double padding, - const std::string& hashAlgorithm, - const std::optional>& label) { +ArrayBuffer HybridRsaCipher::encrypt(const std::shared_ptr& keyHandle, const ArrayBuffer& data, double padding, + const std::string& hashAlgorithm, const std::optional& label) { auto keyHandleImpl = std::static_pointer_cast(keyHandle); EVP_PKEY* pkey = keyHandleImpl->getKeyObjectData().GetAsymmetricKey().get(); @@ -101,15 +97,15 @@ std::shared_ptr HybridRsaCipher::encrypt(const std::shared_ptrsize() > 0) { - unsigned char* label_copy = (unsigned char*)OPENSSL_malloc(label.value()->size()); + if (label.has_value() && label.value().size() > 0) { + unsigned char* label_copy = (unsigned char*)OPENSSL_malloc(label.value().size()); if (!label_copy) { EVP_PKEY_CTX_free(ctx); throw std::runtime_error("Failed to allocate memory for label"); } - std::memcpy(label_copy, label.value()->data(), label.value()->size()); + std::memcpy(label_copy, label.value().data(), label.value().size()); - if (EVP_PKEY_CTX_set0_rsa_oaep_label(ctx, label_copy, label.value()->size()) <= 0) { + if (EVP_PKEY_CTX_set0_rsa_oaep_label(ctx, label_copy, label.value().size()) <= 0) { OPENSSL_free(label_copy); EVP_PKEY_CTX_free(ctx); throw std::runtime_error("Failed to set OAEP label"); @@ -117,8 +113,8 @@ std::shared_ptr HybridRsaCipher::encrypt(const std::shared_ptrdata(); - size_t inlen = data->size(); + const unsigned char* in = dataOrEmpty(data); + size_t inlen = data.size(); size_t outlen; if (EVP_PKEY_encrypt(ctx, nullptr, &outlen, in, inlen) <= 0) { @@ -141,14 +137,12 @@ std::shared_ptr HybridRsaCipher::encrypt(const std::shared_ptr(out_buf.release(), outlen, [raw_ptr]() { delete[] raw_ptr; }); + uint8_t* raw_ptr = out_buf.release(); + return ArrayBuffer::wrap(raw_ptr, outlen, [raw_ptr]() { delete[] raw_ptr; }); } -std::shared_ptr HybridRsaCipher::decrypt(const std::shared_ptr& keyHandle, - const std::shared_ptr& data, double padding, - const std::string& hashAlgorithm, - const std::optional>& label) { +ArrayBuffer HybridRsaCipher::decrypt(const std::shared_ptr& keyHandle, const ArrayBuffer& data, double padding, + const std::string& hashAlgorithm, const std::optional& label) { auto keyHandleImpl = std::static_pointer_cast(keyHandle); EVP_PKEY* pkey = keyHandleImpl->getKeyObjectData().GetAsymmetricKey().get(); @@ -194,15 +188,15 @@ std::shared_ptr HybridRsaCipher::decrypt(const std::shared_ptrsize() > 0) { - unsigned char* label_copy = (unsigned char*)OPENSSL_malloc(label.value()->size()); + if (label.has_value() && label.value().size() > 0) { + unsigned char* label_copy = (unsigned char*)OPENSSL_malloc(label.value().size()); if (!label_copy) { EVP_PKEY_CTX_free(ctx); throw std::runtime_error("Failed to allocate memory for label"); } - std::memcpy(label_copy, label.value()->data(), label.value()->size()); + std::memcpy(label_copy, label.value().data(), label.value().size()); - if (EVP_PKEY_CTX_set0_rsa_oaep_label(ctx, label_copy, label.value()->size()) <= 0) { + if (EVP_PKEY_CTX_set0_rsa_oaep_label(ctx, label_copy, label.value().size()) <= 0) { OPENSSL_free(label_copy); EVP_PKEY_CTX_free(ctx); throw std::runtime_error("Failed to set OAEP label"); @@ -210,8 +204,8 @@ std::shared_ptr HybridRsaCipher::decrypt(const std::shared_ptrdata(); - size_t inlen = data->size(); + const unsigned char* in = dataOrEmpty(data); + size_t inlen = data.size(); // Both decrypt calls below operate on attacker-controlled ciphertext, so // any failure must be surfaced with an opaque, content-independent message. @@ -231,12 +225,12 @@ std::shared_ptr HybridRsaCipher::decrypt(const std::shared_ptr(out_buf.release(), outlen, [raw_ptr]() { delete[] raw_ptr; }); + uint8_t* raw_ptr = out_buf.release(); + return ArrayBuffer::wrap(raw_ptr, outlen, [raw_ptr]() { delete[] raw_ptr; }); } -std::shared_ptr HybridRsaCipher::publicDecrypt(const std::shared_ptr& keyHandle, - const std::shared_ptr& data, double padding) { +ArrayBuffer HybridRsaCipher::publicDecrypt(const std::shared_ptr& keyHandle, const ArrayBuffer& data, + double padding) { auto keyHandleImpl = std::static_pointer_cast(keyHandle); EVP_PKEY* pkey = keyHandleImpl->getKeyObjectData().GetAsymmetricKey().get(); @@ -265,8 +259,8 @@ std::shared_ptr HybridRsaCipher::publicDecrypt(const std::shared_pt throw std::runtime_error("Failed to set RSA padding"); } - const unsigned char* in = data->data(); - size_t inlen = data->size(); + const unsigned char* in = dataOrEmpty(data); + size_t inlen = data.size(); // verify_recover acts on attacker-controlled ciphertext too — surface only // an opaque error so a remote caller cannot distinguish failure modes. @@ -278,9 +272,7 @@ std::shared_ptr HybridRsaCipher::publicDecrypt(const std::shared_pt if (outlen == 0) { EVP_PKEY_CTX_free(ctx); - auto empty_buf = std::make_unique(1); - uint8_t* raw_ptr = empty_buf.get(); - return std::make_shared(empty_buf.release(), 0, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::empty(); } auto out_buf = std::make_unique(outlen); @@ -302,9 +294,7 @@ std::shared_ptr HybridRsaCipher::publicDecrypt(const std::shared_pt if ((err & 0xFFFFFFF) == 0x1C880004 || (err & 0xFF) == 0x04) { ERR_clear_error(); EVP_PKEY_CTX_free(ctx); - auto empty_buf = std::make_unique(1); - uint8_t* raw_ptr = empty_buf.get(); - return std::make_shared(empty_buf.release(), 0, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::empty(); } EVP_PKEY_CTX_free(ctx); throwOpaqueDecryptFailure(); @@ -312,12 +302,12 @@ std::shared_ptr HybridRsaCipher::publicDecrypt(const std::shared_pt EVP_PKEY_CTX_free(ctx); - uint8_t* raw_ptr = out_buf.get(); - return std::make_shared(out_buf.release(), outlen, [raw_ptr]() { delete[] raw_ptr; }); + uint8_t* raw_ptr = out_buf.release(); + return ArrayBuffer::wrap(raw_ptr, outlen, [raw_ptr]() { delete[] raw_ptr; }); } -std::shared_ptr HybridRsaCipher::privateEncrypt(const std::shared_ptr& keyHandle, - const std::shared_ptr& data, double padding) { +ArrayBuffer HybridRsaCipher::privateEncrypt(const std::shared_ptr& keyHandle, const ArrayBuffer& data, + double padding) { auto keyHandleImpl = std::static_pointer_cast(keyHandle); EVP_PKEY* pkey = keyHandleImpl->getKeyObjectData().GetAsymmetricKey().get(); @@ -346,8 +336,8 @@ std::shared_ptr HybridRsaCipher::privateEncrypt(const std::shared_p throw std::runtime_error("Failed to set RSA padding"); } - const unsigned char* in = data->data(); - size_t inlen = data->size(); + const unsigned char* in = dataOrEmpty(data); + size_t inlen = data.size(); size_t outlen; if (EVP_PKEY_sign(ctx, nullptr, &outlen, in, inlen) <= 0) { @@ -370,14 +360,12 @@ std::shared_ptr HybridRsaCipher::privateEncrypt(const std::shared_p EVP_PKEY_CTX_free(ctx); - uint8_t* raw_ptr = out_buf.get(); - return std::make_shared(out_buf.release(), outlen, [raw_ptr]() { delete[] raw_ptr; }); + uint8_t* raw_ptr = out_buf.release(); + return ArrayBuffer::wrap(raw_ptr, outlen, [raw_ptr]() { delete[] raw_ptr; }); } -std::shared_ptr HybridRsaCipher::privateDecrypt(const std::shared_ptr& keyHandle, - const std::shared_ptr& data, double padding, - const std::string& hashAlgorithm, - const std::optional>& label) { +ArrayBuffer HybridRsaCipher::privateDecrypt(const std::shared_ptr& keyHandle, const ArrayBuffer& data, + double padding, const std::string& hashAlgorithm, const std::optional& label) { auto keyHandleImpl = std::static_pointer_cast(keyHandle); EVP_PKEY* pkey = keyHandleImpl->getKeyObjectData().GetAsymmetricKey().get(); @@ -423,15 +411,15 @@ std::shared_ptr HybridRsaCipher::privateDecrypt(const std::shared_p throw std::runtime_error("Failed to set MGF1 hash algorithm"); } - if (label.has_value() && label.value()->size() > 0) { - unsigned char* label_copy = (unsigned char*)OPENSSL_malloc(label.value()->size()); + if (label.has_value() && label.value().size() > 0) { + unsigned char* label_copy = (unsigned char*)OPENSSL_malloc(label.value().size()); if (!label_copy) { EVP_PKEY_CTX_free(ctx); throw std::runtime_error("Failed to allocate memory for label"); } - std::memcpy(label_copy, label.value()->data(), label.value()->size()); + std::memcpy(label_copy, label.value().data(), label.value().size()); - if (EVP_PKEY_CTX_set0_rsa_oaep_label(ctx, label_copy, label.value()->size()) <= 0) { + if (EVP_PKEY_CTX_set0_rsa_oaep_label(ctx, label_copy, label.value().size()) <= 0) { OPENSSL_free(label_copy); EVP_PKEY_CTX_free(ctx); throw std::runtime_error("Failed to set OAEP label"); @@ -439,8 +427,8 @@ std::shared_ptr HybridRsaCipher::privateDecrypt(const std::shared_p } } - const unsigned char* in = data->data(); - size_t inlen = data->size(); + const unsigned char* in = dataOrEmpty(data); + size_t inlen = data.size(); // Both decrypt calls below operate on attacker-controlled ciphertext, so // any failure must be surfaced with an opaque, content-independent message. @@ -460,18 +448,8 @@ std::shared_ptr HybridRsaCipher::privateDecrypt(const std::shared_p EVP_PKEY_CTX_free(ctx); - uint8_t* raw_ptr = out_buf.get(); - return std::make_shared(out_buf.release(), outlen, [raw_ptr]() { delete[] raw_ptr; }); -} - -void HybridRsaCipher::loadHybridMethods() { - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("encrypt", &HybridRsaCipher::encrypt); - prototype.registerHybridMethod("decrypt", &HybridRsaCipher::decrypt); - prototype.registerHybridMethod("publicDecrypt", &HybridRsaCipher::publicDecrypt); - prototype.registerHybridMethod("privateEncrypt", &HybridRsaCipher::privateEncrypt); - prototype.registerHybridMethod("privateDecrypt", &HybridRsaCipher::privateDecrypt); - }); + uint8_t* raw_ptr = out_buf.release(); + return ArrayBuffer::wrap(raw_ptr, outlen, [raw_ptr]() { delete[] raw_ptr; }); } } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/cpp/cipher/HybridRsaCipher.hpp b/packages/react-native-quick-crypto/cpp/cipher/HybridRsaCipher.hpp index 5133b24e7..fe308ae8a 100644 --- a/packages/react-native-quick-crypto/cpp/cipher/HybridRsaCipher.hpp +++ b/packages/react-native-quick-crypto/cpp/cipher/HybridRsaCipher.hpp @@ -1,33 +1,24 @@ #pragma once -#include "HybridRsaCipherSpec.hpp" +#include #include namespace margelo::nitro::crypto { class HybridRsaCipher : public HybridRsaCipherSpec { public: - HybridRsaCipher() : HybridObject(TAG) {} + static ArrayBuffer encrypt(const std::shared_ptr& keyHandle, const ArrayBuffer& data, double padding, + const std::string& hashAlgorithm, const std::optional& label); - std::shared_ptr encrypt(const std::shared_ptr& keyHandle, - const std::shared_ptr& data, double padding, const std::string& hashAlgorithm, - const std::optional>& label) override; + static ArrayBuffer decrypt(const std::shared_ptr& keyHandle, const ArrayBuffer& data, double padding, + const std::string& hashAlgorithm, const std::optional& label); - std::shared_ptr decrypt(const std::shared_ptr& keyHandle, - const std::shared_ptr& data, double padding, const std::string& hashAlgorithm, - const std::optional>& label) override; + static ArrayBuffer publicDecrypt(const std::shared_ptr& keyHandle, const ArrayBuffer& data, double padding); - std::shared_ptr publicDecrypt(const std::shared_ptr& keyHandle, - const std::shared_ptr& data, double padding) override; + static ArrayBuffer privateEncrypt(const std::shared_ptr& keyHandle, const ArrayBuffer& data, double padding); - std::shared_ptr privateEncrypt(const std::shared_ptr& keyHandle, - const std::shared_ptr& data, double padding) override; - - std::shared_ptr privateDecrypt(const std::shared_ptr& keyHandle, - const std::shared_ptr& data, double padding, const std::string& hashAlgorithm, - const std::optional>& label) override; - - void loadHybridMethods() override; + static ArrayBuffer privateDecrypt(const std::shared_ptr& keyHandle, const ArrayBuffer& data, double padding, + const std::string& hashAlgorithm, const std::optional& label); }; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/cpp/cipher/OCBCipher.cpp b/packages/react-native-quick-crypto/cpp/cipher/OCBCipher.cpp index b2ca3dce9..cf86aeda1 100644 --- a/packages/react-native-quick-crypto/cpp/cipher/OCBCipher.cpp +++ b/packages/react-native-quick-crypto/cpp/cipher/OCBCipher.cpp @@ -9,7 +9,7 @@ namespace margelo::nitro::crypto { -void OCBCipher::init(const std::shared_ptr& key, const std::shared_ptr& iv, size_t tag_len) { +void OCBCipher::init(const ArrayBuffer& key, const ArrayBuffer& iv, size_t tag_len) { HybridCipher::init(key, iv); auth_tag_len = tag_len; @@ -22,7 +22,7 @@ void OCBCipher::init(const std::shared_ptr& key, const std::shared_ } } -std::shared_ptr OCBCipher::getAuthTag() { +ArrayBuffer OCBCipher::getAuthTag() { checkCtx(); if (!is_cipher) { throw std::runtime_error("getAuthTag can only be called during encryption."); @@ -32,19 +32,19 @@ std::shared_ptr OCBCipher::getAuthTag() { throw std::runtime_error("Failed to get OCB auth tag"); } uint8_t* raw_ptr = tag_buf.get(); - return std::make_shared(tag_buf.release(), auth_tag_len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(tag_buf.release(), auth_tag_len, [raw_ptr]() { delete[] raw_ptr; }); } -bool OCBCipher::setAuthTag(const std::shared_ptr& tag) { +bool OCBCipher::setAuthTag(const ArrayBuffer& tag) { checkCtx(); if (is_cipher) { throw std::runtime_error("setAuthTag can only be called during decryption."); } - size_t tag_len = tag->size(); + size_t tag_len = tag.size(); if (tag_len < 8 || tag_len > 16) { throw std::runtime_error("Invalid OCB tag length"); } - if (EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_AEAD_SET_TAG, tag_len, tag->data()) != 1) { + if (EVP_CIPHER_CTX_ctrl(ctx.get(), EVP_CTRL_AEAD_SET_TAG, tag_len, tag.data()) != 1) { throw std::runtime_error("Failed to set OCB auth tag"); } auth_tag_len = tag_len; diff --git a/packages/react-native-quick-crypto/cpp/cipher/OCBCipher.hpp b/packages/react-native-quick-crypto/cpp/cipher/OCBCipher.hpp index 2bef60414..d7a32ff09 100644 --- a/packages/react-native-quick-crypto/cpp/cipher/OCBCipher.hpp +++ b/packages/react-native-quick-crypto/cpp/cipher/OCBCipher.hpp @@ -6,11 +6,11 @@ namespace margelo::nitro::crypto { class OCBCipher : public HybridCipher { public: - OCBCipher() : HybridObject(TAG) {} - void init(const std::shared_ptr& key, const std::shared_ptr& iv, size_t tag_len = 16); + OCBCipher() = default; + void init(const ArrayBuffer& key, const ArrayBuffer& iv, size_t tag_len = 16); - std::shared_ptr getAuthTag() override; - bool setAuthTag(const std::shared_ptr& tag) override; + ArrayBuffer getAuthTag() override; + bool setAuthTag(const ArrayBuffer& tag) override; protected: size_t auth_tag_len = 16; diff --git a/packages/react-native-quick-crypto/cpp/cipher/XChaCha20Poly1305Cipher.cpp b/packages/react-native-quick-crypto/cpp/cipher/XChaCha20Poly1305Cipher.cpp index 40c6cdf5d..c0b9cd741 100644 --- a/packages/react-native-quick-crypto/cpp/cipher/XChaCha20Poly1305Cipher.cpp +++ b/packages/react-native-quick-crypto/cpp/cipher/XChaCha20Poly1305Cipher.cpp @@ -28,39 +28,39 @@ XChaCha20Poly1305Cipher::~XChaCha20Poly1305Cipher() { aad_.clear(); } -void XChaCha20Poly1305Cipher::init(const std::shared_ptr cipher_key, const std::shared_ptr iv) { - if (cipher_key->size() != kKeySize) { - throw std::runtime_error("XChaCha20-Poly1305 key must be 32 bytes, got " + std::to_string(cipher_key->size()) + " bytes"); +void XChaCha20Poly1305Cipher::init(const ArrayBuffer& cipher_key, const ArrayBuffer& iv) { + if (cipher_key.size() != kKeySize) { + throw std::runtime_error("XChaCha20-Poly1305 key must be 32 bytes, got " + std::to_string(cipher_key.size()) + " bytes"); } - if (iv->size() != kNonceSize) { - throw std::runtime_error("XChaCha20-Poly1305 nonce must be 24 bytes, got " + std::to_string(iv->size()) + " bytes"); + if (iv.size() != kNonceSize) { + throw std::runtime_error("XChaCha20-Poly1305 nonce must be 24 bytes, got " + std::to_string(iv.size()) + " bytes"); } - std::memcpy(key_, cipher_key->data(), kKeySize); - std::memcpy(nonce_, iv->data(), kNonceSize); + std::memcpy(key_, cipher_key.data(), kKeySize); + std::memcpy(nonce_, iv.data(), kNonceSize); data_buffer_.clear(); aad_.clear(); is_finalized = false; } -std::shared_ptr XChaCha20Poly1305Cipher::update(const std::shared_ptr& data) { +ArrayBuffer XChaCha20Poly1305Cipher::update(const ArrayBuffer& data) { checkNotFinalized(); #ifndef BLSALLOC_SODIUM throw std::runtime_error("XChaCha20Poly1305Cipher: libsodium must be enabled (BLSALLOC_SODIUM)"); #else - size_t data_len = data->size(); + size_t data_len = data.size(); size_t old_size = data_buffer_.size(); data_buffer_.resize(old_size + data_len); - std::memcpy(data_buffer_.data() + old_size, data->data(), data_len); + std::memcpy(data_buffer_.data() + old_size, dataOrEmpty(data), data_len); - return std::make_shared(nullptr, 0, nullptr); + return ArrayBuffer::empty(); #endif } -std::shared_ptr XChaCha20Poly1305Cipher::final() { +ArrayBuffer XChaCha20Poly1305Cipher::final() { checkNotFinalized(); #ifndef BLSALLOC_SODIUM throw std::runtime_error("XChaCha20Poly1305Cipher: libsodium must be enabled (BLSALLOC_SODIUM)"); @@ -80,11 +80,11 @@ std::shared_ptr XChaCha20Poly1305Cipher::final() { is_finalized = true; size_t ct_len = data_buffer_.size(); uint8_t* raw_ptr = ciphertext.get(); - return std::make_shared(ciphertext.release(), ct_len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(ciphertext.release(), ct_len, [raw_ptr]() { delete[] raw_ptr; }); } else { if (data_buffer_.empty()) { is_finalized = true; - return std::make_shared(nullptr, 0, nullptr); + return ArrayBuffer::empty(); } auto plaintext = std::make_unique(data_buffer_.size()); @@ -101,22 +101,22 @@ std::shared_ptr XChaCha20Poly1305Cipher::final() { is_finalized = true; size_t pt_len = data_buffer_.size(); uint8_t* raw_ptr = plaintext.get(); - return std::make_shared(plaintext.release(), pt_len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(plaintext.release(), pt_len, [raw_ptr]() { delete[] raw_ptr; }); } #endif } -bool XChaCha20Poly1305Cipher::setAAD(const std::shared_ptr& data, std::optional plaintextLength) { +bool XChaCha20Poly1305Cipher::setAAD(const ArrayBuffer& data, const std::optional& plaintextLength) { #ifndef BLSALLOC_SODIUM throw std::runtime_error("XChaCha20Poly1305Cipher: libsodium must be enabled (BLSALLOC_SODIUM)"); #else - aad_.resize(data->size()); - std::memcpy(aad_.data(), data->data(), data->size()); + aad_.resize(data.size()); + std::memcpy(aad_.data(), dataOrEmpty(data), data.size()); return true; #endif } -std::shared_ptr XChaCha20Poly1305Cipher::getAuthTag() { +ArrayBuffer XChaCha20Poly1305Cipher::getAuthTag() { #ifndef BLSALLOC_SODIUM throw std::runtime_error("XChaCha20Poly1305Cipher: libsodium must be enabled (BLSALLOC_SODIUM)"); #else @@ -130,11 +130,11 @@ std::shared_ptr XChaCha20Poly1305Cipher::getAuthTag() { auto tag_copy = std::make_unique(kTagSize); std::memcpy(tag_copy.get(), auth_tag_, kTagSize); uint8_t* raw_ptr = tag_copy.get(); - return std::make_shared(tag_copy.release(), kTagSize, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(tag_copy.release(), kTagSize, [raw_ptr]() { delete[] raw_ptr; }); #endif } -bool XChaCha20Poly1305Cipher::setAuthTag(const std::shared_ptr& tag) { +bool XChaCha20Poly1305Cipher::setAuthTag(const ArrayBuffer& tag) { #ifndef BLSALLOC_SODIUM throw std::runtime_error("XChaCha20Poly1305Cipher: libsodium must be enabled (BLSALLOC_SODIUM)"); #else @@ -142,11 +142,11 @@ bool XChaCha20Poly1305Cipher::setAuthTag(const std::shared_ptr& tag throw std::runtime_error("setAuthTag can only be called during decryption"); } - if (tag->size() != kTagSize) { - throw std::runtime_error("XChaCha20-Poly1305 tag must be 16 bytes, got " + std::to_string(tag->size()) + " bytes"); + if (tag.size() != kTagSize) { + throw std::runtime_error("XChaCha20-Poly1305 tag must be 16 bytes, got " + std::to_string(tag.size()) + " bytes"); } - std::memcpy(auth_tag_, tag->data(), kTagSize); + std::memcpy(auth_tag_, tag.data(), kTagSize); return true; #endif } diff --git a/packages/react-native-quick-crypto/cpp/cipher/XChaCha20Poly1305Cipher.hpp b/packages/react-native-quick-crypto/cpp/cipher/XChaCha20Poly1305Cipher.hpp index eb3f88297..c446fd6c4 100644 --- a/packages/react-native-quick-crypto/cpp/cipher/XChaCha20Poly1305Cipher.hpp +++ b/packages/react-native-quick-crypto/cpp/cipher/XChaCha20Poly1305Cipher.hpp @@ -16,15 +16,15 @@ namespace margelo::nitro::crypto { class XChaCha20Poly1305Cipher : public HybridCipher { public: - XChaCha20Poly1305Cipher() : HybridObject(TAG) {} + XChaCha20Poly1305Cipher() = default; ~XChaCha20Poly1305Cipher(); - void init(const std::shared_ptr cipher_key, const std::shared_ptr iv) override; - std::shared_ptr update(const std::shared_ptr& data) override; - std::shared_ptr final() override; - bool setAAD(const std::shared_ptr& data, std::optional plaintextLength) override; - std::shared_ptr getAuthTag() override; - bool setAuthTag(const std::shared_ptr& tag) override; + void init(const ArrayBuffer& cipher_key, const ArrayBuffer& iv) override; + ArrayBuffer update(const ArrayBuffer& data) override; + ArrayBuffer final() override; + bool setAAD(const ArrayBuffer& data, const std::optional& plaintextLength) override; + ArrayBuffer getAuthTag() override; + bool setAuthTag(const ArrayBuffer& tag) override; bool setAutoPadding(bool autoPad) override; private: diff --git a/packages/react-native-quick-crypto/cpp/cipher/XSalsa20Cipher.cpp b/packages/react-native-quick-crypto/cpp/cipher/XSalsa20Cipher.cpp index 4533e3b47..c36a82d67 100644 --- a/packages/react-native-quick-crypto/cpp/cipher/XSalsa20Cipher.cpp +++ b/packages/react-native-quick-crypto/cpp/cipher/XSalsa20Cipher.cpp @@ -12,21 +12,21 @@ namespace margelo::nitro::crypto { /** * Initialize the cipher with a key and a nonce (using iv argument as nonce) */ -void XSalsa20Cipher::init(const std::shared_ptr cipher_key, const std::shared_ptr iv) { +void XSalsa20Cipher::init(const ArrayBuffer& cipher_key, const ArrayBuffer& iv) { // Validate key size - if (cipher_key->size() < crypto_stream_KEYBYTES) { + if (cipher_key.size() < crypto_stream_KEYBYTES) { throw std::runtime_error("XSalsa20 key too short: expected " + std::to_string(crypto_stream_KEYBYTES) + " bytes, got " + - std::to_string(cipher_key->size()) + " bytes."); + std::to_string(cipher_key.size()) + " bytes."); } // Validate nonce size - if (iv->size() < crypto_stream_NONCEBYTES) { + if (iv.size() < crypto_stream_NONCEBYTES) { throw std::runtime_error("XSalsa20 nonce too short: expected " + std::to_string(crypto_stream_NONCEBYTES) + " bytes, got " + - std::to_string(iv->size()) + " bytes."); + std::to_string(iv.size()) + " bytes."); } // Copy key and nonce data - std::memcpy(key, cipher_key->data(), crypto_stream_KEYBYTES); - std::memcpy(nonce, iv->data(), crypto_stream_NONCEBYTES); + std::memcpy(key, cipher_key.data(), crypto_stream_KEYBYTES); + std::memcpy(nonce, iv.data(), crypto_stream_NONCEBYTES); // Reset streaming state so a re-init'd cipher does not accidentally reuse // keystream bytes from a previous session. @@ -49,20 +49,20 @@ void XSalsa20Cipher::init(const std::shared_ptr cipher_key, const s * block, XOR the requested prefix, and stash the unused suffix for the * next update() call. */ -std::shared_ptr XSalsa20Cipher::update(const std::shared_ptr& data) { +ArrayBuffer XSalsa20Cipher::update(const ArrayBuffer& data) { checkNotFinalized(); #ifndef BLSALLOC_SODIUM throw std::runtime_error("XSalsa20Cipher: libsodium must be enabled to use this cipher (BLSALLOC_SODIUM is not defined)."); #else - const std::size_t data_size = data->size(); + const std::size_t data_size = data.size(); if (data_size == 0) { - return std::make_shared(nullptr, 0, nullptr); + return ArrayBuffer::empty(); } // Owning buffer: prevents leaking `output` if we throw on the way out. auto output = std::make_unique(data_size); - const uint8_t* input = data->data(); + const uint8_t* input = dataOrEmpty(data); std::size_t pos = 0; // (1) Drain any unused keystream from the previous update()'s tail block. @@ -107,20 +107,20 @@ std::shared_ptr XSalsa20Cipher::update(const std::shared_ptr(raw, data_size, [=]() { delete[] raw; }); + return ArrayBuffer::wrap(raw, data_size, [=]() { delete[] raw; }); #endif } /** * xsalsa20 does not have a final step, returns empty buffer */ -std::shared_ptr XSalsa20Cipher::final() { +ArrayBuffer XSalsa20Cipher::final() { checkNotFinalized(); #ifndef BLSALLOC_SODIUM throw std::runtime_error("XSalsa20Cipher: libsodium must be enabled to use this cipher (BLSALLOC_SODIUM is not defined)."); #else is_finalized = true; - return std::make_shared(nullptr, 0, nullptr); + return ArrayBuffer::empty(); #endif } diff --git a/packages/react-native-quick-crypto/cpp/cipher/XSalsa20Cipher.hpp b/packages/react-native-quick-crypto/cpp/cipher/XSalsa20Cipher.hpp index 54fec370f..60e33bf46 100644 --- a/packages/react-native-quick-crypto/cpp/cipher/XSalsa20Cipher.hpp +++ b/packages/react-native-quick-crypto/cpp/cipher/XSalsa20Cipher.hpp @@ -19,7 +19,7 @@ namespace margelo::nitro::crypto { class XSalsa20Cipher : public HybridCipher { public: - XSalsa20Cipher() : HybridObject(TAG) {} + XSalsa20Cipher() = default; ~XSalsa20Cipher() override { // Wipe key material and any cached keystream bytes before the heap is // returned. Without this the secret-bearing bytes persist on the heap @@ -30,9 +30,9 @@ class XSalsa20Cipher : public HybridCipher { secureZero(leftover_keystream); } - void init(const std::shared_ptr cipher_key, const std::shared_ptr iv) override; - std::shared_ptr update(const std::shared_ptr& data) override; - std::shared_ptr final() override; + void init(const ArrayBuffer& cipher_key, const ArrayBuffer& iv) override; + ArrayBuffer update(const ArrayBuffer& data) override; + ArrayBuffer final() override; private: // Salsa20 (and therefore XSalsa20) processes the keystream in 64-byte blocks. diff --git a/packages/react-native-quick-crypto/cpp/cipher/XSalsa20Poly1305Cipher.cpp b/packages/react-native-quick-crypto/cpp/cipher/XSalsa20Poly1305Cipher.cpp index 4faa9b2a5..befdb3a50 100644 --- a/packages/react-native-quick-crypto/cpp/cipher/XSalsa20Poly1305Cipher.cpp +++ b/packages/react-native-quick-crypto/cpp/cipher/XSalsa20Poly1305Cipher.cpp @@ -19,38 +19,38 @@ XSalsa20Poly1305Cipher::~XSalsa20Poly1305Cipher() { data_buffer_.clear(); } -void XSalsa20Poly1305Cipher::init(const std::shared_ptr cipher_key, const std::shared_ptr iv) { - if (cipher_key->size() != kKeySize) { - throw std::runtime_error("XSalsa20-Poly1305 key must be 32 bytes, got " + std::to_string(cipher_key->size()) + " bytes"); +void XSalsa20Poly1305Cipher::init(const ArrayBuffer& cipher_key, const ArrayBuffer& iv) { + if (cipher_key.size() != kKeySize) { + throw std::runtime_error("XSalsa20-Poly1305 key must be 32 bytes, got " + std::to_string(cipher_key.size()) + " bytes"); } - if (iv->size() != kNonceSize) { - throw std::runtime_error("XSalsa20-Poly1305 nonce must be 24 bytes, got " + std::to_string(iv->size()) + " bytes"); + if (iv.size() != kNonceSize) { + throw std::runtime_error("XSalsa20-Poly1305 nonce must be 24 bytes, got " + std::to_string(iv.size()) + " bytes"); } - std::memcpy(key_, cipher_key->data(), kKeySize); - std::memcpy(nonce_, iv->data(), kNonceSize); + std::memcpy(key_, cipher_key.data(), kKeySize); + std::memcpy(nonce_, iv.data(), kNonceSize); data_buffer_.clear(); is_finalized = false; } -std::shared_ptr XSalsa20Poly1305Cipher::update(const std::shared_ptr& data) { +ArrayBuffer XSalsa20Poly1305Cipher::update(const ArrayBuffer& data) { checkNotFinalized(); #ifndef BLSALLOC_SODIUM throw std::runtime_error("XSalsa20Poly1305Cipher: libsodium must be enabled (BLSALLOC_SODIUM)"); #else - size_t data_len = data->size(); + size_t data_len = data.size(); size_t old_size = data_buffer_.size(); data_buffer_.resize(old_size + data_len); - std::memcpy(data_buffer_.data() + old_size, data->data(), data_len); + std::memcpy(data_buffer_.data() + old_size, dataOrEmpty(data), data_len); - return std::make_shared(nullptr, 0, nullptr); + return ArrayBuffer::empty(); #endif } -std::shared_ptr XSalsa20Poly1305Cipher::final() { +ArrayBuffer XSalsa20Poly1305Cipher::final() { checkNotFinalized(); #ifndef BLSALLOC_SODIUM throw std::runtime_error("XSalsa20Poly1305Cipher: libsodium must be enabled (BLSALLOC_SODIUM)"); @@ -68,11 +68,11 @@ std::shared_ptr XSalsa20Poly1305Cipher::final() { is_finalized = true; size_t ct_len = data_buffer_.size(); uint8_t* raw_ptr = ciphertext.get(); - return std::make_shared(ciphertext.release(), ct_len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(ciphertext.release(), ct_len, [raw_ptr]() { delete[] raw_ptr; }); } else { if (data_buffer_.empty()) { is_finalized = true; - return std::make_shared(nullptr, 0, nullptr); + return ArrayBuffer::empty(); } auto plaintext = std::make_unique(data_buffer_.size()); @@ -87,16 +87,16 @@ std::shared_ptr XSalsa20Poly1305Cipher::final() { is_finalized = true; size_t pt_len = data_buffer_.size(); uint8_t* raw_ptr = plaintext.get(); - return std::make_shared(plaintext.release(), pt_len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(plaintext.release(), pt_len, [raw_ptr]() { delete[] raw_ptr; }); } #endif } -bool XSalsa20Poly1305Cipher::setAAD(const std::shared_ptr& data, std::optional plaintextLength) { +bool XSalsa20Poly1305Cipher::setAAD(const ArrayBuffer& data, const std::optional& plaintextLength) { throw std::runtime_error("AAD is not supported for xsalsa20-poly1305 (use xchacha20-poly1305 instead)"); } -std::shared_ptr XSalsa20Poly1305Cipher::getAuthTag() { +ArrayBuffer XSalsa20Poly1305Cipher::getAuthTag() { #ifndef BLSALLOC_SODIUM throw std::runtime_error("XSalsa20Poly1305Cipher: libsodium must be enabled (BLSALLOC_SODIUM)"); #else @@ -110,11 +110,11 @@ std::shared_ptr XSalsa20Poly1305Cipher::getAuthTag() { auto tag_copy = std::make_unique(kTagSize); std::memcpy(tag_copy.get(), auth_tag_, kTagSize); uint8_t* raw_ptr = tag_copy.get(); - return std::make_shared(tag_copy.release(), kTagSize, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(tag_copy.release(), kTagSize, [raw_ptr]() { delete[] raw_ptr; }); #endif } -bool XSalsa20Poly1305Cipher::setAuthTag(const std::shared_ptr& tag) { +bool XSalsa20Poly1305Cipher::setAuthTag(const ArrayBuffer& tag) { #ifndef BLSALLOC_SODIUM throw std::runtime_error("XSalsa20Poly1305Cipher: libsodium must be enabled (BLSALLOC_SODIUM)"); #else @@ -122,11 +122,11 @@ bool XSalsa20Poly1305Cipher::setAuthTag(const std::shared_ptr& tag) throw std::runtime_error("setAuthTag can only be called during decryption"); } - if (tag->size() != kTagSize) { - throw std::runtime_error("XSalsa20-Poly1305 tag must be 16 bytes, got " + std::to_string(tag->size()) + " bytes"); + if (tag.size() != kTagSize) { + throw std::runtime_error("XSalsa20-Poly1305 tag must be 16 bytes, got " + std::to_string(tag.size()) + " bytes"); } - std::memcpy(auth_tag_, tag->data(), kTagSize); + std::memcpy(auth_tag_, tag.data(), kTagSize); return true; #endif } diff --git a/packages/react-native-quick-crypto/cpp/cipher/XSalsa20Poly1305Cipher.hpp b/packages/react-native-quick-crypto/cpp/cipher/XSalsa20Poly1305Cipher.hpp index a8cb55c2f..769e2de04 100644 --- a/packages/react-native-quick-crypto/cpp/cipher/XSalsa20Poly1305Cipher.hpp +++ b/packages/react-native-quick-crypto/cpp/cipher/XSalsa20Poly1305Cipher.hpp @@ -16,15 +16,15 @@ namespace margelo::nitro::crypto { class XSalsa20Poly1305Cipher : public HybridCipher { public: - XSalsa20Poly1305Cipher() : HybridObject(TAG) {} + XSalsa20Poly1305Cipher() = default; ~XSalsa20Poly1305Cipher(); - void init(const std::shared_ptr cipher_key, const std::shared_ptr iv) override; - std::shared_ptr update(const std::shared_ptr& data) override; - std::shared_ptr final() override; - bool setAAD(const std::shared_ptr& data, std::optional plaintextLength) override; - std::shared_ptr getAuthTag() override; - bool setAuthTag(const std::shared_ptr& tag) override; + void init(const ArrayBuffer& cipher_key, const ArrayBuffer& iv) override; + ArrayBuffer update(const ArrayBuffer& data) override; + ArrayBuffer final() override; + bool setAAD(const ArrayBuffer& data, const std::optional& plaintextLength) override; + ArrayBuffer getAuthTag() override; + bool setAuthTag(const ArrayBuffer& tag) override; bool setAutoPadding(bool autoPad) override; private: diff --git a/packages/react-native-quick-crypto/cpp/dh/HybridDhKeyPair.cpp b/packages/react-native-quick-crypto/cpp/dh/HybridDhKeyPair.cpp index 774d5e7e0..f854aefb3 100644 --- a/packages/react-native-quick-crypto/cpp/dh/HybridDhKeyPair.cpp +++ b/packages/react-native-quick-crypto/cpp/dh/HybridDhKeyPair.cpp @@ -28,16 +28,17 @@ void HybridDhKeyPair::setPrimeLength(double primeLength) { primeLength_ = static_cast(primeLength); } -void HybridDhKeyPair::setPrime(const std::shared_ptr& prime) { - prime_.assign(prime->data(), prime->data() + prime->size()); +void HybridDhKeyPair::setPrime(const ArrayBuffer& prime) { + prime_.assign(dataOrEmpty(prime), dataOrEmpty(prime) + prime.size()); } void HybridDhKeyPair::setGenerator(double generator) { generator_ = static_cast(generator); } -std::shared_ptr> HybridDhKeyPair::generateKeyPair() { - return Promise::async([this]() { this->generateKeyPairSync(); }); +Promise HybridDhKeyPair::generateKeyPair() { + auto self = this->shared_cast(); + return Promise::async([self]() { self->generateKeyPairSync(); }); } void HybridDhKeyPair::generateKeyPairSync() { @@ -128,7 +129,7 @@ void HybridDhKeyPair::generateKeyPairSync() { pkey_.reset(raw_pkey); } -std::shared_ptr HybridDhKeyPair::getPublicKey() { +ArrayBuffer HybridDhKeyPair::getPublicKey() { if (!pkey_) { throw std::runtime_error("DH: no key pair generated"); } @@ -151,7 +152,7 @@ std::shared_ptr HybridDhKeyPair::getPublicKey() { return ToNativeArrayBuffer(derData); } -std::shared_ptr HybridDhKeyPair::getPrivateKey() { +ArrayBuffer HybridDhKeyPair::getPrivateKey() { if (!pkey_) { throw std::runtime_error("DH: no key pair generated"); } diff --git a/packages/react-native-quick-crypto/cpp/dh/HybridDhKeyPair.hpp b/packages/react-native-quick-crypto/cpp/dh/HybridDhKeyPair.hpp index 671384c80..12c8050f7 100644 --- a/packages/react-native-quick-crypto/cpp/dh/HybridDhKeyPair.hpp +++ b/packages/react-native-quick-crypto/cpp/dh/HybridDhKeyPair.hpp @@ -6,24 +6,24 @@ #include #include -#include "HybridDhKeyPairSpec.hpp" #include "QuickCryptoUtils.hpp" +#include namespace margelo::nitro::crypto { class HybridDhKeyPair : public HybridDhKeyPairSpec { public: - HybridDhKeyPair() : HybridObject(TAG) {} + HybridDhKeyPair() = default; ~HybridDhKeyPair() override = default; public: - std::shared_ptr> generateKeyPair() override; + Promise generateKeyPair() override; void generateKeyPairSync() override; void setPrimeLength(double primeLength) override; - void setPrime(const std::shared_ptr& prime) override; + void setPrime(const ArrayBuffer& prime) override; void setGenerator(double generator) override; - std::shared_ptr getPublicKey() override; - std::shared_ptr getPrivateKey() override; + ArrayBuffer getPublicKey() override; + ArrayBuffer getPrivateKey() override; private: int primeLength_ = 0; diff --git a/packages/react-native-quick-crypto/cpp/dh/HybridDiffieHellman.cpp b/packages/react-native-quick-crypto/cpp/dh/HybridDiffieHellman.cpp index b0adab98e..b3704aea8 100644 --- a/packages/react-native-quick-crypto/cpp/dh/HybridDiffieHellman.cpp +++ b/packages/react-native-quick-crypto/cpp/dh/HybridDiffieHellman.cpp @@ -22,7 +22,7 @@ static constexpr int kMinDHPrimeBits = 2048; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" -void HybridDiffieHellman::init(const std::shared_ptr& prime, const std::shared_ptr& generator) { +void HybridDiffieHellman::init(const ArrayBuffer& prime, const ArrayBuffer& generator) { // Create DH structure DH_ptr dh(DH_new(), DH_free); if (!dh) { @@ -30,8 +30,8 @@ void HybridDiffieHellman::init(const std::shared_ptr& prime, const } // Convert prime and generator to BIGNUMs - BIGNUM* p = BN_bin2bn(prime->data(), static_cast(prime->size()), nullptr); - BIGNUM* g = BN_bin2bn(generator->data(), static_cast(generator->size()), nullptr); + BIGNUM* p = BN_bin2bn(dataOrEmpty(prime), static_cast(prime.size()), nullptr); + BIGNUM* g = BN_bin2bn(dataOrEmpty(generator), static_cast(generator.size()), nullptr); if (!p || !g) { if (p) @@ -98,7 +98,7 @@ void HybridDiffieHellman::initWithSize(double primeLength, double generator) { _pkey.reset(params); } -std::shared_ptr HybridDiffieHellman::generateKeys() { +ArrayBuffer HybridDiffieHellman::generateKeys() { ensureInitialized(); // EVP_PKEY_get1_DH returns a mutable, ref-counted DH copy so we can @@ -126,7 +126,7 @@ std::shared_ptr HybridDiffieHellman::generateKeys() { return getPublicKey(); } -std::shared_ptr HybridDiffieHellman::computeSecret(const std::shared_ptr& otherPublicKey) { +ArrayBuffer HybridDiffieHellman::computeSecret(const ArrayBuffer& otherPublicKey) { ensureInitialized(); const DH* ourDh = getDH(); @@ -140,7 +140,7 @@ std::shared_ptr HybridDiffieHellman::computeSecret(const std::share // Match the ncrypto pattern (DHPointer::checkPublicKey) and Node.js error // surface so callers see why the key was rejected. { - BN_ptr peerPubCheck(BN_bin2bn(otherPublicKey->data(), static_cast(otherPublicKey->size()), nullptr), BN_free); + BN_ptr peerPubCheck(BN_bin2bn(dataOrEmpty(otherPublicKey), static_cast(otherPublicKey.size()), nullptr), BN_free); if (!peerPubCheck) { throw std::runtime_error("DiffieHellman: failed to parse peer public key"); } @@ -171,7 +171,7 @@ std::shared_ptr HybridDiffieHellman::computeSecret(const std::share // Duplicate parameters for peer BIGNUM* peerP = BN_dup(p); BIGNUM* peerG = BN_dup(g); - BIGNUM* peerPubKey = BN_bin2bn(otherPublicKey->data(), static_cast(otherPublicKey->size()), nullptr); + BIGNUM* peerPubKey = BN_bin2bn(dataOrEmpty(otherPublicKey), static_cast(otherPublicKey.size()), nullptr); if (!peerP || !peerG || !peerPubKey) { if (peerP) @@ -241,7 +241,7 @@ std::shared_ptr HybridDiffieHellman::computeSecret(const std::share return ToNativeArrayBuffer(secret); } -std::shared_ptr HybridDiffieHellman::getPrime() { +ArrayBuffer HybridDiffieHellman::getPrime() { ensureInitialized(); const DH* dh = getDH(); @@ -258,7 +258,7 @@ std::shared_ptr HybridDiffieHellman::getPrime() { return ToNativeArrayBuffer(buf); } -std::shared_ptr HybridDiffieHellman::getGenerator() { +ArrayBuffer HybridDiffieHellman::getGenerator() { ensureInitialized(); const DH* dh = getDH(); @@ -275,7 +275,7 @@ std::shared_ptr HybridDiffieHellman::getGenerator() { return ToNativeArrayBuffer(buf); } -std::shared_ptr HybridDiffieHellman::getPublicKey() { +ArrayBuffer HybridDiffieHellman::getPublicKey() { ensureInitialized(); const DH* dh = getDH(); @@ -292,7 +292,7 @@ std::shared_ptr HybridDiffieHellman::getPublicKey() { return ToNativeArrayBuffer(buf); } -std::shared_ptr HybridDiffieHellman::getPrivateKey() { +ArrayBuffer HybridDiffieHellman::getPrivateKey() { ensureInitialized(); const DH* dh = getDH(); @@ -309,7 +309,7 @@ std::shared_ptr HybridDiffieHellman::getPrivateKey() { return ToNativeArrayBuffer(buf); } -void HybridDiffieHellman::setPublicKey(const std::shared_ptr& publicKey) { +void HybridDiffieHellman::setPublicKey(const ArrayBuffer& publicKey) { ensureInitialized(); const DH* dh = getDH(); @@ -351,7 +351,7 @@ void HybridDiffieHellman::setPublicKey(const std::shared_ptr& publi } // Convert new public key - BIGNUM* newPub = BN_bin2bn(publicKey->data(), static_cast(publicKey->size()), nullptr); + BIGNUM* newPub = BN_bin2bn(dataOrEmpty(publicKey), static_cast(publicKey.size()), nullptr); BIGNUM* newPriv = oldPriv ? BN_dup(oldPriv) : nullptr; if (!newPub) { @@ -381,7 +381,7 @@ void HybridDiffieHellman::setPublicKey(const std::shared_ptr& publi _pkey = std::move(newPkey); } -void HybridDiffieHellman::setPrivateKey(const std::shared_ptr& privateKey) { +void HybridDiffieHellman::setPrivateKey(const ArrayBuffer& privateKey) { ensureInitialized(); const DH* dh = getDH(); @@ -424,7 +424,7 @@ void HybridDiffieHellman::setPrivateKey(const std::shared_ptr& priv // Convert new private key BIGNUM* newPub = oldPub ? BN_dup(oldPub) : nullptr; - BIGNUM* newPriv = BN_bin2bn(privateKey->data(), static_cast(privateKey->size()), nullptr); + BIGNUM* newPriv = BN_bin2bn(dataOrEmpty(privateKey), static_cast(privateKey.size()), nullptr); if (!newPriv) { if (newPub) diff --git a/packages/react-native-quick-crypto/cpp/dh/HybridDiffieHellman.hpp b/packages/react-native-quick-crypto/cpp/dh/HybridDiffieHellman.hpp index 8d77a1cf1..0498b2c37 100644 --- a/packages/react-native-quick-crypto/cpp/dh/HybridDiffieHellman.hpp +++ b/packages/react-native-quick-crypto/cpp/dh/HybridDiffieHellman.hpp @@ -6,7 +6,7 @@ #include #include -#include "HybridDiffieHellmanSpec.hpp" +#include namespace margelo::nitro::crypto { @@ -17,19 +17,19 @@ using EVP_PKEY_ptr = std::unique_ptr; class HybridDiffieHellman : public HybridDiffieHellmanSpec { public: - HybridDiffieHellman() : HybridObject("DiffieHellman"), _pkey(nullptr, EVP_PKEY_free) {} + HybridDiffieHellman() : _pkey(nullptr, EVP_PKEY_free) {} virtual ~HybridDiffieHellman() = default; - void init(const std::shared_ptr& prime, const std::shared_ptr& generator) override; + void init(const ArrayBuffer& prime, const ArrayBuffer& generator) override; void initWithSize(double primeLength, double generator) override; - std::shared_ptr generateKeys() override; - std::shared_ptr computeSecret(const std::shared_ptr& otherPublicKey) override; - std::shared_ptr getPrime() override; - std::shared_ptr getGenerator() override; - std::shared_ptr getPublicKey() override; - std::shared_ptr getPrivateKey() override; - void setPublicKey(const std::shared_ptr& publicKey) override; - void setPrivateKey(const std::shared_ptr& privateKey) override; + ArrayBuffer generateKeys() override; + ArrayBuffer computeSecret(const ArrayBuffer& otherPublicKey) override; + ArrayBuffer getPrime() override; + ArrayBuffer getGenerator() override; + ArrayBuffer getPublicKey() override; + ArrayBuffer getPrivateKey() override; + void setPublicKey(const ArrayBuffer& publicKey) override; + void setPrivateKey(const ArrayBuffer& privateKey) override; double getVerifyError() override; private: diff --git a/packages/react-native-quick-crypto/cpp/dsa/HybridDsaKeyPair.cpp b/packages/react-native-quick-crypto/cpp/dsa/HybridDsaKeyPair.cpp index 1a1d1e556..266439cf0 100644 --- a/packages/react-native-quick-crypto/cpp/dsa/HybridDsaKeyPair.cpp +++ b/packages/react-native-quick-crypto/cpp/dsa/HybridDsaKeyPair.cpp @@ -21,8 +21,9 @@ void HybridDsaKeyPair::setDivisorLength(double divisorLength) { divisorLength_ = static_cast(divisorLength); } -std::shared_ptr> HybridDsaKeyPair::generateKeyPair() { - return Promise::async([this]() { this->generateKeyPairSync(); }); +Promise HybridDsaKeyPair::generateKeyPair() { + auto self = this->shared_cast(); + return Promise::async([self]() { self->generateKeyPairSync(); }); } void HybridDsaKeyPair::generateKeyPairSync() { @@ -79,7 +80,7 @@ void HybridDsaKeyPair::generateKeyPairSync() { pkey_.reset(raw_pkey); } -std::shared_ptr HybridDsaKeyPair::getPublicKey() { +ArrayBuffer HybridDsaKeyPair::getPublicKey() { if (!pkey_) { throw std::runtime_error("DSA: no key pair generated"); } @@ -102,7 +103,7 @@ std::shared_ptr HybridDsaKeyPair::getPublicKey() { return ToNativeArrayBuffer(derData); } -std::shared_ptr HybridDsaKeyPair::getPrivateKey() { +ArrayBuffer HybridDsaKeyPair::getPrivateKey() { if (!pkey_) { throw std::runtime_error("DSA: no key pair generated"); } diff --git a/packages/react-native-quick-crypto/cpp/dsa/HybridDsaKeyPair.hpp b/packages/react-native-quick-crypto/cpp/dsa/HybridDsaKeyPair.hpp index 646291b81..ecb3b3a62 100644 --- a/packages/react-native-quick-crypto/cpp/dsa/HybridDsaKeyPair.hpp +++ b/packages/react-native-quick-crypto/cpp/dsa/HybridDsaKeyPair.hpp @@ -3,23 +3,23 @@ #include #include -#include "HybridDsaKeyPairSpec.hpp" #include "QuickCryptoUtils.hpp" +#include namespace margelo::nitro::crypto { class HybridDsaKeyPair : public HybridDsaKeyPairSpec { public: - HybridDsaKeyPair() : HybridObject(TAG) {} + HybridDsaKeyPair() = default; ~HybridDsaKeyPair() override = default; public: - std::shared_ptr> generateKeyPair() override; + Promise generateKeyPair() override; void generateKeyPairSync() override; void setModulusLength(double modulusLength) override; void setDivisorLength(double divisorLength) override; - std::shared_ptr getPublicKey() override; - std::shared_ptr getPrivateKey() override; + ArrayBuffer getPublicKey() override; + ArrayBuffer getPrivateKey() override; private: int modulusLength_ = 0; diff --git a/packages/react-native-quick-crypto/cpp/ec/HybridEcKeyPair.cpp b/packages/react-native-quick-crypto/cpp/ec/HybridEcKeyPair.cpp index 612534343..a7d5163c1 100644 --- a/packages/react-native-quick-crypto/cpp/ec/HybridEcKeyPair.cpp +++ b/packages/react-native-quick-crypto/cpp/ec/HybridEcKeyPair.cpp @@ -26,12 +26,11 @@ #include "HybridEcKeyPair.hpp" #include "QuickCryptoUtils.hpp" -using margelo::nitro::NativeArrayBuffer; - namespace margelo::nitro::crypto { -std::shared_ptr> HybridEcKeyPair::generateKeyPair() { - return Promise::async([this]() { this->generateKeyPairSync(); }); +Promise HybridEcKeyPair::generateKeyPair() { + auto self = this->shared_cast(); + return Promise::async([self]() { self->generateKeyPairSync(); }); } void HybridEcKeyPair::generateKeyPairSync() { @@ -105,9 +104,8 @@ void HybridEcKeyPair::generateKeyPairSync() { this->pkey_.reset(raw_pkey); } -KeyObject HybridEcKeyPair::importKey(const std::string& format, const std::shared_ptr& keyData, - const std::string& /* algorithm */, bool /* extractable */, - const std::vector& /* keyUsages */) { +KeyObject HybridEcKeyPair::importKey(const std::string& format, const ArrayBuffer& keyData, const std::string& /* algorithm */, + bool /* extractable */, const std::vector& /* keyUsages */) { // Clean up any existing key this->pkey_.reset(); // Reset curve state to avoid interference between different uses @@ -118,18 +116,18 @@ KeyObject HybridEcKeyPair::importKey(const std::string& format, const std::share throw std::runtime_error("Only DER format is supported for key import"); } - const unsigned char* keyPtr = static_cast(keyData->data()); - size_t keyLen = keyData->size(); + const unsigned char* keyPtr = static_cast(dataOrEmpty(keyData)); + size_t keyLen = keyData.size(); // Try to import as public key first (SPKI format) EVP_PKEY* pkey = d2i_PUBKEY(nullptr, &keyPtr, keyLen); if (!pkey) { // Reset pointer and try as private key (PKCS8 format) - keyPtr = static_cast(keyData->data()); + keyPtr = static_cast(dataOrEmpty(keyData)); // Try PKCS8 format for private keys - BIO* pkcs8_bio = BIO_new_mem_buf(keyData->data(), static_cast(keyData->size())); + BIO* pkcs8_bio = BIO_new_mem_buf(dataOrEmpty(keyData), static_cast(keyData.size())); if (pkcs8_bio) { PKCS8_PRIV_KEY_INFO* p8inf = d2i_PKCS8_PRIV_KEY_INFO_bio(pkcs8_bio, nullptr); if (p8inf != nullptr) { @@ -138,7 +136,7 @@ KeyObject HybridEcKeyPair::importKey(const std::string& format, const std::share BIO_free(pkcs8_bio); if (pkcs8_pkey != nullptr) { this->pkey_.reset(pkcs8_pkey); - KeyObject keyObj; + KeyObject keyObj(false); return keyObj; } } @@ -146,13 +144,13 @@ KeyObject HybridEcKeyPair::importKey(const std::string& format, const std::share } // Try to parse as SPKI (public key) with BIO - BIO* spki_bio = BIO_new_mem_buf(keyData->data(), static_cast(keyData->size())); + BIO* spki_bio = BIO_new_mem_buf(dataOrEmpty(keyData), static_cast(keyData.size())); if (spki_bio) { EVP_PKEY* spki_pkey = d2i_PUBKEY_bio(spki_bio, nullptr); BIO_free(spki_bio); if (spki_pkey != nullptr) { this->pkey_.reset(spki_pkey); - KeyObject keyObj; + KeyObject keyObj(false); return keyObj; } } @@ -164,11 +162,11 @@ KeyObject HybridEcKeyPair::importKey(const std::string& format, const std::share // Return a placeholder KeyObject - this would need proper implementation // For now, we just need the key imported into this->pkey for sign/verify - KeyObject keyObj; + KeyObject keyObj(false); return keyObj; } -std::shared_ptr HybridEcKeyPair::exportKey(const KeyObject& key, const std::string& format) { +ArrayBuffer HybridEcKeyPair::exportKey(const KeyObject& key, const std::string& format) { // Suppress unused parameter warning (void)key; @@ -246,7 +244,7 @@ std::shared_ptr HybridEcKeyPair::exportKey(const KeyObject& key, co throw std::runtime_error("Unsupported export format: " + format); } -std::shared_ptr HybridEcKeyPair::getPublicKey() { +ArrayBuffer HybridEcKeyPair::getPublicKey() { this->checkKeyPair(); // Export as DER format using direct OpenSSL calls @@ -270,7 +268,7 @@ std::shared_ptr HybridEcKeyPair::getPublicKey() { return ToNativeArrayBuffer(derData); } -std::shared_ptr HybridEcKeyPair::getPrivateKey() { +ArrayBuffer HybridEcKeyPair::getPrivateKey() { if (!this->pkey_) { throw std::runtime_error("No private key available"); } @@ -320,7 +318,7 @@ int HybridEcKeyPair::GetCurveFromName(const char* name) { return nid; } -std::shared_ptr HybridEcKeyPair::sign(const std::shared_ptr& data, const std::string& hashAlgorithm) { +ArrayBuffer HybridEcKeyPair::sign(const ArrayBuffer& data, const std::string& hashAlgorithm) { this->checkKeyPair(); // Get the hash algorithm EVP_MD @@ -349,7 +347,7 @@ std::shared_ptr HybridEcKeyPair::sign(const std::shared_ptrdata(), data->size()) <= 0) { + if (EVP_DigestSignUpdate(md_ctx.get(), dataOrEmpty(data), data.size()) <= 0) { throw std::runtime_error("Failed to update ECDSA signing with data"); } @@ -381,11 +379,10 @@ std::shared_ptr HybridEcKeyPair::sign(const std::shared_ptr(p1363_buf.release(), 2 * n, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(p1363_buf.release(), 2 * n, [raw_ptr]() { delete[] raw_ptr; }); } -bool HybridEcKeyPair::verify(const std::shared_ptr& data, const std::shared_ptr& signature, - const std::string& hashAlgorithm) { +bool HybridEcKeyPair::verify(const ArrayBuffer& data, const ArrayBuffer& signature, const std::string& hashAlgorithm) { this->checkKeyPair(); // Get the hash algorithm EVP_MD @@ -414,7 +411,7 @@ bool HybridEcKeyPair::verify(const std::shared_ptr& data, const std } // Update with data - if (EVP_DigestVerifyUpdate(md_ctx.get(), data->data(), data->size()) <= 0) { + if (EVP_DigestVerifyUpdate(md_ctx.get(), dataOrEmpty(data), data.size()) <= 0) { throw std::runtime_error("Failed to update ECDSA verification with data"); } @@ -424,8 +421,8 @@ bool HybridEcKeyPair::verify(const std::shared_ptr& data, const std // passed through unchanged. This matches what every other ECDSA verify // wrapper (Node's, ncrypto's) does and is robust because well-formed DER // ECDSA signatures are never exactly 2*n bytes for the curves we support. - const unsigned char* sig_data = static_cast(signature->data()); - size_t sig_len = signature->size(); + const unsigned char* sig_data = static_cast(dataOrEmpty(signature)); + size_t sig_len = signature.size(); std::unique_ptr der_sig_buf; unsigned int n = getBytesOfRS(this->pkey_.get()); diff --git a/packages/react-native-quick-crypto/cpp/ec/HybridEcKeyPair.hpp b/packages/react-native-quick-crypto/cpp/ec/HybridEcKeyPair.hpp index 8548405bc..89b1860bc 100644 --- a/packages/react-native-quick-crypto/cpp/ec/HybridEcKeyPair.hpp +++ b/packages/react-native-quick-crypto/cpp/ec/HybridEcKeyPair.hpp @@ -5,31 +5,30 @@ #include #include -#include "HybridEcKeyPairSpec.hpp" #include "QuickCryptoUtils.hpp" +#include namespace margelo::nitro::crypto { class HybridEcKeyPair : public HybridEcKeyPairSpec { public: - HybridEcKeyPair() : HybridObject(TAG) {} + HybridEcKeyPair() = default; ~HybridEcKeyPair() override = default; public: // Methods - std::shared_ptr> generateKeyPair() override; + Promise generateKeyPair() override; void generateKeyPairSync() override; - KeyObject importKey(const std::string& format, const std::shared_ptr& keyData, const std::string& algorithm, - bool extractable, const std::vector& keyUsages) override; - std::shared_ptr exportKey(const KeyObject& key, const std::string& format) override; - std::shared_ptr getPublicKey() override; - std::shared_ptr getPrivateKey() override; + KeyObject importKey(const std::string& format, const ArrayBuffer& keyData, const std::string& algorithm, bool extractable, + const std::vector& keyUsages) override; + ArrayBuffer exportKey(const KeyObject& key, const std::string& format) override; + ArrayBuffer getPublicKey() override; + ArrayBuffer getPrivateKey() override; void setCurve(const std::string& curve) override; - std::shared_ptr sign(const std::shared_ptr& data, const std::string& hashAlgorithm) override; - bool verify(const std::shared_ptr& data, const std::shared_ptr& signature, - const std::string& hashAlgorithm) override; - std::vector getSupportedCurves() override; + ArrayBuffer sign(const ArrayBuffer& data, const std::string& hashAlgorithm) override; + bool verify(const ArrayBuffer& data, const ArrayBuffer& signature, const std::string& hashAlgorithm) override; + static std::vector getSupportedCurves(); protected: void checkKeyPair(); diff --git a/packages/react-native-quick-crypto/cpp/ecdh/HybridECDH.cpp b/packages/react-native-quick-crypto/cpp/ecdh/HybridECDH.cpp index d567b4114..5ffd3198c 100644 --- a/packages/react-native-quick-crypto/cpp/ecdh/HybridECDH.cpp +++ b/packages/react-native-quick-crypto/cpp/ecdh/HybridECDH.cpp @@ -33,7 +33,7 @@ void HybridECDH::init(const std::string& curveName) { _pkey.reset(); } -std::shared_ptr HybridECDH::generateKeys() { +ArrayBuffer HybridECDH::generateKeys() { ensureInitialized(); EVP_PKEY_CTX_ptr ctx(EVP_PKEY_CTX_new_id(EVP_PKEY_EC, nullptr), EVP_PKEY_CTX_free); @@ -59,7 +59,7 @@ std::shared_ptr HybridECDH::generateKeys() { return getPublicKey(); } -std::shared_ptr HybridECDH::computeSecret(const std::shared_ptr& otherPublicKey) { +ArrayBuffer HybridECDH::computeSecret(const ArrayBuffer& otherPublicKey) { ensureInitialized(); if (!_pkey) { throw std::runtime_error("ECDH: private key not set"); @@ -77,7 +77,7 @@ std::shared_ptr HybridECDH::computeSecret(const std::shared_ptrdata(), otherPublicKey->size(), nullptr) != 1) { + if (EC_POINT_oct2point(_group.get(), peerPoint.get(), dataOrEmpty(otherPublicKey), otherPublicKey.size(), nullptr) != 1) { throw std::runtime_error("ECDH: peer public key is malformed"); } if (EC_POINT_is_at_infinity(_group.get(), peerPoint.get())) { @@ -89,7 +89,7 @@ std::shared_ptr HybridECDH::computeSecret(const std::shared_ptrdata(), otherPublicKey->size()), EVP_PKEY_free); + EVP_PKEY_ptr peerPkey(createEcEvpPkey(_curveName.c_str(), dataOrEmpty(otherPublicKey), otherPublicKey.size()), EVP_PKEY_free); // Derive shared secret using EVP API EVP_PKEY_CTX_ptr ctx(EVP_PKEY_CTX_new(_pkey.get(), nullptr), EVP_PKEY_CTX_free); @@ -122,7 +122,7 @@ std::shared_ptr HybridECDH::computeSecret(const std::shared_ptr HybridECDH::getPrivateKey() { +ArrayBuffer HybridECDH::getPrivateKey() { if (!_pkey) { throw std::runtime_error("ECDH: no key set"); } @@ -140,11 +140,11 @@ std::shared_ptr HybridECDH::getPrivateKey() { return ToNativeArrayBuffer(buf); } -void HybridECDH::setPrivateKey(const std::shared_ptr& privateKey) { +void HybridECDH::setPrivateKey(const ArrayBuffer& privateKey) { ensureInitialized(); // Convert private key bytes to BIGNUM - BN_ptr privBn(BN_bin2bn(privateKey->data(), static_cast(privateKey->size()), nullptr), BN_free); + BN_ptr privBn(BN_bin2bn(dataOrEmpty(privateKey), static_cast(privateKey.size()), nullptr), BN_free); if (!privBn) { throw std::runtime_error("ECDH: failed to convert private key"); } @@ -171,7 +171,7 @@ void HybridECDH::setPrivateKey(const std::shared_ptr& privateKey) { _pkey.reset(createEcEvpPkey(_curveName.c_str(), pubOct.data(), pubOct.size(), privBn.get())); } -std::shared_ptr HybridECDH::getPublicKey() { +ArrayBuffer HybridECDH::getPublicKey() { if (!_pkey) { throw std::runtime_error("ECDH: no key set"); } @@ -189,14 +189,14 @@ std::shared_ptr HybridECDH::getPublicKey() { return ToNativeArrayBuffer(buf); } -void HybridECDH::setPublicKey(const std::shared_ptr& publicKey) { +void HybridECDH::setPublicKey(const ArrayBuffer& publicKey) { ensureInitialized(); // Build EVP_PKEY directly from public key octets - _pkey.reset(createEcEvpPkey(_curveName.c_str(), publicKey->data(), publicKey->size())); + _pkey.reset(createEcEvpPkey(_curveName.c_str(), dataOrEmpty(publicKey), publicKey.size())); } -std::shared_ptr HybridECDH::convertKey(const std::shared_ptr& key, const std::string& curve, double format) { +ArrayBuffer HybridECDH::convertKey(const ArrayBuffer& key, const std::string& curve, double format) { int nid = getCurveNid(curve); if (nid == NID_undef) { throw std::runtime_error("ECDH: unknown curve: " + curve); @@ -212,7 +212,7 @@ std::shared_ptr HybridECDH::convertKey(const std::shared_ptrdata(), key->size(), nullptr) != 1) { + if (EC_POINT_oct2point(group.get(), point.get(), dataOrEmpty(key), key.size(), nullptr) != 1) { throw std::runtime_error("ECDH: failed to decode public key"); } diff --git a/packages/react-native-quick-crypto/cpp/ecdh/HybridECDH.hpp b/packages/react-native-quick-crypto/cpp/ecdh/HybridECDH.hpp index dca423892..7648ca532 100644 --- a/packages/react-native-quick-crypto/cpp/ecdh/HybridECDH.hpp +++ b/packages/react-native-quick-crypto/cpp/ecdh/HybridECDH.hpp @@ -6,7 +6,7 @@ #include #include -#include "HybridECDHSpec.hpp" +#include namespace margelo::nitro::crypto { @@ -18,17 +18,17 @@ using EC_GROUP_ptr = std::unique_ptr; class HybridECDH : public HybridECDHSpec { public: - HybridECDH() : HybridObject("ECDH"), _pkey(nullptr, EVP_PKEY_free), _group(nullptr, EC_GROUP_free) {} + HybridECDH() : _pkey(nullptr, EVP_PKEY_free), _group(nullptr, EC_GROUP_free) {} virtual ~HybridECDH() = default; void init(const std::string& curveName) override; - std::shared_ptr generateKeys() override; - std::shared_ptr computeSecret(const std::shared_ptr& otherPublicKey) override; - std::shared_ptr getPrivateKey() override; - void setPrivateKey(const std::shared_ptr& privateKey) override; - std::shared_ptr getPublicKey() override; - void setPublicKey(const std::shared_ptr& publicKey) override; - std::shared_ptr convertKey(const std::shared_ptr& key, const std::string& curve, double format) override; + ArrayBuffer generateKeys() override; + ArrayBuffer computeSecret(const ArrayBuffer& otherPublicKey) override; + ArrayBuffer getPrivateKey() override; + void setPrivateKey(const ArrayBuffer& privateKey) override; + ArrayBuffer getPublicKey() override; + void setPublicKey(const ArrayBuffer& publicKey) override; + static ArrayBuffer convertKey(const ArrayBuffer& key, const std::string& curve, double format); private: EVP_PKEY_ptr _pkey; diff --git a/packages/react-native-quick-crypto/cpp/ed25519/HybridEdKeyPair.cpp b/packages/react-native-quick-crypto/cpp/ed25519/HybridEdKeyPair.cpp index 00df22c8f..46f491973 100644 --- a/packages/react-native-quick-crypto/cpp/ed25519/HybridEdKeyPair.cpp +++ b/packages/react-native-quick-crypto/cpp/ed25519/HybridEdKeyPair.cpp @@ -9,8 +9,7 @@ namespace margelo::nitro::crypto { -std::shared_ptr HybridEdKeyPair::diffieHellman(const std::shared_ptr& privateKey, - const std::shared_ptr& publicKey) { +ArrayBuffer HybridEdKeyPair::diffieHellman(const ArrayBuffer& privateKey, const ArrayBuffer& publicKey) { using EVP_PKEY_CTX_ptr = std::unique_ptr; // Determine key type from curve name @@ -20,13 +19,13 @@ std::shared_ptr HybridEdKeyPair::diffieHellman(const std::shared_pt } // 1. Create EVP_PKEY for private key (our key) - EVP_PKEY_ptr pkey_priv(EVP_PKEY_new_raw_private_key(keyType, NULL, privateKey->data(), privateKey->size()), EVP_PKEY_free); + EVP_PKEY_ptr pkey_priv(EVP_PKEY_new_raw_private_key(keyType, NULL, dataOrEmpty(privateKey), privateKey.size()), EVP_PKEY_free); if (!pkey_priv) { throw std::runtime_error("Failed to create private key: " + getOpenSSLError()); } // 2. Create EVP_PKEY for public key (peer's key) - EVP_PKEY_ptr pkey_pub(EVP_PKEY_new_raw_public_key(keyType, NULL, publicKey->data(), publicKey->size()), EVP_PKEY_free); + EVP_PKEY_ptr pkey_pub(EVP_PKEY_new_raw_public_key(keyType, NULL, dataOrEmpty(publicKey), publicKey.size()), EVP_PKEY_free); if (!pkey_pub) { throw std::runtime_error("Failed to create public key: " + getOpenSSLError()); } @@ -63,26 +62,25 @@ std::shared_ptr HybridEdKeyPair::diffieHellman(const std::shared_pt // 9. Return a newly-created ArrayBuffer from the raw buffer w/ cleanup uint8_t* raw_ptr = shared_secret.get(); - return std::make_shared(shared_secret.release(), shared_secret_len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(shared_secret.release(), shared_secret_len, [raw_ptr]() { delete[] raw_ptr; }); } -std::shared_ptr> HybridEdKeyPair::generateKeyPair(double publicFormat, double publicType, double privateFormat, - double privateType, const std::optional& cipher, - const std::optional>& passphrase) { +Promise HybridEdKeyPair::generateKeyPair(double publicFormat, double publicType, double privateFormat, double privateType, + const std::optional& cipher, const std::optional& passphrase) { // get owned NativeArrayBuffers before passing to sync function - std::optional> nativePassphrase = std::nullopt; + std::optional nativePassphrase = std::nullopt; if (passphrase.has_value()) { nativePassphrase = ToNativeArrayBuffer(passphrase.value()); } - return Promise::async([this, publicFormat, publicType, privateFormat, privateType, cipher, nativePassphrase]() { - this->generateKeyPairSync(publicFormat, publicType, privateFormat, privateType, cipher, nativePassphrase); + auto self = this->shared_cast(); + return Promise::async([self, publicFormat, publicType, privateFormat, privateType, cipher, nativePassphrase]() { + self->generateKeyPairSync(publicFormat, publicType, privateFormat, privateType, cipher, nativePassphrase); }); } void HybridEdKeyPair::generateKeyPairSync(double publicFormat, double publicType, double privateFormat, double privateType, - const std::optional& cipher, - const std::optional>& passphrase) { + const std::optional& cipher, const std::optional& passphrase) { // Clear any previous OpenSSL errors to prevent pollution clearOpenSSLErrors(); @@ -119,21 +117,19 @@ void HybridEdKeyPair::generateKeyPairSync(double publicFormat, double publicType this->pkey_.reset(raw_pkey); } -std::shared_ptr>> HybridEdKeyPair::sign(const std::shared_ptr& message, - const std::optional>& key) { +Promise HybridEdKeyPair::sign(const ArrayBuffer& message, const std::optional& key) { // get owned NativeArrayBuffer before passing to sync function auto nativeMessage = ToNativeArrayBuffer(message); - std::optional> nativeKey = std::nullopt; + std::optional nativeKey = std::nullopt; if (key.has_value()) { nativeKey = ToNativeArrayBuffer(key.value()); } - return Promise>::async( - [this, nativeMessage, nativeKey]() { return this->signSync(nativeMessage, nativeKey); }); + auto self = this->shared_cast(); + return Promise::async([self, nativeMessage, nativeKey]() { return self->signSync(nativeMessage, nativeKey); }); } -std::shared_ptr HybridEdKeyPair::signSync(const std::shared_ptr& message, - const std::optional>& key) { +ArrayBuffer HybridEdKeyPair::signSync(const ArrayBuffer& message, const std::optional& key) { // Clear any previous OpenSSL errors to prevent pollution clearOpenSSLErrors(); @@ -152,38 +148,36 @@ std::shared_ptr HybridEdKeyPair::signSync(const std::shared_ptrdata(), message.get()->size()) <= 0) { + if (EVP_DigestSign(md_ctx.get(), NULL, &sig_len, dataOrEmpty(message), message.size()) <= 0) { throw std::runtime_error("Failed to calculate signature size"); } auto sig = std::make_unique(sig_len); // Actually calculate the signature - if (EVP_DigestSign(md_ctx.get(), sig.get(), &sig_len, message.get()->data(), message.get()->size()) <= 0) { + if (EVP_DigestSign(md_ctx.get(), sig.get(), &sig_len, dataOrEmpty(message), message.size()) <= 0) { throw std::runtime_error("Failed to calculate signature"); } // return value for JS uint8_t* raw_ptr = sig.get(); - return std::make_shared(sig.release(), sig_len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(sig.release(), sig_len, [raw_ptr]() { delete[] raw_ptr; }); } -std::shared_ptr> HybridEdKeyPair::verify(const std::shared_ptr& signature, - const std::shared_ptr& message, - const std::optional>& key) { +Promise HybridEdKeyPair::verify(const ArrayBuffer& signature, const ArrayBuffer& message, const std::optional& key) { // get owned NativeArrayBuffers before passing to sync function auto nativeSignature = ToNativeArrayBuffer(signature); auto nativeMessage = ToNativeArrayBuffer(message); - std::optional> nativeKey = std::nullopt; + std::optional nativeKey = std::nullopt; if (key.has_value()) { nativeKey = ToNativeArrayBuffer(key.value()); } + auto self = this->shared_cast(); return Promise::async( - [this, nativeSignature, nativeMessage, nativeKey]() { return this->verifySync(nativeSignature, nativeMessage, nativeKey); }); + [self, nativeSignature, nativeMessage, nativeKey]() { return self->verifySync(nativeSignature, nativeMessage, nativeKey); }); } -bool HybridEdKeyPair::verifySync(const std::shared_ptr& signature, const std::shared_ptr& message, - const std::optional>& key) { +bool HybridEdKeyPair::verifySync(const ArrayBuffer& signature, const ArrayBuffer& message, const std::optional& key) { // Clear any previous OpenSSL errors to prevent pollution clearOpenSSLErrors(); @@ -201,7 +195,7 @@ bool HybridEdKeyPair::verifySync(const std::shared_ptr& signature, } // verify - auto res = EVP_DigestVerify(md_ctx.get(), signature.get()->data(), signature.get()->size(), message.get()->data(), message.get()->size()); + auto res = EVP_DigestVerify(md_ctx.get(), dataOrEmpty(signature), signature.size(), dataOrEmpty(message), message.size()); // return value for JS if (res < 0) { @@ -210,7 +204,7 @@ bool HybridEdKeyPair::verifySync(const std::shared_ptr& signature, return res == 1; // true if 1, false if 0 } -std::shared_ptr HybridEdKeyPair::getPublicKey() { +ArrayBuffer HybridEdKeyPair::getPublicKey() { this->checkKeyPair(); // If format is DER (0) or PEM (1), export in SPKI format @@ -241,7 +235,7 @@ std::shared_ptr HybridEdKeyPair::getPublicKey() { size_t len = bptr->length; uint8_t* raw_ptr = data.get(); - return std::make_shared(data.release(), len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(data.release(), len, [raw_ptr]() { delete[] raw_ptr; }); } // Default: raw format @@ -251,10 +245,10 @@ std::shared_ptr HybridEdKeyPair::getPublicKey() { EVP_PKEY_get_raw_public_key(this->pkey_.get(), publ.get(), &len); uint8_t* raw_ptr = publ.get(); - return std::make_shared(publ.release(), len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(publ.release(), len, [raw_ptr]() { delete[] raw_ptr; }); } -std::shared_ptr HybridEdKeyPair::getPrivateKey() { +ArrayBuffer HybridEdKeyPair::getPrivateKey() { this->checkKeyPair(); // If format is DER (0) or PEM (1), export in PKCS8 format @@ -288,7 +282,7 @@ std::shared_ptr HybridEdKeyPair::getPrivateKey() { secureZero(bptr->data, bptr->length); uint8_t* raw_ptr = data.get(); - return std::make_shared(data.release(), len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(data.release(), len, [raw_ptr]() { delete[] raw_ptr; }); } // Default: raw format @@ -298,7 +292,7 @@ std::shared_ptr HybridEdKeyPair::getPrivateKey() { EVP_PKEY_get_raw_private_key(this->pkey_.get(), priv.get(), &len); uint8_t* raw_ptr = priv.get(); - return std::make_shared(priv.release(), len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(priv.release(), len, [raw_ptr]() { delete[] raw_ptr; }); } void HybridEdKeyPair::checkKeyPair() { @@ -311,7 +305,7 @@ void HybridEdKeyPair::setCurve(const std::string& curve) { this->curve = curve; } -auto HybridEdKeyPair::importPublicKey(const std::optional>& key) -> EVP_PKEY_ptr { +auto HybridEdKeyPair::importPublicKey(const std::optional& key) -> EVP_PKEY_ptr { if (key.has_value()) { // Determine key type from curve name int keyType = EVP_PKEY_ED25519; @@ -323,7 +317,7 @@ auto HybridEdKeyPair::importPublicKey(const std::optionaldata(), key.value()->size()), EVP_PKEY_free); + EVP_PKEY_ptr pkey(EVP_PKEY_new_raw_public_key(keyType, NULL, dataOrEmpty(key.value()), key.value().size()), EVP_PKEY_free); if (!pkey) { throw std::runtime_error("Failed to read public key"); } @@ -334,7 +328,7 @@ auto HybridEdKeyPair::importPublicKey(const std::optionalpkey_.get(), EVP_PKEY_free); } -auto HybridEdKeyPair::importPrivateKey(const std::optional>& key) -> EVP_PKEY_ptr { +auto HybridEdKeyPair::importPrivateKey(const std::optional& key) -> EVP_PKEY_ptr { if (key.has_value()) { // Determine key type from curve name int keyType = EVP_PKEY_ED25519; @@ -346,7 +340,7 @@ auto HybridEdKeyPair::importPrivateKey(const std::optionaldata(), key.value()->size()), EVP_PKEY_free); + EVP_PKEY_ptr pkey(EVP_PKEY_new_raw_private_key(keyType, NULL, dataOrEmpty(key.value()), key.value().size()), EVP_PKEY_free); if (!pkey) { throw std::runtime_error("Failed to read private key"); } diff --git a/packages/react-native-quick-crypto/cpp/ed25519/HybridEdKeyPair.hpp b/packages/react-native-quick-crypto/cpp/ed25519/HybridEdKeyPair.hpp index 9f9fa0b27..06b497903 100644 --- a/packages/react-native-quick-crypto/cpp/ed25519/HybridEdKeyPair.hpp +++ b/packages/react-native-quick-crypto/cpp/ed25519/HybridEdKeyPair.hpp @@ -3,45 +3,38 @@ #include #include -#include "HybridEdKeyPairSpec.hpp" #include "QuickCryptoUtils.hpp" +#include namespace margelo::nitro::crypto { class HybridEdKeyPair : public HybridEdKeyPairSpec { public: - HybridEdKeyPair() : HybridObject(TAG) {} + HybridEdKeyPair() = default; ~HybridEdKeyPair() override = default; public: // Methods - std::shared_ptr diffieHellman(const std::shared_ptr& privateKey, - const std::shared_ptr& publicKey) override; + ArrayBuffer diffieHellman(const ArrayBuffer& privateKey, const ArrayBuffer& publicKey) override; - std::shared_ptr> generateKeyPair(double publicFormat, double publicType, double privateFormat, double privateType, - const std::optional& cipher, - const std::optional>& passphrase) override; + Promise generateKeyPair(double publicFormat, double publicType, double privateFormat, double privateType, + const std::optional& cipher, const std::optional& passphrase) override; void generateKeyPairSync(double publicFormat, double publicType, double privateFormat, double privateType, - const std::optional& cipher, - const std::optional>& passphrase) override; + const std::optional& cipher, const std::optional& passphrase) override; - std::shared_ptr>> sign(const std::shared_ptr& message, - const std::optional>& key) override; + Promise sign(const ArrayBuffer& message, const std::optional& key) override; - std::shared_ptr signSync(const std::shared_ptr& message, - const std::optional>& key) override; + ArrayBuffer signSync(const ArrayBuffer& message, const std::optional& key) override; - std::shared_ptr> verify(const std::shared_ptr& signature, const std::shared_ptr& message, - const std::optional>& key) override; + Promise verify(const ArrayBuffer& signature, const ArrayBuffer& message, const std::optional& key) override; - bool verifySync(const std::shared_ptr& signature, const std::shared_ptr& message, - const std::optional>& key) override; + bool verifySync(const ArrayBuffer& signature, const ArrayBuffer& message, const std::optional& key) override; protected: - std::shared_ptr getPublicKey() override; + ArrayBuffer getPublicKey() override; - std::shared_ptr getPrivateKey() override; + ArrayBuffer getPrivateKey() override; void checkKeyPair(); @@ -60,8 +53,8 @@ class HybridEdKeyPair : public HybridEdKeyPairSpec { int privateFormat_ = -1; int privateType_ = -1; - EVP_PKEY_ptr importPublicKey(const std::optional>& key); - EVP_PKEY_ptr importPrivateKey(const std::optional>& key); + EVP_PKEY_ptr importPublicKey(const std::optional& key); + EVP_PKEY_ptr importPrivateKey(const std::optional& key); }; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/cpp/hash/HybridHash.cpp b/packages/react-native-quick-crypto/cpp/hash/HybridHash.cpp index 7df66ec7f..d71cbb595 100644 --- a/packages/react-native-quick-crypto/cpp/hash/HybridHash.cpp +++ b/packages/react-native-quick-crypto/cpp/hash/HybridHash.cpp @@ -22,7 +22,7 @@ HybridHash::~HybridHash() { } } -void HybridHash::createHash(const std::string& hashAlgorithmArg, const std::optional outputLengthArg) { +void HybridHash::createHash(const std::string& hashAlgorithmArg, const std::optional& outputLengthArg) { // Clear any previous OpenSSL errors to prevent pollution clearOpenSSLErrors(); @@ -68,7 +68,7 @@ void HybridHash::createHash(const std::string& hashAlgorithmArg, const std::opti } } -void HybridHash::update(const std::variant, std::string>& data) { +void HybridHash::update(const std::variant& data) { if (!ctx) { throw std::runtime_error("Hash context not initialized"); } @@ -79,14 +79,14 @@ void HybridHash::update(const std::variant, std::st throw std::runtime_error("Failed to update hash digest: " + std::to_string(ERR_get_error())); } } else { - const std::shared_ptr& buffer = std::get>(data); - if (EVP_DigestUpdate(ctx, reinterpret_cast(buffer->data()), buffer->size()) != 1) { + const ArrayBuffer& buffer = std::get(data); + if (EVP_DigestUpdate(ctx, dataOrEmpty(buffer), buffer.size()) != 1) { throw std::runtime_error("Failed to update hash digest: " + std::to_string(ERR_get_error())); } } } -std::shared_ptr HybridHash::digest(const std::optional& encoding) { +ArrayBuffer HybridHash::digest(const std::optional& encoding) { if (!ctx) { throw std::runtime_error("Hash context not initialized"); } @@ -116,10 +116,10 @@ std::shared_ptr HybridHash::digest(const std::optional } uint8_t* raw_ptr = hashBuffer.get(); - return std::make_shared(hashBuffer.release(), hashLength, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(hashBuffer.release(), hashLength, [raw_ptr]() { delete[] raw_ptr; }); } -std::shared_ptr HybridHash::copy(const std::optional outputLengthArg) { +std::shared_ptr HybridHash::copy(const std::optional& outputLengthArg) { if (!ctx) { throw std::runtime_error("Hash context not initialized"); } diff --git a/packages/react-native-quick-crypto/cpp/hash/HybridHash.hpp b/packages/react-native-quick-crypto/cpp/hash/HybridHash.hpp index a71f512ce..dde1e9eec 100644 --- a/packages/react-native-quick-crypto/cpp/hash/HybridHash.hpp +++ b/packages/react-native-quick-crypto/cpp/hash/HybridHash.hpp @@ -5,7 +5,7 @@ #include #include -#include "HybridHashSpec.hpp" +#include namespace margelo::nitro::crypto { @@ -13,19 +13,19 @@ using namespace facebook; class HybridHash : public HybridHashSpec { public: - HybridHash() : HybridObject(TAG) {} - HybridHash(EVP_MD_CTX* ctx, EVP_MD* md, const std::string& algorithm, const std::optional outputLength, bool md_fetched = false) - : HybridObject(TAG), ctx(ctx), md(md), md_fetched(md_fetched), algorithm(algorithm), outputLength(outputLength) {} + HybridHash() = default; + HybridHash(EVP_MD_CTX* ctx, EVP_MD* md, const std::string& algorithm, const std::optional& outputLength, bool md_fetched = false) + : ctx(ctx), md(md), md_fetched(md_fetched), algorithm(algorithm), outputLength(outputLength) {} ~HybridHash(); public: // Methods - void createHash(const std::string& algorithm, const std::optional outputLength) override; - void update(const std::variant, std::string>& data) override; - std::shared_ptr digest(const std::optional& encoding = std::nullopt) override; - std::shared_ptr copy(const std::optional outputLength) override; - std::vector getSupportedHashAlgorithms() override; - std::string getOpenSSLVersion() override; + void createHash(const std::string& algorithm, const std::optional& outputLength) override; + void update(const std::variant& data) override; + ArrayBuffer digest(const std::optional& encoding = std::nullopt) override; + std::shared_ptr copy(const std::optional& outputLength) override; + static std::vector getSupportedHashAlgorithms(); + static std::string getOpenSSLVersion(); private: // Methods diff --git a/packages/react-native-quick-crypto/cpp/hkdf/HybridHkdf.cpp b/packages/react-native-quick-crypto/cpp/hkdf/HybridHkdf.cpp index ce38194bf..3222a46be 100644 --- a/packages/react-native-quick-crypto/cpp/hkdf/HybridHkdf.cpp +++ b/packages/react-native-quick-crypto/cpp/hkdf/HybridHkdf.cpp @@ -12,22 +12,20 @@ namespace margelo::nitro::crypto { -std::shared_ptr>> -HybridHkdf::deriveKey(const std::string& algorithm, const std::shared_ptr& key, const std::shared_ptr& salt, - const std::shared_ptr& info, double length, HkdfMode mode) { +Promise HybridHkdf::deriveKey(const std::string& algorithm, const ArrayBuffer& key, const ArrayBuffer& salt, + const ArrayBuffer& info, double length, HkdfMode mode) { // get owned NativeArrayBuffers before passing to sync function auto nativeKey = ToNativeArrayBuffer(key); auto nativeSalt = ToNativeArrayBuffer(salt); auto nativeInfo = ToNativeArrayBuffer(info); - return Promise>::async([this, algorithm, nativeKey, nativeSalt, nativeInfo, length, mode]() { - return this->deriveKeySync(algorithm, nativeKey, nativeSalt, nativeInfo, length, mode); + return Promise::async([algorithm, nativeKey, nativeSalt, nativeInfo, length, mode]() { + return deriveKeySync(algorithm, nativeKey, nativeSalt, nativeInfo, length, mode); }); } -std::shared_ptr HybridHkdf::deriveKeySync(const std::string& algorithm, const std::shared_ptr& baseKey, - const std::shared_ptr& salt, const std::shared_ptr& info, - double length, HkdfMode mode) { +ArrayBuffer HybridHkdf::deriveKeySync(const std::string& algorithm, const ArrayBuffer& baseKey, const ArrayBuffer& salt, + const ArrayBuffer& info, double length, HkdfMode mode) { EVP_KDF* kdf = EVP_KDF_fetch(nullptr, "HKDF", nullptr); if (kdf == nullptr) { throw std::runtime_error("Failed to fetch HKDF implementation: " + std::to_string(ERR_get_error())); @@ -67,15 +65,15 @@ std::shared_ptr HybridHkdf::deriveKeySync(const std::string& algori // pointer even when the length is 0 ("passed a null parameter"), so pass a non-null empty // buffer. It must stay alive through EVP_KDF_derive, which copies the parameter. unsigned char emptyKey = 0; - if (baseKey && baseKey->size() > 0) { - params[paramIndex++] = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, baseKey->data(), baseKey->size()); + if (baseKey.size() > 0) { + params[paramIndex++] = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, baseKey.data(), baseKey.size()); } else { params[paramIndex++] = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, &emptyKey, 0); } // Salt - if (salt && salt->size() > 0) { - params[paramIndex++] = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT, salt->data(), salt->size()); + if (salt.size() > 0) { + params[paramIndex++] = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT, salt.data(), salt.size()); } else { // If salt is not provided, it is set to a string of HashLen zeros. // OpenSSL handles missing salt as default? Or do we need to pass empty? @@ -83,8 +81,8 @@ std::shared_ptr HybridHkdf::deriveKeySync(const std::string& algori } // Info - if (info && info->size() > 0) { - params[paramIndex++] = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO, info->data(), info->size()); + if (info.size() > 0) { + params[paramIndex++] = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO, info.data(), info.size()); } params[paramIndex++] = OSSL_PARAM_construct_end(); @@ -107,8 +105,8 @@ std::shared_ptr HybridHkdf::deriveKeySync(const std::string& algori EVP_KDF_CTX_free(ctx); - uint8_t* raw_ptr = out_buf.get(); - return std::make_shared(out_buf.release(), outLen, [raw_ptr]() { delete[] raw_ptr; }); + uint8_t* raw_ptr = out_buf.release(); + return ArrayBuffer::wrap(raw_ptr, outLen, [raw_ptr]() { delete[] raw_ptr; }); } } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/cpp/hkdf/HybridHkdf.hpp b/packages/react-native-quick-crypto/cpp/hkdf/HybridHkdf.hpp index 89079a556..e51a6356f 100644 --- a/packages/react-native-quick-crypto/cpp/hkdf/HybridHkdf.hpp +++ b/packages/react-native-quick-crypto/cpp/hkdf/HybridHkdf.hpp @@ -5,7 +5,7 @@ #include #include -#include "HybridHkdfSpec.hpp" +#include namespace margelo::nitro::crypto { @@ -13,17 +13,10 @@ using namespace facebook; class HybridHkdf : public HybridHkdfSpec { public: - HybridHkdf() : HybridObject(TAG) {} - - public: - // Methods - std::shared_ptr deriveKeySync(const std::string& algorithm, const std::shared_ptr& key, - const std::shared_ptr& salt, const std::shared_ptr& info, - double length, HkdfMode mode) override; - std::shared_ptr>> deriveKey(const std::string& algorithm, const std::shared_ptr& key, - const std::shared_ptr& salt, - const std::shared_ptr& info, double length, - HkdfMode mode) override; + static ArrayBuffer deriveKeySync(const std::string& algorithm, const ArrayBuffer& key, const ArrayBuffer& salt, const ArrayBuffer& info, + double length, HkdfMode mode); + static Promise deriveKey(const std::string& algorithm, const ArrayBuffer& key, const ArrayBuffer& salt, + const ArrayBuffer& info, double length, HkdfMode mode); }; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/cpp/hmac/HybridHmac.cpp b/packages/react-native-quick-crypto/cpp/hmac/HybridHmac.cpp index d6865422e..60992924c 100644 --- a/packages/react-native-quick-crypto/cpp/hmac/HybridHmac.cpp +++ b/packages/react-native-quick-crypto/cpp/hmac/HybridHmac.cpp @@ -7,6 +7,7 @@ #include #include "HybridHmac.hpp" +#include "QuickCryptoUtils.hpp" namespace margelo::nitro::crypto { @@ -17,7 +18,7 @@ HybridHmac::~HybridHmac() { } } -void HybridHmac::createHmac(const std::string& hmacAlgorithm, const std::shared_ptr& secretKey) { +void HybridHmac::createHmac(const std::string& hmacAlgorithm, const ArrayBuffer& secretKey) { algorithm = hmacAlgorithm; // Create and use EVP_MAC locally @@ -44,8 +45,8 @@ void HybridHmac::createHmac(const std::string& hmacAlgorithm, const std::shared_ params[0] = OSSL_PARAM_construct_utf8_string("digest", const_cast(algorithm.c_str()), 0); params[1] = OSSL_PARAM_construct_end(); - const uint8_t* keyData = reinterpret_cast(secretKey->data()); - size_t keySize = secretKey->size(); + const uint8_t* keyData = dataOrEmpty(secretKey); + size_t keySize = secretKey.size(); // Handle empty key case by providing a dummy key static const uint8_t dummyKey = 0; @@ -60,7 +61,7 @@ void HybridHmac::createHmac(const std::string& hmacAlgorithm, const std::shared_ } } -void HybridHmac::update(const std::variant, std::string>& data) { +void HybridHmac::update(const std::variant& data) { if (!ctx) { throw std::runtime_error("HMAC context not initialized"); } @@ -73,14 +74,14 @@ void HybridHmac::update(const std::variant, std::st } } else { // Handle ArrayBuffer - const std::shared_ptr& buffer = std::get>(data); - if (EVP_MAC_update(ctx, reinterpret_cast(buffer->data()), buffer->size()) != 1) { + const ArrayBuffer& buffer = std::get(data); + if (EVP_MAC_update(ctx, dataOrEmpty(buffer), buffer.size()) != 1) { throw std::runtime_error("Failed to update HMAC: " + std::to_string(ERR_get_error())); } } } -std::shared_ptr HybridHmac::digest() { +ArrayBuffer HybridHmac::digest() { if (!ctx) { throw std::runtime_error("HMAC context not initialized"); } @@ -96,7 +97,7 @@ std::shared_ptr HybridHmac::digest() { } uint8_t* raw_ptr = hmacBuffer.get(); - return std::make_shared(hmacBuffer.release(), hmacLength, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(hmacBuffer.release(), hmacLength, [raw_ptr]() { delete[] raw_ptr; }); } } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/cpp/hmac/HybridHmac.hpp b/packages/react-native-quick-crypto/cpp/hmac/HybridHmac.hpp index 0de204085..f18cdee4f 100644 --- a/packages/react-native-quick-crypto/cpp/hmac/HybridHmac.hpp +++ b/packages/react-native-quick-crypto/cpp/hmac/HybridHmac.hpp @@ -6,7 +6,7 @@ #include #include -#include "HybridHmacSpec.hpp" +#include namespace margelo::nitro::crypto { @@ -14,14 +14,14 @@ using namespace facebook; class HybridHmac : public HybridHmacSpec { public: - HybridHmac() : HybridObject(TAG) {} + HybridHmac() = default; ~HybridHmac(); public: // Methods - void createHmac(const std::string& algorithm, const std::shared_ptr& key) override; - void update(const std::variant, std::string>& data) override; - std::shared_ptr digest() override; + void createHmac(const std::string& algorithm, const ArrayBuffer& key) override; + void update(const std::variant& data) override; + ArrayBuffer digest() override; private: // Properties diff --git a/packages/react-native-quick-crypto/cpp/keys/HybridKeyObjectHandle.cpp b/packages/react-native-quick-crypto/cpp/keys/HybridKeyObjectHandle.cpp index b562acdcb..8e8d64a10 100644 --- a/packages/react-native-quick-crypto/cpp/keys/HybridKeyObjectHandle.cpp +++ b/packages/react-native-quick-crypto/cpp/keys/HybridKeyObjectHandle.cpp @@ -42,7 +42,7 @@ static void configurePqcOutputFormats() { } #endif -HybridKeyObjectHandle::HybridKeyObjectHandle() : HybridObject(TAG) { +HybridKeyObjectHandle::HybridKeyObjectHandle() { #if OPENSSL_VERSION_NUMBER >= 0x30600000L // Configure once on first handle construction. Providers are guaranteed // loaded by this point (any prior crypto op routed through ncrypto), and @@ -81,7 +81,7 @@ facebook::jsi::Value HybridKeyObjectHandle::importSlhDsaRawPrivateKey(facebook:: using Reject = JSIConverter>; enum class Attachment { pending, failed, ready }; auto attachment = std::make_shared(Attachment::pending); - auto promise = ValidationPromise::create(); + auto promise = ValidationPromise::pending(); auto jsPromise = CommonGlobals::Promise::callConstructor( runtime, [promise, attachment, error](facebook::jsi::Runtime& js, const facebook::jsi::Value&, const facebook::jsi::Value* callbacks, size_t count) { @@ -92,8 +92,8 @@ facebook::jsi::Value HybridKeyObjectHandle::importSlhDsaRawPrivateKey(facebook:: } auto resolve = Resolve::fromJSI(js, callbacks[0]); auto reject = Reject::fromJSI(js, callbacks[1]); - promise->addOnResolvedListener(std::move(resolve)); - promise->addOnRejectedListener(std::move(reject)); + promise.addOnResolvedListener(std::move(resolve)); + promise.addOnRejectedListener(std::move(reject)); *attachment = Attachment::ready; return facebook::jsi::Value::undefined(); }); @@ -117,17 +117,17 @@ facebook::jsi::Value HybridKeyObjectHandle::importSlhDsaRawPrivateKey(facebook:: output = std::move(handle); } catch (...) { // The owned input has unwound before either callback can run. - promise->reject(std::current_exception()); + promise.reject(std::current_exception()); return; } - promise->resolve(std::move(output)); + promise.resolve(std::move(output)); }); } catch (...) { validation.reset(); try { throw std::runtime_error(error); } catch (...) { - promise->reject(std::current_exception()); + promise.reject(std::current_exception()); } } return jsPromise; @@ -141,11 +141,11 @@ facebook::jsi::Value HybridKeyObjectHandle::importSlhDsaRawPrivateKey(facebook:: // Generated conversion omits release-mode ArrayBuffer brand checks and converts // the returned Promise after entering native code. Admit work only after both // the input and the JavaScript Promise callbacks have been checked. -void HybridKeyObjectHandle::loadHybridMethods() { - HybridKeyObjectHandleSpec::loadHybridMethods(); - registerHybrids(this, [](Prototype& prototype) { - prototype.registerRawHybridMethod("importSlhDsaRawPrivateKey", 2, &HybridKeyObjectHandle::importSlhDsaRawPrivateKey); +const std::shared_ptr& HybridKeyObjectHandle::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerRawHybridMethod("importSlhDsaRawPrivateKey", 2, &HybridKeyObjectHandle::importSlhDsaRawPrivateKey); }); + return hybridClass; } // All current operations on a key handle run synchronously on the JS thread. @@ -228,9 +228,8 @@ static std::string base64url_decode(const std::string& input) { return base64_decode(padded, false); } -std::shared_ptr HybridKeyObjectHandle::exportKey(std::optional format, std::optional type, - const std::optional& cipher, - const std::optional>& passphrase) { +ArrayBuffer HybridKeyObjectHandle::exportKey(const std::optional& format, const std::optional& type, + const std::optional& cipher, const std::optional& passphrase) { auto keyType = data_.GetKeyType(); // Copy to avoid JSI ArrayBuffer GC issues. See #645. @@ -340,7 +339,7 @@ std::shared_ptr HybridKeyObjectHandle::exportKey(std::optional{passphrase_ptr->data(), passphrase_ptr->size()})); + std::make_optional(ncrypto::DataPointer::Copy(ncrypto::Buffer{passphrase_ptr.data(), passphrase_ptr.size()})); } auto result = pkey.writePrivateKey(config); @@ -366,7 +365,7 @@ JWK HybridKeyObjectHandle::exportJwk(const JWK& key, bool handleRsaPss) { auto symKey = data_.GetSymmetricKey(); result.kty = JWKkty::OCT; // RFC 7517 compliant base64url encoding (no padding characters) - result.k = base64url_encode(reinterpret_cast(symKey->data()), symKey->size()); + result.k = base64url_encode(reinterpret_cast(symKey.data()), symKey.size()); return result; } @@ -601,7 +600,7 @@ static bool supportsRawSeed(int keyId, const char* typeName) { return false; } -std::shared_ptr HybridKeyObjectHandle::exportRawPublic() { +ArrayBuffer HybridKeyObjectHandle::exportRawPublic() { auto keyType = data_.GetKeyType(); if (keyType == KeyType::SECRET) { throw std::runtime_error("Raw public key export is not supported for secret keys"); @@ -626,7 +625,7 @@ std::shared_ptr HybridKeyObjectHandle::exportRawPublic() { return ToNativeArrayBuffer(reinterpret_cast(rawData.get()), rawData.size()); } -std::shared_ptr HybridKeyObjectHandle::exportRawPrivate() { +ArrayBuffer HybridKeyObjectHandle::exportRawPrivate() { auto keyType = data_.GetKeyType(); if (keyType != KeyType::PRIVATE) { throw std::runtime_error("Raw private key export requires a private key"); @@ -651,7 +650,7 @@ std::shared_ptr HybridKeyObjectHandle::exportRawPrivate() { return ToNativeArrayBuffer(reinterpret_cast(rawData.get()), rawData.size()); } -std::shared_ptr HybridKeyObjectHandle::exportRawSeed() { +ArrayBuffer HybridKeyObjectHandle::exportRawSeed() { #if OPENSSL_VERSION_NUMBER >= 0x30500000L auto keyType = data_.GetKeyType(); if (keyType != KeyType::PRIVATE) { @@ -680,7 +679,7 @@ std::shared_ptr HybridKeyObjectHandle::exportRawSeed() { #endif } -std::shared_ptr HybridKeyObjectHandle::exportECPublicRaw(bool compressed) { +ArrayBuffer HybridKeyObjectHandle::exportECPublicRaw(bool compressed) { auto keyType = data_.GetKeyType(); if (keyType == KeyType::SECRET) { throw std::runtime_error("EC raw public key export is not supported for secret keys"); @@ -719,7 +718,7 @@ std::shared_ptr HybridKeyObjectHandle::exportECPublicRaw(bool compr return ToNativeArrayBuffer(buf.data(), buf.size()); } -std::shared_ptr HybridKeyObjectHandle::exportECPrivateRaw() { +ArrayBuffer HybridKeyObjectHandle::exportECPrivateRaw() { auto keyType = data_.GetKeyType(); if (keyType != KeyType::PRIVATE) { throw std::runtime_error("EC raw private key export requires a private key"); @@ -848,25 +847,20 @@ AsymmetricKeyType HybridKeyObjectHandle::getAsymmetricKeyType() { throw std::runtime_error("Unsupported asymmetric key type"); } -bool HybridKeyObjectHandle::init(KeyType keyType, const std::variant, std::string>& key, - std::optional format, std::optional type, - const std::optional>& passphrase) { +bool HybridKeyObjectHandle::init(KeyType keyType, const std::variant& key, + const std::optional& format, const std::optional& type, + const std::optional& passphrase) { // Reset any existing data to prevent state leakage data_ = KeyObjectData(); // get ArrayBuffer from key - always copy to ensure we own the data - std::shared_ptr ab; - if (std::holds_alternative(key)) { - ab = ToNativeArrayBuffer(std::get(key)); - } else { - const auto& abPtr = std::get>(key); - ab = ToNativeArrayBuffer(abPtr); - } + const auto ab = std::holds_alternative(key) ? ToNativeArrayBuffer(std::get(key)) + : ToNativeArrayBuffer(std::get(key)); // Handle raw asymmetric key material - only for special curves with known raw sizes std::optional actualFormat = format; if (!actualFormat.has_value() && !type.has_value() && (keyType == KeyType::PUBLIC || keyType == KeyType::PRIVATE)) { - size_t keySize = ab->size(); + size_t keySize = ab.size(); // Only route to initRawKey for exact special curve sizes: // X25519/Ed25519: 32 bytes, X448: 56 bytes, Ed448: 57 bytes // DER-encoded keys will be much larger and should use standard parsing @@ -898,7 +892,7 @@ bool HybridKeyObjectHandle::init(KeyType keyType, const std::variant HybridKeyObjectHandle::initJwk(const JWK& keyData, std::optional namedCurve) { +std::optional HybridKeyObjectHandle::initJwk(const JWK& keyData, const std::optional& namedCurve) { // Reset any existing data data_ = KeyObjectData(); @@ -1220,10 +1214,14 @@ std::optional HybridKeyObjectHandle::initJwk(const JWK& keyData, std::o throw std::runtime_error("Unsupported JWK key type"); } +static KeyDetail emptyKeyDetail() { + return KeyDetail(std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt, std::nullopt); +} + KeyDetail HybridKeyObjectHandle::keyDetail() { const auto& pkey_ptr = data_.GetAsymmetricKey(); if (!pkey_ptr) { - return KeyDetail{}; + return emptyKeyDetail(); } EVP_PKEY* pkey = pkey_ptr.get(); @@ -1259,14 +1257,14 @@ KeyDetail HybridKeyObjectHandle::keyDetail() { } } - return KeyDetail{}; + return emptyKeyDetail(); } -bool HybridKeyObjectHandle::initRawKey(KeyType keyType, std::shared_ptr keyData) { +bool HybridKeyObjectHandle::initRawKey(KeyType keyType, const ArrayBuffer& keyData) { // For asymmetric keys (x25519/x448/ed25519/ed448), we need to determine the curve type // Based on key size: x25519=32 bytes, x448=56 bytes, ed25519=32 bytes, ed448=57 bytes int curveId = -1; - size_t keySize = keyData->size(); + size_t keySize = keyData.size(); if (keySize == 32) { // Could be x25519 or ed25519 - for now assume x25519 based on test context @@ -1279,7 +1277,7 @@ bool HybridKeyObjectHandle::initRawKey(KeyType keyType, std::shared_ptr buffer{.data = reinterpret_cast(keyData->data()), .len = keyData->size()}; + ncrypto::Buffer buffer{.data = reinterpret_cast(keyData.data()), .len = keyData.size()}; ncrypto::EVPKeyPointer pkey; if (keyType == KeyType::PRIVATE) { @@ -1298,7 +1296,7 @@ bool HybridKeyObjectHandle::initRawKey(KeyType keyType, std::shared_ptr& keyData) { +bool HybridKeyObjectHandle::initECRaw(const std::string& namedCurve, const ArrayBuffer& keyData) { // Reset any existing data data_ = KeyObjectData(); @@ -1327,12 +1325,12 @@ bool HybridKeyObjectHandle::initECRaw(const std::string& namedCurve, const std:: throw std::runtime_error("Failed to get curve name for NID"); } - EVP_PKEY* pkey = createEcEvpPkey(group_name, keyData->data(), keyData->size()); + EVP_PKEY* pkey = createEcEvpPkey(group_name, keyData.data(), keyData.size()); this->data_ = KeyObjectData::CreateAsymmetric(KeyType::PUBLIC, ncrypto::EVPKeyPointer(pkey)); return true; } -bool HybridKeyObjectHandle::initPqcRaw(const std::string& algorithmName, const std::shared_ptr& keyData, bool isPublic) { +bool HybridKeyObjectHandle::initPqcRaw(const std::string& algorithmName, const ArrayBuffer& keyData, bool isPublic) { #if OPENSSL_VERSION_NUMBER >= 0x30500000L data_ = KeyObjectData(); @@ -1376,7 +1374,7 @@ bool HybridKeyObjectHandle::initPqcRaw(const std::string& algorithmName, const s else throw std::runtime_error("Unknown PQC algorithm: " + algorithmName); - ncrypto::Buffer buffer{.data = reinterpret_cast(keyData->data()), .len = keyData->size()}; + ncrypto::Buffer buffer{.data = reinterpret_cast(keyData.data()), .len = keyData.size()}; ncrypto::EVPKeyPointer pkey; if (isPublic) { @@ -1450,7 +1448,7 @@ static int evpNidForAsymmetricKeyType(const std::string& asymmetricKeyType) { return 0; } -bool HybridKeyObjectHandle::initRawPublic(const std::string& asymmetricKeyType, const std::shared_ptr& keyData, +bool HybridKeyObjectHandle::initRawPublic(const std::string& asymmetricKeyType, const ArrayBuffer& keyData, const std::optional& namedCurve) { data_ = KeyObjectData(); @@ -1466,7 +1464,7 @@ bool HybridKeyObjectHandle::initRawPublic(const std::string& asymmetricKeyType, throw std::runtime_error("Invalid asymmetricKeyType for raw public key import: " + asymmetricKeyType); } - ncrypto::Buffer buffer{.data = reinterpret_cast(keyData->data()), .len = keyData->size()}; + ncrypto::Buffer buffer{.data = reinterpret_cast(keyData.data()), .len = keyData.size()}; auto pkey = ncrypto::EVPKeyPointer::NewRawPublic(nid, buffer); if (!pkey) { throw std::runtime_error("Failed to create raw public key"); @@ -1475,7 +1473,7 @@ bool HybridKeyObjectHandle::initRawPublic(const std::string& asymmetricKeyType, return true; } -bool HybridKeyObjectHandle::initRawPrivate(const std::string& asymmetricKeyType, const std::shared_ptr& keyData, +bool HybridKeyObjectHandle::initRawPrivate(const std::string& asymmetricKeyType, const ArrayBuffer& keyData, const std::optional& namedCurve) { if (asymmetricKeyType.starts_with("slh-dsa-") || asymmetricKeyType.starts_with("SLH-DSA-")) throw std::runtime_error("SLH-DSA raw private keys require createPrivateKeyAsync()"); @@ -1518,11 +1516,11 @@ bool HybridKeyObjectHandle::initRawPrivate(const std::string& asymmetricKeyType, size_t order_size = (BN_num_bits(order) + 7) / 8; BN_free(order); - if (keyData->size() != order_size) { + if (keyData.size() != order_size) { throw std::runtime_error("Invalid EC private key length"); } - BIGNUM* priv_bn = BN_bin2bn(reinterpret_cast(keyData->data()), static_cast(keyData->size()), nullptr); + BIGNUM* priv_bn = BN_bin2bn(reinterpret_cast(keyData.data()), static_cast(keyData.size()), nullptr); if (!priv_bn) { throw std::runtime_error("Failed to decode EC private key"); } @@ -1557,7 +1555,7 @@ bool HybridKeyObjectHandle::initRawPrivate(const std::string& asymmetricKeyType, throw std::runtime_error("Invalid asymmetricKeyType for raw private key import: " + asymmetricKeyType); } - ncrypto::Buffer buffer{.data = reinterpret_cast(keyData->data()), .len = keyData->size()}; + ncrypto::Buffer buffer{.data = reinterpret_cast(keyData.data()), .len = keyData.size()}; auto pkey = ncrypto::EVPKeyPointer::NewRawPrivate(nid, buffer); if (!pkey) { throw std::runtime_error("Failed to create raw private key"); @@ -1566,7 +1564,7 @@ bool HybridKeyObjectHandle::initRawPrivate(const std::string& asymmetricKeyType, return true; } -bool HybridKeyObjectHandle::initRawSeed(const std::string& asymmetricKeyType, const std::shared_ptr& keyData) { +bool HybridKeyObjectHandle::initRawSeed(const std::string& asymmetricKeyType, const ArrayBuffer& keyData) { #if OPENSSL_VERSION_NUMBER >= 0x30500000L data_ = KeyObjectData(); @@ -1575,7 +1573,7 @@ bool HybridKeyObjectHandle::initRawSeed(const std::string& asymmetricKeyType, co throw std::runtime_error("Invalid asymmetricKeyType for raw seed import: " + asymmetricKeyType); } - ncrypto::Buffer buffer{.data = reinterpret_cast(keyData->data()), .len = keyData->size()}; + ncrypto::Buffer buffer{.data = reinterpret_cast(keyData.data()), .len = keyData.size()}; auto pkey = ncrypto::EVPKeyPointer::NewRawSeed(nid, buffer); if (!pkey) { throw std::runtime_error("Failed to create key from raw seed"); @@ -1599,9 +1597,9 @@ bool HybridKeyObjectHandle::keyEquals(const std::shared_ptrsize() != otherKey->size()) + if (thisKey.size() != otherKey.size()) return false; - return CRYPTO_memcmp(thisKey->data(), otherKey->data(), thisKey->size()) == 0; + return CRYPTO_memcmp(thisKey.data(), otherKey.data(), thisKey.size()) == 0; } const auto& thisPkey = data_.GetAsymmetricKey(); diff --git a/packages/react-native-quick-crypto/cpp/keys/HybridKeyObjectHandle.hpp b/packages/react-native-quick-crypto/cpp/keys/HybridKeyObjectHandle.hpp index d8f97e7f2..32ad6c15e 100644 --- a/packages/react-native-quick-crypto/cpp/keys/HybridKeyObjectHandle.hpp +++ b/packages/react-native-quick-crypto/cpp/keys/HybridKeyObjectHandle.hpp @@ -4,55 +4,60 @@ #include #include -#include "HybridKeyObjectHandleSpec.hpp" -#include "JWK.hpp" -#include "KeyDetail.hpp" #include "KeyObjectData.hpp" -#include "KeyType.hpp" -#include "NamedCurve.hpp" +#include +#include +#include +#include +#include namespace margelo::nitro::crypto { class HybridKeyObjectHandle : public HybridKeyObjectHandleSpec { public: + struct Class { + using Base = HybridKeyObjectHandleSpec::Class; + static constexpr const char* name = "KeyObjectHandle"; + static const std::shared_ptr& get(); + }; + HybridKeyObjectHandle(); void dispose() override; public: - std::shared_ptr exportKey(std::optional format, std::optional type, - const std::optional& cipher, - const std::optional>& passphrase) override; + ArrayBuffer exportKey(const std::optional& format, const std::optional& type, + const std::optional& cipher, const std::optional& passphrase) override; JWK exportJwk(const JWK& key, bool handleRsaPss) override; - std::shared_ptr exportRawPublic() override; + ArrayBuffer exportRawPublic() override; - std::shared_ptr exportRawPrivate() override; + ArrayBuffer exportRawPrivate() override; - std::shared_ptr exportRawSeed() override; + ArrayBuffer exportRawSeed() override; - std::shared_ptr exportECPublicRaw(bool compressed) override; + ArrayBuffer exportECPublicRaw(bool compressed) override; - std::shared_ptr exportECPrivateRaw() override; + ArrayBuffer exportECPrivateRaw() override; AsymmetricKeyType getAsymmetricKeyType() override; - bool init(KeyType keyType, const std::variant, std::string>& key, std::optional format, - std::optional type, const std::optional>& passphrase) override; + bool init(KeyType keyType, const std::variant& key, const std::optional& format, + const std::optional& type, const std::optional& passphrase) override; - bool initECRaw(const std::string& namedCurve, const std::shared_ptr& keyData) override; + bool initECRaw(const std::string& namedCurve, const ArrayBuffer& keyData) override; - bool initPqcRaw(const std::string& algorithmName, const std::shared_ptr& keyData, bool isPublic) override; + bool initPqcRaw(const std::string& algorithmName, const ArrayBuffer& keyData, bool isPublic) override; - bool initRawPublic(const std::string& asymmetricKeyType, const std::shared_ptr& keyData, + bool initRawPublic(const std::string& asymmetricKeyType, const ArrayBuffer& keyData, const std::optional& namedCurve) override; - bool initRawPrivate(const std::string& asymmetricKeyType, const std::shared_ptr& keyData, + bool initRawPrivate(const std::string& asymmetricKeyType, const ArrayBuffer& keyData, const std::optional& namedCurve) override; - bool initRawSeed(const std::string& asymmetricKeyType, const std::shared_ptr& keyData) override; + bool initRawSeed(const std::string& asymmetricKeyType, const ArrayBuffer& keyData) override; - std::optional initJwk(const JWK& keyData, std::optional namedCurve) override; + std::optional initJwk(const JWK& keyData, const std::optional& namedCurve) override; KeyDetail keyDetail() override; @@ -71,14 +76,16 @@ class HybridKeyObjectHandle : public HybridKeyObjectHandleSpec { } protected: - void loadHybridMethods() override; + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } private: facebook::jsi::Value importSlhDsaRawPrivateKey(facebook::jsi::Runtime& runtime, const facebook::jsi::Value& thisArg, const facebook::jsi::Value* args, size_t argCount); KeyObjectData data_; - bool initRawKey(KeyType keyType, std::shared_ptr keyData); + bool initRawKey(KeyType keyType, const ArrayBuffer& keyData); }; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/cpp/keys/KeyObjectData.cpp b/packages/react-native-quick-crypto/cpp/keys/KeyObjectData.cpp index b34818ec5..ec021cd8f 100644 --- a/packages/react-native-quick-crypto/cpp/keys/KeyObjectData.cpp +++ b/packages/react-native-quick-crypto/cpp/keys/KeyObjectData.cpp @@ -21,8 +21,8 @@ ncrypto::EVPKeyPointer::PublicKeyEncodingConfig GetPublicKeyEncodingConfig(KForm return config; } -KeyObjectData TryParsePrivateKey(std::shared_ptr key, std::optional format, std::optional type, - const std::optional>& passphrase) { +KeyObjectData TryParsePrivateKey(const ArrayBuffer& key, std::optional format, std::optional type, + const std::optional& passphrase) { // For PEM format, use PKCS8 as default encoding KeyEncoding actualType = type.value_or(KeyEncoding::PKCS8); auto config = GetPrivateKeyEncodingConfig(format.value(), actualType); @@ -30,10 +30,10 @@ KeyObjectData TryParsePrivateKey(std::shared_ptr key, std::optional if (passphrase.has_value()) { auto& passphrase_ptr = passphrase.value(); config.passphrase = - std::make_optional(ncrypto::DataPointer::Copy(ncrypto::Buffer{passphrase_ptr->data(), passphrase_ptr->size()})); + std::make_optional(ncrypto::DataPointer::Copy(ncrypto::Buffer{passphrase_ptr.data(), passphrase_ptr.size()})); } - auto buffer = ncrypto::Buffer{key->data(), key->size()}; + auto buffer = ncrypto::Buffer{key.data(), key.size()}; // Clear any existing OpenSSL errors before parsing ERR_clear_error(); @@ -64,13 +64,13 @@ KeyObjectData TryParsePrivateKey(std::shared_ptr key, std::optional KeyObjectData::KeyObjectData(std::nullptr_t) : key_type_(KeyType::SECRET) {} -KeyObjectData::KeyObjectData(std::shared_ptr symmetric_key) +KeyObjectData::KeyObjectData(ArrayBuffer symmetric_key) : key_type_(KeyType::SECRET), data_(std::make_shared(std::move(symmetric_key))) {} KeyObjectData::KeyObjectData(KeyType type, ncrypto::EVPKeyPointer&& pkey) : key_type_(type), data_(std::make_shared(std::move(pkey))) {} -KeyObjectData KeyObjectData::CreateSecret(std::shared_ptr key) { +KeyObjectData KeyObjectData::CreateSecret(ArrayBuffer key) { return KeyObjectData(std::move(key)); } @@ -96,14 +96,14 @@ const ncrypto::EVPKeyPointer& KeyObjectData::GetAsymmetricKey() const { return data_->asymmetric_key; } -std::shared_ptr KeyObjectData::GetSymmetricKey() const { +ArrayBuffer KeyObjectData::GetSymmetricKey() const { if (key_type_ != KeyType::SECRET) { throw std::runtime_error("Cannot get symmetric key from asymmetric key object"); } if (!data_) { throw std::runtime_error("Invalid key object: no key data available"); } - return data_->symmetric_key; + return *data_->symmetric_key; } size_t KeyObjectData::GetSymmetricKeySize() const { @@ -116,17 +116,16 @@ size_t KeyObjectData::GetSymmetricKeySize() const { return data_->symmetric_key->size(); } -KeyObjectData KeyObjectData::GetPublicOrPrivateKey(std::shared_ptr key, std::optional format, - std::optional type, - const std::optional>& passphrase) { - if (key->size() > static_cast(std::numeric_limits::max())) { +KeyObjectData KeyObjectData::GetPublicOrPrivateKey(const ArrayBuffer& key, std::optional format, + std::optional type, const std::optional& passphrase) { + if (key.size() > static_cast(std::numeric_limits::max())) { throw std::runtime_error("key is too big"); } KFormatType actualFormat = format.value_or(KFormatType::DER); if (actualFormat == KFormatType::PEM || actualFormat == KFormatType::DER) { - auto buffer = ncrypto::Buffer{key->data(), key->size()}; + auto buffer = ncrypto::Buffer{key.data(), key.size()}; if (actualFormat == KFormatType::PEM) { if (type.has_value() && type.value() == KeyEncoding::SPKI) { @@ -143,7 +142,7 @@ KeyObjectData KeyObjectData::GetPublicOrPrivateKey(std::shared_ptr if (passphrase.has_value()) { auto& passphrase_ptr = passphrase.value(); config.passphrase = - std::make_optional(ncrypto::DataPointer::Copy(ncrypto::Buffer{passphrase_ptr->data(), passphrase_ptr->size()})); + std::make_optional(ncrypto::DataPointer::Copy(ncrypto::Buffer{passphrase_ptr.data(), passphrase_ptr.size()})); } ERR_clear_error(); auto private_res = ncrypto::EVPKeyPointer::TryParsePrivateKey(config, buffer); @@ -166,7 +165,7 @@ KeyObjectData KeyObjectData::GetPublicOrPrivateKey(std::shared_ptr if (passphrase.has_value()) { auto& passphrase_ptr = passphrase.value(); config.passphrase = - std::make_optional(ncrypto::DataPointer::Copy(ncrypto::Buffer{passphrase_ptr->data(), passphrase_ptr->size()})); + std::make_optional(ncrypto::DataPointer::Copy(ncrypto::Buffer{passphrase_ptr.data(), passphrase_ptr.size()})); } ERR_clear_error(); @@ -200,7 +199,7 @@ KeyObjectData KeyObjectData::GetPublicOrPrivateKey(std::shared_ptr if (passphrase.has_value()) { auto& passphrase_ptr = passphrase.value(); private_config.passphrase = - std::make_optional(ncrypto::DataPointer::Copy(ncrypto::Buffer{passphrase_ptr->data(), passphrase_ptr->size()})); + std::make_optional(ncrypto::DataPointer::Copy(ncrypto::Buffer{passphrase_ptr.data(), passphrase_ptr.size()})); } ERR_clear_error(); auto res = ncrypto::EVPKeyPointer::TryParsePrivateKey(private_config, buffer); @@ -223,7 +222,7 @@ KeyObjectData KeyObjectData::GetPublicOrPrivateKey(std::shared_ptr if (passphrase.has_value()) { auto& passphrase_ptr = passphrase.value(); private_config.passphrase = - std::make_optional(ncrypto::DataPointer::Copy(ncrypto::Buffer{passphrase_ptr->data(), passphrase_ptr->size()})); + std::make_optional(ncrypto::DataPointer::Copy(ncrypto::Buffer{passphrase_ptr.data(), passphrase_ptr.size()})); } auto private_res = ncrypto::EVPKeyPointer::TryParsePrivateKey(private_config, buffer); if (private_res) { @@ -244,13 +243,12 @@ KeyObjectData KeyObjectData::GetPublicOrPrivateKey(std::shared_ptr throw std::runtime_error("Unsupported key format for GetPublicOrPrivateKey. Only PEM and DER are supported."); } -KeyObjectData KeyObjectData::GetPrivateKey(std::shared_ptr key, std::optional format, - std::optional type, const std::optional>& passphrase, - bool /* isPublic */) { +KeyObjectData KeyObjectData::GetPrivateKey(const ArrayBuffer& key, std::optional format, std::optional type, + const std::optional& passphrase, bool /* isPublic */) { // Check if key size fits in int32_t without using double conversion - if (key->size() > static_cast(std::numeric_limits::max())) { - std::string error_msg = "key is too big (int32): size=" + std::to_string(key->size()) + - ", max_int32=" + std::to_string(std::numeric_limits::max()); + if (key.size() > static_cast(std::numeric_limits::max())) { + std::string error_msg = + "key is too big (int32): size=" + std::to_string(key.size()) + ", max_int32=" + std::to_string(std::numeric_limits::max()); throw std::runtime_error(error_msg); } @@ -258,7 +256,7 @@ KeyObjectData KeyObjectData::GetPrivateKey(std::shared_ptr key, std KFormatType actualFormat = format.has_value() ? format.value() : KFormatType::DER; if (actualFormat == KFormatType::PEM || actualFormat == KFormatType::DER) { - auto buffer = ncrypto::Buffer{key->data(), key->size()}; + auto buffer = ncrypto::Buffer{key.data(), key.size()}; if (actualFormat == KFormatType::PEM) { return TryParsePrivateKey(key, format, type, passphrase); @@ -269,7 +267,7 @@ KeyObjectData KeyObjectData::GetPrivateKey(std::shared_ptr key, std if (passphrase.has_value()) { auto& passphrase_ptr = passphrase.value(); private_config.passphrase = - std::make_optional(ncrypto::DataPointer::Copy(ncrypto::Buffer{passphrase_ptr->data(), passphrase_ptr->size()})); + std::make_optional(ncrypto::DataPointer::Copy(ncrypto::Buffer{passphrase_ptr.data(), passphrase_ptr.size()})); } // Clear any existing OpenSSL errors before parsing diff --git a/packages/react-native-quick-crypto/cpp/keys/KeyObjectData.hpp b/packages/react-native-quick-crypto/cpp/keys/KeyObjectData.hpp index f597ec4f0..545c69984 100644 --- a/packages/react-native-quick-crypto/cpp/keys/KeyObjectData.hpp +++ b/packages/react-native-quick-crypto/cpp/keys/KeyObjectData.hpp @@ -4,17 +4,17 @@ #include -#include "KFormatType.hpp" -#include "KeyEncoding.hpp" -#include "KeyType.hpp" #include "QuickCryptoUtils.hpp" +#include +#include +#include #include namespace margelo::nitro::crypto { class KeyObjectData final { public: - static KeyObjectData CreateSecret(std::shared_ptr key); + static KeyObjectData CreateSecret(ArrayBuffer key); static KeyObjectData CreateAsymmetric(KeyType type, ncrypto::EVPKeyPointer&& pkey); @@ -29,15 +29,14 @@ class KeyObjectData final { // These functions allow unprotected access to the raw key material and should // only be used to implement cryptographic operations requiring the key. const ncrypto::EVPKeyPointer& GetAsymmetricKey() const; - std::shared_ptr GetSymmetricKey() const; + ArrayBuffer GetSymmetricKey() const; size_t GetSymmetricKeySize() const; - static KeyObjectData GetPublicOrPrivateKey(std::shared_ptr key, std::optional format, - std::optional type, - const std::optional>& passphrase); + static KeyObjectData GetPublicOrPrivateKey(const ArrayBuffer& key, std::optional format, std::optional type, + const std::optional& passphrase); - static KeyObjectData GetPrivateKey(std::shared_ptr key, std::optional format, std::optional type, - const std::optional>& passphrase, bool isPublic); + static KeyObjectData GetPrivateKey(const ArrayBuffer& key, std::optional format, std::optional type, + const std::optional& passphrase, bool isPublic); inline KeyObjectData addRef() const { return KeyObjectData(key_type_, data_); @@ -48,7 +47,7 @@ class KeyObjectData final { } private: - explicit KeyObjectData(std::shared_ptr symmetric_key); + explicit KeyObjectData(ArrayBuffer symmetric_key); explicit KeyObjectData(KeyType type, ncrypto::EVPKeyPointer&& pkey); // static KeyObjectData GetParsedKey(KeyType type, @@ -60,9 +59,9 @@ class KeyObjectData final { KeyType key_type_; struct Data { - const std::shared_ptr symmetric_key; + const std::optional symmetric_key; const ncrypto::EVPKeyPointer asymmetric_key; - explicit Data(std::shared_ptr symmetric_key) : symmetric_key(std::move(symmetric_key)) {} + explicit Data(ArrayBuffer symmetric_key) : symmetric_key(std::move(symmetric_key)) {} explicit Data(ncrypto::EVPKeyPointer asymmetric_key) : asymmetric_key(std::move(asymmetric_key)) {} }; std::shared_ptr data_; diff --git a/packages/react-native-quick-crypto/cpp/kmac/HybridKmac.cpp b/packages/react-native-quick-crypto/cpp/kmac/HybridKmac.cpp index 7da17ae76..61bf7b91e 100644 --- a/packages/react-native-quick-crypto/cpp/kmac/HybridKmac.cpp +++ b/packages/react-native-quick-crypto/cpp/kmac/HybridKmac.cpp @@ -7,11 +7,12 @@ #include #include "HybridKmac.hpp" +#include "QuickCryptoUtils.hpp" namespace margelo::nitro::crypto { -void HybridKmac::createKmac(const std::string& algorithm, const std::shared_ptr& key, double outputLength, - const std::optional>& customization) { +void HybridKmac::createKmac(const std::string& algorithm, const ArrayBuffer& key, double outputLength, + const std::optional& customization) { outputLen = static_cast(outputLength); if (outputLen == 0) { throw std::runtime_error("KMAC output length must be greater than 0"); @@ -33,16 +34,16 @@ void HybridKmac::createKmac(const std::string& algorithm, const std::shared_ptr< params[paramCount++] = OSSL_PARAM_construct_size_t(OSSL_MAC_PARAM_SIZE, &outputLen); std::vector custData; - if (customization.has_value() && customization.value()->size() > 0) { + if (customization.has_value() && customization.value().size() > 0) { const auto& custBuf = customization.value(); - custData.assign(reinterpret_cast(custBuf->data()), reinterpret_cast(custBuf->data()) + custBuf->size()); + custData.assign(reinterpret_cast(custBuf.data()), reinterpret_cast(custBuf.data()) + custBuf.size()); params[paramCount++] = OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_CUSTOM, custData.data(), custData.size()); } params[paramCount] = OSSL_PARAM_construct_end(); - const uint8_t* keyData = reinterpret_cast(key->data()); - size_t keySize = key->size(); + const uint8_t* keyData = dataOrEmpty(key); + size_t keySize = key.size(); if (keySize == 0) { throw std::runtime_error("KMAC key must not be empty"); @@ -53,17 +54,17 @@ void HybridKmac::createKmac(const std::string& algorithm, const std::shared_ptr< } } -void HybridKmac::update(const std::shared_ptr& data) { +void HybridKmac::update(const ArrayBuffer& data) { if (!ctx) { throw std::runtime_error("KMAC context not initialized"); } - if (EVP_MAC_update(ctx.get(), reinterpret_cast(data->data()), data->size()) != 1) { + if (EVP_MAC_update(ctx.get(), dataOrEmpty(data), data.size()) != 1) { throw std::runtime_error("Failed to update KMAC: " + std::to_string(ERR_get_error())); } } -std::shared_ptr HybridKmac::digest() { +ArrayBuffer HybridKmac::digest() { if (!ctx) { throw std::runtime_error("KMAC context not initialized"); } @@ -77,7 +78,7 @@ std::shared_ptr HybridKmac::digest() { ctx.reset(); uint8_t* raw_ptr = buffer.get(); - return std::make_shared(buffer.release(), outputLen, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(buffer.release(), outputLen, [raw_ptr]() { delete[] raw_ptr; }); } } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/cpp/kmac/HybridKmac.hpp b/packages/react-native-quick-crypto/cpp/kmac/HybridKmac.hpp index 4778dbcc3..b096b6de5 100644 --- a/packages/react-native-quick-crypto/cpp/kmac/HybridKmac.hpp +++ b/packages/react-native-quick-crypto/cpp/kmac/HybridKmac.hpp @@ -5,7 +5,7 @@ #include #include -#include "HybridKmacSpec.hpp" +#include namespace margelo::nitro::crypto { @@ -15,13 +15,13 @@ using EVP_MAC_CTX_ptr = std::unique_ptr& key, double outputLength, - const std::optional>& customization) override; - void update(const std::shared_ptr& data) override; - std::shared_ptr digest() override; + void createKmac(const std::string& algorithm, const ArrayBuffer& key, double outputLength, + const std::optional& customization) override; + void update(const ArrayBuffer& data) override; + ArrayBuffer digest() override; private: EVP_MAC_CTX_ptr ctx{nullptr, EVP_MAC_CTX_free}; diff --git a/packages/react-native-quick-crypto/cpp/mldsa/HybridMlDsaKeyPair.cpp b/packages/react-native-quick-crypto/cpp/mldsa/HybridMlDsaKeyPair.cpp index a9e130dfc..663cc3e03 100644 --- a/packages/react-native-quick-crypto/cpp/mldsa/HybridMlDsaKeyPair.cpp +++ b/packages/react-native-quick-crypto/cpp/mldsa/HybridMlDsaKeyPair.cpp @@ -40,8 +40,7 @@ void HybridMlDsaKeyPair::setVariant(const std::string& variant) { variant_ = variant; } -std::shared_ptr> HybridMlDsaKeyPair::generateKeyPair(double publicFormat, double publicType, double privateFormat, - double privateType) { +Promise HybridMlDsaKeyPair::generateKeyPair(double publicFormat, double publicType, double privateFormat, double privateType) { auto self = this->shared_cast(); return Promise::async([self, publicFormat, publicType, privateFormat, privateType]() { self->generateKeyPairSync(publicFormat, publicType, privateFormat, privateType); @@ -82,7 +81,7 @@ void HybridMlDsaKeyPair::generateKeyPairSync(double publicFormat, double publicT #endif } -std::shared_ptr HybridMlDsaKeyPair::getPublicKey() { +ArrayBuffer HybridMlDsaKeyPair::getPublicKey() { #if !RNQC_HAS_ML_DSA throw std::runtime_error("ML-DSA requires OpenSSL 3.5+"); #else @@ -115,11 +114,11 @@ std::shared_ptr HybridMlDsaKeyPair::getPublicKey() { BIO_free(bio); uint8_t* raw_ptr = buf.get(); - return std::make_shared(buf.release(), len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(buf.release(), len, [raw_ptr]() { delete[] raw_ptr; }); #endif } -std::shared_ptr HybridMlDsaKeyPair::getPrivateKey() { +ArrayBuffer HybridMlDsaKeyPair::getPrivateKey() { #if !RNQC_HAS_ML_DSA throw std::runtime_error("ML-DSA requires OpenSSL 3.5+"); #else @@ -154,17 +153,17 @@ std::shared_ptr HybridMlDsaKeyPair::getPrivateKey() { BIO_free(bio); uint8_t* raw_ptr = buf.get(); - return std::make_shared(buf.release(), len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(buf.release(), len, [raw_ptr]() { delete[] raw_ptr; }); #endif } -std::shared_ptr>> HybridMlDsaKeyPair::sign(const std::shared_ptr& message) { +Promise HybridMlDsaKeyPair::sign(const ArrayBuffer& message) { auto nativeMessage = ToNativeArrayBuffer(message); auto self = this->shared_cast(); - return Promise>::async([self, nativeMessage]() { return self->signSync(nativeMessage); }); + return Promise::async([self, nativeMessage]() { return self->signSync(nativeMessage); }); } -std::shared_ptr HybridMlDsaKeyPair::signSync(const std::shared_ptr& message) { +ArrayBuffer HybridMlDsaKeyPair::signSync(const ArrayBuffer& message) { #if !RNQC_HAS_ML_DSA throw std::runtime_error("ML-DSA requires OpenSSL 3.5+"); #else @@ -183,30 +182,29 @@ std::shared_ptr HybridMlDsaKeyPair::signSync(const std::shared_ptr< } size_t sig_len = 0; - if (EVP_DigestSign(md_ctx.get(), nullptr, &sig_len, message->data(), message->size()) <= 0) { + if (EVP_DigestSign(md_ctx.get(), nullptr, &sig_len, dataOrEmpty(message), message.size()) <= 0) { throw std::runtime_error("Failed to calculate signature size: " + getOpenSSLError()); } auto sig = std::make_unique(sig_len); - if (EVP_DigestSign(md_ctx.get(), sig.get(), &sig_len, message->data(), message->size()) <= 0) { + if (EVP_DigestSign(md_ctx.get(), sig.get(), &sig_len, dataOrEmpty(message), message.size()) <= 0) { throw std::runtime_error("Failed to sign message: " + getOpenSSLError()); } uint8_t* raw_ptr = sig.get(); - return std::make_shared(sig.release(), sig_len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(sig.release(), sig_len, [raw_ptr]() { delete[] raw_ptr; }); #endif } -std::shared_ptr> HybridMlDsaKeyPair::verify(const std::shared_ptr& signature, - const std::shared_ptr& message) { +Promise HybridMlDsaKeyPair::verify(const ArrayBuffer& signature, const ArrayBuffer& message) { auto nativeSignature = ToNativeArrayBuffer(signature); auto nativeMessage = ToNativeArrayBuffer(message); auto self = this->shared_cast(); return Promise::async([self, nativeSignature, nativeMessage]() { return self->verifySync(nativeSignature, nativeMessage); }); } -bool HybridMlDsaKeyPair::verifySync(const std::shared_ptr& signature, const std::shared_ptr& message) { +bool HybridMlDsaKeyPair::verifySync(const ArrayBuffer& signature, const ArrayBuffer& message) { #if !RNQC_HAS_ML_DSA throw std::runtime_error("ML-DSA requires OpenSSL 3.5+"); #else @@ -224,7 +222,7 @@ bool HybridMlDsaKeyPair::verifySync(const std::shared_ptr& signatur throw std::runtime_error("Failed to initialize verification: " + getOpenSSLError()); } - int result = EVP_DigestVerify(md_ctx.get(), signature->data(), signature->size(), message->data(), message->size()); + int result = EVP_DigestVerify(md_ctx.get(), dataOrEmpty(signature), signature.size(), dataOrEmpty(message), message.size()); if (result < 0) { throw std::runtime_error("Verification error: " + getOpenSSLError()); diff --git a/packages/react-native-quick-crypto/cpp/mldsa/HybridMlDsaKeyPair.hpp b/packages/react-native-quick-crypto/cpp/mldsa/HybridMlDsaKeyPair.hpp index dca2ef9a7..335a0bd67 100644 --- a/packages/react-native-quick-crypto/cpp/mldsa/HybridMlDsaKeyPair.hpp +++ b/packages/react-native-quick-crypto/cpp/mldsa/HybridMlDsaKeyPair.hpp @@ -4,30 +4,29 @@ #include #include -#include "HybridMlDsaKeyPairSpec.hpp" +#include namespace margelo::nitro::crypto { class HybridMlDsaKeyPair : public HybridMlDsaKeyPairSpec { public: - HybridMlDsaKeyPair() : HybridObject(TAG) {} + HybridMlDsaKeyPair() = default; ~HybridMlDsaKeyPair() override = default; - std::shared_ptr> generateKeyPair(double publicFormat, double publicType, double privateFormat, double privateType) override; + Promise generateKeyPair(double publicFormat, double publicType, double privateFormat, double privateType) override; void generateKeyPairSync(double publicFormat, double publicType, double privateFormat, double privateType) override; - std::shared_ptr getPublicKey() override; - std::shared_ptr getPrivateKey() override; + ArrayBuffer getPublicKey() override; + ArrayBuffer getPrivateKey() override; - std::shared_ptr>> sign(const std::shared_ptr& message) override; + Promise sign(const ArrayBuffer& message) override; - std::shared_ptr signSync(const std::shared_ptr& message) override; + ArrayBuffer signSync(const ArrayBuffer& message) override; - std::shared_ptr> verify(const std::shared_ptr& signature, - const std::shared_ptr& message) override; + Promise verify(const ArrayBuffer& signature, const ArrayBuffer& message) override; - bool verifySync(const std::shared_ptr& signature, const std::shared_ptr& message) override; + bool verifySync(const ArrayBuffer& signature, const ArrayBuffer& message) override; void setVariant(const std::string& variant) override; diff --git a/packages/react-native-quick-crypto/cpp/mlkem/HybridMlKemKeyPair.cpp b/packages/react-native-quick-crypto/cpp/mlkem/HybridMlKemKeyPair.cpp index 97d4cbb95..bb484bd9e 100644 --- a/packages/react-native-quick-crypto/cpp/mlkem/HybridMlKemKeyPair.cpp +++ b/packages/react-native-quick-crypto/cpp/mlkem/HybridMlKemKeyPair.cpp @@ -27,8 +27,7 @@ void HybridMlKemKeyPair::setVariant(const std::string& variant) { variant_ = variant; } -std::shared_ptr> HybridMlKemKeyPair::generateKeyPair(double publicFormat, double publicType, double privateFormat, - double privateType) { +Promise HybridMlKemKeyPair::generateKeyPair(double publicFormat, double publicType, double privateFormat, double privateType) { auto self = this->shared_cast(); return Promise::async([self, publicFormat, publicType, privateFormat, privateType]() { self->generateKeyPairSync(publicFormat, publicType, privateFormat, privateType); @@ -70,7 +69,7 @@ void HybridMlKemKeyPair::generateKeyPairSync(double publicFormat, double publicT #endif } -std::shared_ptr HybridMlKemKeyPair::getPublicKey() { +ArrayBuffer HybridMlKemKeyPair::getPublicKey() { #if !RNQC_HAS_ML_KEM throw std::runtime_error("ML-KEM requires OpenSSL 3.5+"); #else @@ -103,11 +102,11 @@ std::shared_ptr HybridMlKemKeyPair::getPublicKey() { BIO_free(bio); uint8_t* raw_ptr = buf.get(); - return std::make_shared(buf.release(), len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(buf.release(), len, [raw_ptr]() { delete[] raw_ptr; }); #endif } -std::shared_ptr HybridMlKemKeyPair::getPrivateKey() { +ArrayBuffer HybridMlKemKeyPair::getPrivateKey() { #if !RNQC_HAS_ML_KEM throw std::runtime_error("ML-KEM requires OpenSSL 3.5+"); #else @@ -142,11 +141,11 @@ std::shared_ptr HybridMlKemKeyPair::getPrivateKey() { BIO_free(bio); uint8_t* raw_ptr = buf.get(); - return std::make_shared(buf.release(), len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(buf.release(), len, [raw_ptr]() { delete[] raw_ptr; }); #endif } -void HybridMlKemKeyPair::setPublicKey(const std::shared_ptr& keyData, double format, double type) { +void HybridMlKemKeyPair::setPublicKey(const ArrayBuffer& keyData, double format, double type) { #if !RNQC_HAS_ML_KEM throw std::runtime_error("ML-KEM requires OpenSSL 3.5+"); #else @@ -159,7 +158,7 @@ void HybridMlKemKeyPair::setPublicKey(const std::shared_ptr& keyDat publicFormat_ = static_cast(format); publicType_ = static_cast(type); - BIO* bio = BIO_new_mem_buf(keyData->data(), static_cast(keyData->size())); + BIO* bio = BIO_new_mem_buf(dataOrEmpty(keyData), static_cast(keyData.size())); if (!bio) { throw std::runtime_error("Failed to create BIO for public key import"); } @@ -181,7 +180,7 @@ void HybridMlKemKeyPair::setPublicKey(const std::shared_ptr& keyDat #endif } -void HybridMlKemKeyPair::setPrivateKey(const std::shared_ptr& keyData, double format, double type) { +void HybridMlKemKeyPair::setPrivateKey(const ArrayBuffer& keyData, double format, double type) { #if !RNQC_HAS_ML_KEM throw std::runtime_error("ML-KEM requires OpenSSL 3.5+"); #else @@ -194,7 +193,7 @@ void HybridMlKemKeyPair::setPrivateKey(const std::shared_ptr& keyDa privateFormat_ = static_cast(format); privateType_ = static_cast(type); - BIO* bio = BIO_new_mem_buf(keyData->data(), static_cast(keyData->size())); + BIO* bio = BIO_new_mem_buf(dataOrEmpty(keyData), static_cast(keyData.size())); if (!bio) { throw std::runtime_error("Failed to create BIO for private key import"); } @@ -216,12 +215,12 @@ void HybridMlKemKeyPair::setPrivateKey(const std::shared_ptr& keyDa #endif } -std::shared_ptr>> HybridMlKemKeyPair::encapsulate() { +Promise HybridMlKemKeyPair::encapsulate() { auto self = this->shared_cast(); - return Promise>::async([self]() { return self->encapsulateSync(); }); + return Promise::async([self]() { return self->encapsulateSync(); }); } -std::shared_ptr HybridMlKemKeyPair::encapsulateSync() { +ArrayBuffer HybridMlKemKeyPair::encapsulateSync() { #if !RNQC_HAS_ML_KEM throw std::runtime_error("ML-KEM requires OpenSSL 3.5+"); #else @@ -261,17 +260,17 @@ std::shared_ptr HybridMlKemKeyPair::encapsulateSync() { } uint8_t* raw_ptr = out.get(); - return std::make_shared(out.release(), total_size, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(out.release(), total_size, [raw_ptr]() { delete[] raw_ptr; }); #endif } -std::shared_ptr>> HybridMlKemKeyPair::decapsulate(const std::shared_ptr& ciphertext) { +Promise HybridMlKemKeyPair::decapsulate(const ArrayBuffer& ciphertext) { auto nativeCiphertext = ToNativeArrayBuffer(ciphertext); auto self = this->shared_cast(); - return Promise>::async([self, nativeCiphertext]() { return self->decapsulateSync(nativeCiphertext); }); + return Promise::async([self, nativeCiphertext]() { return self->decapsulateSync(nativeCiphertext); }); } -std::shared_ptr HybridMlKemKeyPair::decapsulateSync(const std::shared_ptr& ciphertext) { +ArrayBuffer HybridMlKemKeyPair::decapsulateSync(const ArrayBuffer& ciphertext) { #if !RNQC_HAS_ML_KEM throw std::runtime_error("ML-KEM requires OpenSSL 3.5+"); #else @@ -287,8 +286,8 @@ std::shared_ptr HybridMlKemKeyPair::decapsulateSync(const std::shar throw std::runtime_error("Failed to initialize decapsulation: " + getOpenSSLError()); } - const uint8_t* ct_data = ciphertext->data(); - size_t ct_size = ciphertext->size(); + const uint8_t* ct_data = dataOrEmpty(ciphertext); + size_t ct_size = ciphertext.size(); size_t sk_len = 0; if (EVP_PKEY_decapsulate(ctx.get(), nullptr, &sk_len, ct_data, ct_size) <= 0) { @@ -302,7 +301,7 @@ std::shared_ptr HybridMlKemKeyPair::decapsulateSync(const std::shar } uint8_t* raw_ptr = sk_buf.get(); - return std::make_shared(sk_buf.release(), sk_len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(sk_buf.release(), sk_len, [raw_ptr]() { delete[] raw_ptr; }); #endif } diff --git a/packages/react-native-quick-crypto/cpp/mlkem/HybridMlKemKeyPair.hpp b/packages/react-native-quick-crypto/cpp/mlkem/HybridMlKemKeyPair.hpp index eb9180ecd..86072059f 100644 --- a/packages/react-native-quick-crypto/cpp/mlkem/HybridMlKemKeyPair.hpp +++ b/packages/react-native-quick-crypto/cpp/mlkem/HybridMlKemKeyPair.hpp @@ -4,32 +4,32 @@ #include #include -#include "HybridMlKemKeyPairSpec.hpp" #include "QuickCryptoUtils.hpp" +#include namespace margelo::nitro::crypto { class HybridMlKemKeyPair : public HybridMlKemKeyPairSpec { public: - HybridMlKemKeyPair() : HybridObject(TAG) {} + HybridMlKemKeyPair() = default; ~HybridMlKemKeyPair() override = default; void setVariant(const std::string& variant) override; - std::shared_ptr> generateKeyPair(double publicFormat, double publicType, double privateFormat, double privateType) override; + Promise generateKeyPair(double publicFormat, double publicType, double privateFormat, double privateType) override; void generateKeyPairSync(double publicFormat, double publicType, double privateFormat, double privateType) override; - std::shared_ptr getPublicKey() override; - std::shared_ptr getPrivateKey() override; + ArrayBuffer getPublicKey() override; + ArrayBuffer getPrivateKey() override; - void setPublicKey(const std::shared_ptr& keyData, double format, double type) override; - void setPrivateKey(const std::shared_ptr& keyData, double format, double type) override; + void setPublicKey(const ArrayBuffer& keyData, double format, double type) override; + void setPrivateKey(const ArrayBuffer& keyData, double format, double type) override; - std::shared_ptr>> encapsulate() override; - std::shared_ptr encapsulateSync() override; + Promise encapsulate() override; + ArrayBuffer encapsulateSync() override; - std::shared_ptr>> decapsulate(const std::shared_ptr& ciphertext) override; - std::shared_ptr decapsulateSync(const std::shared_ptr& ciphertext) override; + Promise decapsulate(const ArrayBuffer& ciphertext) override; + ArrayBuffer decapsulateSync(const ArrayBuffer& ciphertext) override; private: std::string variant_; diff --git a/packages/react-native-quick-crypto/cpp/pbkdf2/HybridPbkdf2.cpp b/packages/react-native-quick-crypto/cpp/pbkdf2/HybridPbkdf2.cpp index ff51539b5..61c76b68a 100644 --- a/packages/react-native-quick-crypto/cpp/pbkdf2/HybridPbkdf2.cpp +++ b/packages/react-native-quick-crypto/cpp/pbkdf2/HybridPbkdf2.cpp @@ -3,48 +3,49 @@ namespace margelo::nitro::crypto { -std::shared_ptr>> HybridPbkdf2::pbkdf2(const std::shared_ptr& password, - const std::shared_ptr& salt, double iterations, - double keylen, const std::string& digest) { +Promise HybridPbkdf2::pbkdf2(const ArrayBuffer& password, const ArrayBuffer& salt, double iterations, double keylen, + const std::string& digest) { // get owned NativeArrayBuffers before passing to sync function auto nativePassword = ToNativeArrayBuffer(password); auto nativeSalt = ToNativeArrayBuffer(salt); - return Promise>::async([this, nativePassword, nativeSalt, iterations, keylen, digest]() { - return this->pbkdf2Sync(nativePassword, nativeSalt, iterations, keylen, digest); + return Promise::async([nativePassword, nativeSalt, iterations, keylen, digest]() { + return pbkdf2Sync(nativePassword, nativeSalt, iterations, keylen, digest); }); } -std::shared_ptr HybridPbkdf2::pbkdf2Sync(const std::shared_ptr& password, - const std::shared_ptr& salt, double iterations, double keylen, - const std::string& digest) { +ArrayBuffer HybridPbkdf2::pbkdf2Sync(const ArrayBuffer& password, const ArrayBuffer& salt, double iterations, double keylen, + const std::string& digest) { size_t bufferSize = static_cast(keylen); auto out_buf = std::make_unique(bufferSize); + const uint8_t* passwordData = dataOrEmpty(password); + const uint8_t* saltData = dataOrEmpty(salt); + // use fastpbkdf2 when possible if (digest == "sha1") { - fastpbkdf2_hmac_sha1(password.get()->data(), password.get()->size(), salt.get()->data(), salt.get()->size(), - static_cast(iterations), out_buf.get(), bufferSize); + fastpbkdf2_hmac_sha1(passwordData, password.size(), saltData, salt.size(), static_cast(iterations), out_buf.get(), + bufferSize); } else if (digest == "sha256") { - fastpbkdf2_hmac_sha256(password.get()->data(), password.get()->size(), salt.get()->data(), salt.get()->size(), - static_cast(iterations), out_buf.get(), bufferSize); + fastpbkdf2_hmac_sha256(passwordData, password.size(), saltData, salt.size(), static_cast(iterations), out_buf.get(), + bufferSize); } else if (digest == "sha512") { - fastpbkdf2_hmac_sha512(password.get()->data(), password.get()->size(), salt.get()->data(), salt.get()->size(), - static_cast(iterations), out_buf.get(), bufferSize); + fastpbkdf2_hmac_sha512(passwordData, password.size(), saltData, salt.size(), static_cast(iterations), out_buf.get(), + bufferSize); } else { // fallback to OpenSSL auto* digestByName = EVP_get_digestbyname(digest.c_str()); if (digestByName == nullptr) { throw std::runtime_error("Invalid hash-algorithm: " + digest); } - char* passAsCharA = reinterpret_cast(password.get()->data()); - const unsigned char* saltAsCharA = reinterpret_cast(salt.get()->data()); - PKCS5_PBKDF2_HMAC(passAsCharA, password.get()->size(), saltAsCharA, salt.get()->size(), static_cast(iterations), digestByName, - bufferSize, out_buf.get()); + const char* passAsCharA = reinterpret_cast(passwordData); + const unsigned char* saltAsCharA = saltData; + PKCS5_PBKDF2_HMAC(passAsCharA, password.size(), saltAsCharA, salt.size(), static_cast(iterations), digestByName, bufferSize, + out_buf.get()); } - uint8_t* raw_ptr = out_buf.get(); - return std::make_shared(out_buf.release(), bufferSize, [raw_ptr]() { delete[] raw_ptr; }); + uint8_t* raw_ptr = out_buf.release(); + return ArrayBuffer::wrap(raw_ptr, bufferSize, [raw_ptr]() { delete[] raw_ptr; }); } } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/cpp/pbkdf2/HybridPbkdf2.hpp b/packages/react-native-quick-crypto/cpp/pbkdf2/HybridPbkdf2.hpp index 4e9d29a85..9a4a7d980 100644 --- a/packages/react-native-quick-crypto/cpp/pbkdf2/HybridPbkdf2.hpp +++ b/packages/react-native-quick-crypto/cpp/pbkdf2/HybridPbkdf2.hpp @@ -1,7 +1,9 @@ +#pragma once + #include -#include "HybridPbkdf2Spec.hpp" #include "fastpbkdf2.h" +#include namespace margelo::nitro::crypto { @@ -9,16 +11,11 @@ using namespace facebook; class HybridPbkdf2 : public HybridPbkdf2Spec { public: - HybridPbkdf2() : HybridObject(TAG) {} - - public: - // Methods - std::shared_ptr>> pbkdf2(const std::shared_ptr& password, - const std::shared_ptr& salt, double iterations, double keylen, - const std::string& digest) override; + static Promise pbkdf2(const ArrayBuffer& password, const ArrayBuffer& salt, double iterations, double keylen, + const std::string& digest); - std::shared_ptr pbkdf2Sync(const std::shared_ptr& password, const std::shared_ptr& salt, - double iterations, double keylen, const std::string& digest) override; + static ArrayBuffer pbkdf2Sync(const ArrayBuffer& password, const ArrayBuffer& salt, double iterations, double keylen, + const std::string& digest); }; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/cpp/prime/HybridPrime.cpp b/packages/react-native-quick-crypto/cpp/prime/HybridPrime.cpp index f3719ca38..e4bba642d 100644 --- a/packages/react-native-quick-crypto/cpp/prime/HybridPrime.cpp +++ b/packages/react-native-quick-crypto/cpp/prime/HybridPrime.cpp @@ -6,15 +6,14 @@ namespace margelo::nitro::crypto { using namespace ncrypto; -static BignumPointer toBignum(const std::optional>& buf) { - if (!buf.has_value() || buf.value()->size() == 0) { +static BignumPointer toBignum(const std::optional& buf) { + if (!buf.has_value() || buf.value().size() == 0) { return BignumPointer(); } - return BignumPointer(buf.value()->data(), buf.value()->size()); + return BignumPointer(buf.value().data(), buf.value().size()); } -static std::shared_ptr generatePrimeImpl(double size, bool safe, const std::optional>& add, - const std::optional>& rem) { +static ArrayBuffer generatePrimeImpl(double size, bool safe, const std::optional& add, const std::optional& rem) { int bits = static_cast(size); auto addBn = toBignum(add); @@ -34,24 +33,23 @@ static std::shared_ptr generatePrimeImpl(double size, bool safe, co return ToNativeArrayBuffer(encoded.get(), encoded.size()); } -std::shared_ptr>> HybridPrime::generatePrime(double size, bool safe, - const std::optional>& add, - const std::optional>& rem) { - auto addCopy = add.has_value() ? std::make_optional(ToNativeArrayBuffer(add.value())) : std::nullopt; - auto remCopy = rem.has_value() ? std::make_optional(ToNativeArrayBuffer(rem.value())) : std::nullopt; +Promise HybridPrime::generatePrime(double size, bool safe, const std::optional& add, + const std::optional& rem) { + std::optional addCopy = add.has_value() ? std::make_optional(ToNativeArrayBuffer(add.value())) : std::nullopt; + std::optional remCopy = rem.has_value() ? std::make_optional(ToNativeArrayBuffer(rem.value())) : std::nullopt; - return Promise>::async([size, safe, addCopy = std::move(addCopy), remCopy = std::move(remCopy)]() { + return Promise::async([size, safe, addCopy = std::move(addCopy), remCopy = std::move(remCopy)]() { return generatePrimeImpl(size, safe, addCopy, remCopy); }); } -std::shared_ptr HybridPrime::generatePrimeSync(double size, bool safe, const std::optional>& add, - const std::optional>& rem) { +ArrayBuffer HybridPrime::generatePrimeSync(double size, bool safe, const std::optional& add, + const std::optional& rem) { return generatePrimeImpl(size, safe, add, rem); } -bool HybridPrime::checkPrimeSync(const std::shared_ptr& candidate, double checks) { - BignumPointer bn(candidate->data(), candidate->size()); +bool HybridPrime::checkPrimeSync(const ArrayBuffer& candidate, double checks) { + BignumPointer bn(dataOrEmpty(candidate), candidate.size()); if (!bn) { throw std::runtime_error("Invalid candidate"); } @@ -63,10 +61,10 @@ bool HybridPrime::checkPrimeSync(const std::shared_ptr& candidate, return result == 1; } -std::shared_ptr> HybridPrime::checkPrime(const std::shared_ptr& candidate, double checks) { +Promise HybridPrime::checkPrime(const ArrayBuffer& candidate, double checks) { auto candidateCopy = ToNativeArrayBuffer(candidate); return Promise::async([candidateCopy, checks]() { - BignumPointer bn(candidateCopy->data(), candidateCopy->size()); + BignumPointer bn(dataOrEmpty(candidateCopy), candidateCopy.size()); if (!bn) { throw std::runtime_error("Invalid candidate"); } diff --git a/packages/react-native-quick-crypto/cpp/prime/HybridPrime.hpp b/packages/react-native-quick-crypto/cpp/prime/HybridPrime.hpp index a7217f216..350b702e0 100644 --- a/packages/react-native-quick-crypto/cpp/prime/HybridPrime.hpp +++ b/packages/react-native-quick-crypto/cpp/prime/HybridPrime.hpp @@ -1,20 +1,17 @@ #pragma once -#include "HybridPrimeSpec.hpp" +#include namespace margelo::nitro::crypto { class HybridPrime : public HybridPrimeSpec { public: - HybridPrime() : HybridObject(TAG) {} - - std::shared_ptr>> generatePrime(double size, bool safe, - const std::optional>& add, - const std::optional>& rem) override; - std::shared_ptr generatePrimeSync(double size, bool safe, const std::optional>& add, - const std::optional>& rem) override; - std::shared_ptr> checkPrime(const std::shared_ptr& candidate, double checks) override; - bool checkPrimeSync(const std::shared_ptr& candidate, double checks) override; + static Promise generatePrime(double size, bool safe, const std::optional& add, + const std::optional& rem); + static ArrayBuffer generatePrimeSync(double size, bool safe, const std::optional& add, + const std::optional& rem); + static Promise checkPrime(const ArrayBuffer& candidate, double checks); + static bool checkPrimeSync(const ArrayBuffer& candidate, double checks); }; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/cpp/random/HybridRandom.cpp b/packages/react-native-quick-crypto/cpp/random/HybridRandom.cpp index f8bb6653f..a46085999 100644 --- a/packages/react-native-quick-crypto/cpp/random/HybridRandom.cpp +++ b/packages/react-native-quick-crypto/cpp/random/HybridRandom.cpp @@ -23,26 +23,22 @@ size_t checkOffset(double offset) { return static_cast(offset); } -std::shared_ptr>> HybridRandom::randomFill(const std::shared_ptr& buffer, double dOffset, - double dSize) { - // get owned NativeArrayBuffer before passing to sync function +Promise HybridRandom::randomFill(const ArrayBuffer& buffer, double dOffset, double dSize) { auto nativeBuffer = ToNativeArrayBuffer(buffer); + return Promise::async([nativeBuffer, dOffset, dSize]() { return randomFillSync(nativeBuffer, dOffset, dSize); }); +} - return Promise>::async( - [this, nativeBuffer, dOffset, dSize]() { return this->randomFillSync(nativeBuffer, dOffset, dSize); }); -}; - -std::shared_ptr HybridRandom::randomFillSync(const std::shared_ptr& buffer, double dOffset, double dSize) { +ArrayBuffer HybridRandom::randomFillSync(const ArrayBuffer& buffer, double dOffset, double dSize) { size_t size = checkSize(dSize); size_t offset = checkOffset(dOffset); - if (offset + size > buffer->size()) { + if (offset + size > buffer.size()) { throw std::runtime_error("offset + size must not exceed buffer length"); } - uint8_t* data = buffer->data(); + uint8_t* data = buffer.data(); if (RAND_bytes(data + offset, static_cast(size)) != 1) { throw std::runtime_error("error calling RAND_bytes: " + std::to_string(ERR_get_error())); } return buffer; -}; +} } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/cpp/random/HybridRandom.hpp b/packages/react-native-quick-crypto/cpp/random/HybridRandom.hpp index 5a19033fa..b19475496 100644 --- a/packages/react-native-quick-crypto/cpp/random/HybridRandom.hpp +++ b/packages/react-native-quick-crypto/cpp/random/HybridRandom.hpp @@ -1,32 +1,16 @@ +#pragma once + #include -#include -#include #include -#include "HybridRandomSpec.hpp" +#include namespace margelo::nitro::crypto { -using namespace facebook; - class HybridRandom : public HybridRandomSpec { public: - HybridRandom() : HybridObject(TAG) {} - - public: - // Methods - std::shared_ptr>> randomFill(const std::shared_ptr& buffer, double dOffset, - double dSize) override; - - std::shared_ptr randomFillSync(const std::shared_ptr& buffer, double dOffset, double dSize) override; + static Promise randomFill(const ArrayBuffer& buffer, double dOffset, double dSize); + static ArrayBuffer randomFillSync(const ArrayBuffer& buffer, double dOffset, double dSize); }; -inline void printData(std::string name, uint8_t* data, size_t size) { - std::cout << "data - " << name << std::endl; - for (size_t i = 0; i < size; i++) { - printf("%u ", data[i]); - } - printf("\n"); -} - } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/cpp/rsa/HybridRsaKeyPair.cpp b/packages/react-native-quick-crypto/cpp/rsa/HybridRsaKeyPair.cpp index 3c11f7e97..fef12f46d 100644 --- a/packages/react-native-quick-crypto/cpp/rsa/HybridRsaKeyPair.cpp +++ b/packages/react-native-quick-crypto/cpp/rsa/HybridRsaKeyPair.cpp @@ -15,8 +15,9 @@ namespace margelo::nitro::crypto { -std::shared_ptr> HybridRsaKeyPair::generateKeyPair() { - return Promise::async([this]() { this->generateKeyPairSync(); }); +Promise HybridRsaKeyPair::generateKeyPair() { + auto self = this->shared_cast(); + return Promise::async([self]() { self->generateKeyPairSync(); }); } void HybridRsaKeyPair::generateKeyPairSync() { @@ -73,10 +74,10 @@ void HybridRsaKeyPair::setModulusLength(double modulusLength) { this->modulusLength = static_cast(modulusLength); } -void HybridRsaKeyPair::setPublicExponent(const std::shared_ptr& publicExponent) { - if (publicExponent && publicExponent->size() > 0) { - const uint8_t* data = publicExponent->data(); - this->publicExponent.assign(data, data + publicExponent->size()); +void HybridRsaKeyPair::setPublicExponent(const ArrayBuffer& publicExponent) { + if (publicExponent.size() > 0) { + const uint8_t* data = publicExponent.data(); + this->publicExponent.assign(data, data + publicExponent.size()); } } @@ -84,7 +85,7 @@ void HybridRsaKeyPair::setHashAlgorithm(const std::string& hashAlgorithm) { this->hashAlgorithm = hashAlgorithm; } -std::shared_ptr HybridRsaKeyPair::getPublicKey() { +ArrayBuffer HybridRsaKeyPair::getPublicKey() { this->checkKeyPair(); // Export as DER format using direct OpenSSL calls @@ -108,7 +109,7 @@ std::shared_ptr HybridRsaKeyPair::getPublicKey() { return ToNativeArrayBuffer(derData); } -std::shared_ptr HybridRsaKeyPair::getPrivateKey() { +ArrayBuffer HybridRsaKeyPair::getPrivateKey() { this->checkKeyPair(); // Export as DER format in PKCS8 format using direct OpenSSL calls @@ -132,13 +133,12 @@ std::shared_ptr HybridRsaKeyPair::getPrivateKey() { return ToNativeArrayBuffer(derData); } -KeyObject HybridRsaKeyPair::importKey(const std::string& /* format */, const std::shared_ptr& /* keyData */, - const std::string& /* algorithm */, bool /* extractable */, - const std::vector& /* keyUsages */) { +KeyObject HybridRsaKeyPair::importKey(const std::string& /* format */, const ArrayBuffer& /* keyData */, const std::string& /* algorithm */, + bool /* extractable */, const std::vector& /* keyUsages */) { throw std::runtime_error("HybridRsaKeyPair::importKey() is not yet implemented"); } -std::shared_ptr HybridRsaKeyPair::exportKey(const KeyObject& /* key */, const std::string& /* format */) { +ArrayBuffer HybridRsaKeyPair::exportKey(const KeyObject& /* key */, const std::string& /* format */) { throw std::runtime_error("HybridRsaKeyPair::exportKey() is not yet implemented"); } diff --git a/packages/react-native-quick-crypto/cpp/rsa/HybridRsaKeyPair.hpp b/packages/react-native-quick-crypto/cpp/rsa/HybridRsaKeyPair.hpp index 2e96f6972..4ffdb22cb 100644 --- a/packages/react-native-quick-crypto/cpp/rsa/HybridRsaKeyPair.hpp +++ b/packages/react-native-quick-crypto/cpp/rsa/HybridRsaKeyPair.hpp @@ -1,8 +1,8 @@ #pragma once -#include "HybridRsaKeyPairSpec.hpp" #include #include +#include #include #include #include @@ -13,19 +13,19 @@ namespace margelo::nitro::crypto { class HybridRsaKeyPair : public HybridRsaKeyPairSpec { public: - HybridRsaKeyPair() : HybridObject(TAG), modulusLength(2048), hashAlgorithm("SHA-256") {} + HybridRsaKeyPair() : modulusLength(2048), hashAlgorithm("SHA-256") {} ~HybridRsaKeyPair() override = default; - std::shared_ptr> generateKeyPair() override; + Promise generateKeyPair() override; void generateKeyPairSync() override; void setModulusLength(double modulusLength) override; - void setPublicExponent(const std::shared_ptr& publicExponent) override; + void setPublicExponent(const ArrayBuffer& publicExponent) override; void setHashAlgorithm(const std::string& hashAlgorithm) override; - std::shared_ptr getPublicKey() override; - std::shared_ptr getPrivateKey() override; - KeyObject importKey(const std::string& format, const std::shared_ptr& keyData, const std::string& algorithm, - bool extractable, const std::vector& keyUsages) override; - std::shared_ptr exportKey(const KeyObject& key, const std::string& format) override; + ArrayBuffer getPublicKey() override; + ArrayBuffer getPrivateKey() override; + KeyObject importKey(const std::string& format, const ArrayBuffer& keyData, const std::string& algorithm, bool extractable, + const std::vector& keyUsages) override; + ArrayBuffer exportKey(const KeyObject& key, const std::string& format) override; private: using EVP_PKEY_ptr = std::unique_ptr; diff --git a/packages/react-native-quick-crypto/cpp/scrypt/HybridScrypt.cpp b/packages/react-native-quick-crypto/cpp/scrypt/HybridScrypt.cpp index ea9eff112..14612bd0d 100644 --- a/packages/react-native-quick-crypto/cpp/scrypt/HybridScrypt.cpp +++ b/packages/react-native-quick-crypto/cpp/scrypt/HybridScrypt.cpp @@ -10,21 +10,19 @@ namespace margelo::nitro::crypto { -std::shared_ptr>> HybridScrypt::deriveKey(const std::shared_ptr& password, - const std::shared_ptr& salt, double N, double r, - double p, double maxmem, double keylen) { +Promise HybridScrypt::deriveKey(const ArrayBuffer& password, const ArrayBuffer& salt, double N, double r, double p, + double maxmem, double keylen) { // get owned NativeArrayBuffers before passing to sync function auto nativePassword = ToNativeArrayBuffer(password); auto nativeSalt = ToNativeArrayBuffer(salt); - return Promise>::async([this, nativePassword, nativeSalt, N, r, p, maxmem, keylen]() { - return this->deriveKeySync(nativePassword, nativeSalt, N, r, p, maxmem, keylen); + return Promise::async([nativePassword, nativeSalt, N, r, p, maxmem, keylen]() { + return deriveKeySync(nativePassword, nativeSalt, N, r, p, maxmem, keylen); }); } -std::shared_ptr HybridScrypt::deriveKeySync(const std::shared_ptr& password, - const std::shared_ptr& salt, double N, double r, double p, - double maxmem, double keylen) { +ArrayBuffer HybridScrypt::deriveKeySync(const ArrayBuffer& password, const ArrayBuffer& salt, double N, double r, double p, double maxmem, + double keylen) { // Use EVP_PBE_scrypt to match Node.js implementation exactly // All parameters are uint64_t for this API (unlike EVP_KDF which uses uint32_t for r/p) uint64_t n_val = static_cast(N); @@ -38,12 +36,12 @@ std::shared_ptr HybridScrypt::deriveKeySync(const std::shared_ptrsize() > 0 ? reinterpret_cast(password->data()) : ""; - size_t pass_len = password ? password->size() : 0; + const char* pass_data = password.size() > 0 ? reinterpret_cast(password.data()) : ""; + size_t pass_len = password.size(); const unsigned char* salt_data = - salt && salt->size() > 0 ? reinterpret_cast(salt->data()) : reinterpret_cast(""); - size_t salt_len = salt ? salt->size() : 0; + salt.size() > 0 ? reinterpret_cast(salt.data()) : reinterpret_cast(""); + size_t salt_len = salt.size(); // Allocate output buffer auto out_buf = std::make_unique(outLen); @@ -57,8 +55,8 @@ std::shared_ptr HybridScrypt::deriveKeySync(const std::shared_ptr(out_buf.release(), outLen, [raw_ptr]() { delete[] raw_ptr; }); + uint8_t* raw_ptr = out_buf.release(); + return ArrayBuffer::wrap(raw_ptr, outLen, [raw_ptr]() { delete[] raw_ptr; }); } } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/cpp/scrypt/HybridScrypt.hpp b/packages/react-native-quick-crypto/cpp/scrypt/HybridScrypt.hpp index 038d11eba..d6fdbe6a9 100644 --- a/packages/react-native-quick-crypto/cpp/scrypt/HybridScrypt.hpp +++ b/packages/react-native-quick-crypto/cpp/scrypt/HybridScrypt.hpp @@ -6,7 +6,7 @@ #include #include -#include "HybridScryptSpec.hpp" +#include namespace margelo::nitro::crypto { @@ -14,15 +14,10 @@ using namespace facebook; class HybridScrypt : public HybridScryptSpec { public: - HybridScrypt() : HybridObject(TAG) {} - - public: - // Methods - std::shared_ptr deriveKeySync(const std::shared_ptr& password, const std::shared_ptr& salt, - double N, double r, double p, double maxmem, double keylen) override; - std::shared_ptr>> deriveKey(const std::shared_ptr& password, - const std::shared_ptr& salt, double N, double r, double p, - double maxmem, double keylen) override; + static ArrayBuffer deriveKeySync(const ArrayBuffer& password, const ArrayBuffer& salt, double N, double r, double p, double maxmem, + double keylen); + static Promise deriveKey(const ArrayBuffer& password, const ArrayBuffer& salt, double N, double r, double p, double maxmem, + double keylen); }; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/cpp/sign/HybridSignHandle.cpp b/packages/react-native-quick-crypto/cpp/sign/HybridSignHandle.cpp index 13d57c212..13b41c219 100644 --- a/packages/react-native-quick-crypto/cpp/sign/HybridSignHandle.cpp +++ b/packages/react-native-quick-crypto/cpp/sign/HybridSignHandle.cpp @@ -17,8 +17,6 @@ namespace margelo::nitro::crypto { -using margelo::nitro::NativeArrayBuffer; - HybridSignHandle::~HybridSignHandle() { if (md_ctx) { EVP_MD_CTX_free(md_ctx); @@ -53,18 +51,18 @@ void HybridSignHandle::init(const std::string& algorithm) { } } -void HybridSignHandle::update(const std::shared_ptr& data) { +void HybridSignHandle::update(const ArrayBuffer& data) { if (!md_ctx) { throw std::runtime_error("Sign not initialized"); } // Accumulate raw data for potential one-shot signing (Ed25519/Ed448/ML-DSA) - const uint8_t* ptr = reinterpret_cast(data->data()); - data_buffer.insert(data_buffer.end(), ptr, ptr + data->size()); + const uint8_t* ptr = dataOrEmpty(data); + data_buffer.insert(data_buffer.end(), ptr, ptr + data.size()); // Only update digest if we have one (not needed for pure signature schemes) if (md != nullptr) { - if (EVP_DigestUpdate(md_ctx, data->data(), data->size()) <= 0) { + if (EVP_DigestUpdate(md_ctx, dataOrEmpty(data), data.size()) <= 0) { unsigned long err = ERR_get_error(); char err_buf[256]; ERR_error_string_n(err, err_buf, sizeof(err_buf)); @@ -112,9 +110,8 @@ static bool isOneShotVariant(EVP_PKEY* pkey) { using EvpMdCtxPtr = std::unique_ptr; using EvpPkeyCtxPtr = std::unique_ptr; -std::shared_ptr HybridSignHandle::sign(const std::shared_ptr& keyHandle, - std::optional padding, std::optional saltLength, - std::optional dsaEncoding) { +ArrayBuffer HybridSignHandle::sign(const std::shared_ptr& keyHandle, const std::optional& padding, + const std::optional& saltLength, const std::optional& dsaEncoding) { if (!md_ctx) { throw std::runtime_error("Sign not initialized"); } @@ -229,13 +226,13 @@ std::shared_ptr HybridSignHandle::sign(const std::shared_ptr(p1363_buf.release(), 2 * n, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(p1363_buf.release(), 2 * n, [raw_ptr]() { delete[] raw_ptr; }); } } } uint8_t* raw_ptr = sig_buf.get(); - return std::make_shared(sig_buf.release(), sig_len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(sig_buf.release(), sig_len, [raw_ptr]() { delete[] raw_ptr; }); } } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/cpp/sign/HybridSignHandle.hpp b/packages/react-native-quick-crypto/cpp/sign/HybridSignHandle.hpp index e049d1301..644a84fa7 100644 --- a/packages/react-native-quick-crypto/cpp/sign/HybridSignHandle.hpp +++ b/packages/react-native-quick-crypto/cpp/sign/HybridSignHandle.hpp @@ -7,8 +7,8 @@ #include #include -#include "HybridKeyObjectHandleSpec.hpp" -#include "HybridSignHandleSpec.hpp" +#include +#include namespace margelo::nitro::crypto { @@ -16,14 +16,14 @@ using namespace facebook; class HybridSignHandle : public HybridSignHandleSpec { public: - HybridSignHandle() : HybridObject(TAG) {} + HybridSignHandle() = default; ~HybridSignHandle(); public: void init(const std::string& algorithm) override; - void update(const std::shared_ptr& data) override; - std::shared_ptr sign(const std::shared_ptr& keyHandle, std::optional padding, - std::optional saltLength, std::optional dsaEncoding) override; + void update(const ArrayBuffer& data) override; + ArrayBuffer sign(const std::shared_ptr& keyHandle, const std::optional& padding, + const std::optional& saltLength, const std::optional& dsaEncoding) override; private: EVP_MD_CTX* md_ctx = nullptr; diff --git a/packages/react-native-quick-crypto/cpp/sign/HybridVerifyHandle.cpp b/packages/react-native-quick-crypto/cpp/sign/HybridVerifyHandle.cpp index 18fce058e..1824240df 100644 --- a/packages/react-native-quick-crypto/cpp/sign/HybridVerifyHandle.cpp +++ b/packages/react-native-quick-crypto/cpp/sign/HybridVerifyHandle.cpp @@ -17,8 +17,6 @@ namespace margelo::nitro::crypto { -using margelo::nitro::NativeArrayBuffer; - HybridVerifyHandle::~HybridVerifyHandle() { if (md_ctx) { EVP_MD_CTX_free(md_ctx); @@ -53,18 +51,18 @@ void HybridVerifyHandle::init(const std::string& algorithm) { } } -void HybridVerifyHandle::update(const std::shared_ptr& data) { +void HybridVerifyHandle::update(const ArrayBuffer& data) { if (!md_ctx) { throw std::runtime_error("Verify not initialized"); } // Accumulate raw data for potential one-shot verification (Ed25519/Ed448/ML-DSA) - const uint8_t* ptr = reinterpret_cast(data->data()); - data_buffer.insert(data_buffer.end(), ptr, ptr + data->size()); + const uint8_t* ptr = dataOrEmpty(data); + data_buffer.insert(data_buffer.end(), ptr, ptr + data.size()); // Only update digest if we have one (not needed for pure signature schemes) if (md != nullptr) { - if (EVP_DigestUpdate(md_ctx, data->data(), data->size()) <= 0) { + if (EVP_DigestUpdate(md_ctx, dataOrEmpty(data), data.size()) <= 0) { unsigned long err = ERR_get_error(); char err_buf[256]; ERR_error_string_n(err, err_buf, sizeof(err_buf)); @@ -112,8 +110,9 @@ static bool isOneShotVariant(EVP_PKEY* pkey) { using EvpMdCtxPtr = std::unique_ptr; using EvpPkeyCtxPtr = std::unique_ptr; -bool HybridVerifyHandle::verify(const std::shared_ptr& keyHandle, const std::shared_ptr& signature, - std::optional padding, std::optional saltLength, std::optional dsaEncoding) { +bool HybridVerifyHandle::verify(const std::shared_ptr& keyHandle, const ArrayBuffer& signature, + const std::optional& padding, const std::optional& saltLength, + const std::optional& dsaEncoding) { if (!md_ctx) { throw std::runtime_error("Verify not initialized"); } @@ -125,8 +124,8 @@ bool HybridVerifyHandle::verify(const std::shared_ptr throw std::runtime_error("Invalid public key for verification"); } - const unsigned char* sig_data = signature->data(); - size_t sig_len = signature->size(); + const unsigned char* sig_data = dataOrEmpty(signature); + size_t sig_len = signature.size(); // Ed25519/Ed448/ML-DSA require one-shot verification with EVP_DigestVerify // Also use one-shot path if no digest was specified (md == nullptr) diff --git a/packages/react-native-quick-crypto/cpp/sign/HybridVerifyHandle.hpp b/packages/react-native-quick-crypto/cpp/sign/HybridVerifyHandle.hpp index 368783138..38ce26925 100644 --- a/packages/react-native-quick-crypto/cpp/sign/HybridVerifyHandle.hpp +++ b/packages/react-native-quick-crypto/cpp/sign/HybridVerifyHandle.hpp @@ -7,8 +7,8 @@ #include #include -#include "HybridKeyObjectHandleSpec.hpp" -#include "HybridVerifyHandleSpec.hpp" +#include +#include namespace margelo::nitro::crypto { @@ -16,14 +16,15 @@ using namespace facebook; class HybridVerifyHandle : public HybridVerifyHandleSpec { public: - HybridVerifyHandle() : HybridObject(TAG) {} + HybridVerifyHandle() = default; ~HybridVerifyHandle(); public: void init(const std::string& algorithm) override; - void update(const std::shared_ptr& data) override; - bool verify(const std::shared_ptr& keyHandle, const std::shared_ptr& signature, - std::optional padding, std::optional saltLength, std::optional dsaEncoding) override; + void update(const ArrayBuffer& data) override; + bool verify(const std::shared_ptr& keyHandle, const ArrayBuffer& signature, + const std::optional& padding, const std::optional& saltLength, + const std::optional& dsaEncoding) override; private: EVP_MD_CTX* md_ctx = nullptr; diff --git a/packages/react-native-quick-crypto/cpp/slhdsa/HybridSlhDsaKeyPair.cpp b/packages/react-native-quick-crypto/cpp/slhdsa/HybridSlhDsaKeyPair.cpp index 1298025d9..50ed9a1ba 100644 --- a/packages/react-native-quick-crypto/cpp/slhdsa/HybridSlhDsaKeyPair.cpp +++ b/packages/react-native-quick-crypto/cpp/slhdsa/HybridSlhDsaKeyPair.cpp @@ -39,8 +39,7 @@ void HybridSlhDsaKeyPair::setVariant(const std::string& variant) { #endif } -std::shared_ptr> HybridSlhDsaKeyPair::generateKeyPair(double publicFormat, double publicType, double privateFormat, - double privateType) { +Promise HybridSlhDsaKeyPair::generateKeyPair(double publicFormat, double publicType, double privateFormat, double privateType) { auto self = this->shared_cast(); return Promise::async([self, publicFormat, publicType, privateFormat, privateType]() { self->generateKeyPairSync(publicFormat, publicType, privateFormat, privateType); @@ -81,7 +80,7 @@ void HybridSlhDsaKeyPair::generateKeyPairSync(double publicFormat, double public #endif } -std::shared_ptr HybridSlhDsaKeyPair::getPublicKey() { +ArrayBuffer HybridSlhDsaKeyPair::getPublicKey() { #if !RNQC_HAS_SLH_DSA throw std::runtime_error("SLH-DSA requires OpenSSL 3.5+"); #else @@ -114,11 +113,11 @@ std::shared_ptr HybridSlhDsaKeyPair::getPublicKey() { BIO_free(bio); uint8_t* raw_ptr = buf.get(); - return std::make_shared(buf.release(), len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(buf.release(), len, [raw_ptr]() { delete[] raw_ptr; }); #endif } -std::shared_ptr HybridSlhDsaKeyPair::getPrivateKey() { +ArrayBuffer HybridSlhDsaKeyPair::getPrivateKey() { #if !RNQC_HAS_SLH_DSA throw std::runtime_error("SLH-DSA requires OpenSSL 3.5+"); #else @@ -152,17 +151,17 @@ std::shared_ptr HybridSlhDsaKeyPair::getPrivateKey() { BIO_free(bio); uint8_t* raw_ptr = buf.get(); - return std::make_shared(buf.release(), len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(buf.release(), len, [raw_ptr]() { delete[] raw_ptr; }); #endif } -std::shared_ptr>> HybridSlhDsaKeyPair::sign(const std::shared_ptr& message) { +Promise HybridSlhDsaKeyPair::sign(const ArrayBuffer& message) { auto nativeMessage = ToNativeArrayBuffer(message); auto self = this->shared_cast(); - return Promise>::async([self, nativeMessage]() { return self->signSync(nativeMessage); }); + return Promise::async([self, nativeMessage]() { return self->signSync(nativeMessage); }); } -std::shared_ptr HybridSlhDsaKeyPair::signSync(const std::shared_ptr& message) { +ArrayBuffer HybridSlhDsaKeyPair::signSync(const ArrayBuffer& message) { #if !RNQC_HAS_SLH_DSA throw std::runtime_error("SLH-DSA requires OpenSSL 3.5+"); #else @@ -179,30 +178,29 @@ std::shared_ptr HybridSlhDsaKeyPair::signSync(const std::shared_ptr } size_t sig_len = 0; - if (EVP_DigestSign(md_ctx.get(), nullptr, &sig_len, message->data(), message->size()) <= 0) { + if (EVP_DigestSign(md_ctx.get(), nullptr, &sig_len, dataOrEmpty(message), message.size()) <= 0) { throw std::runtime_error("Failed to calculate signature size: " + getOpenSSLError()); } auto sig = std::make_unique(sig_len); - if (EVP_DigestSign(md_ctx.get(), sig.get(), &sig_len, message->data(), message->size()) <= 0) { + if (EVP_DigestSign(md_ctx.get(), sig.get(), &sig_len, dataOrEmpty(message), message.size()) <= 0) { throw std::runtime_error("Failed to sign message: " + getOpenSSLError()); } uint8_t* raw_ptr = sig.get(); - return std::make_shared(sig.release(), sig_len, [raw_ptr]() { delete[] raw_ptr; }); + return ArrayBuffer::wrap(sig.release(), sig_len, [raw_ptr]() { delete[] raw_ptr; }); #endif } -std::shared_ptr> HybridSlhDsaKeyPair::verify(const std::shared_ptr& signature, - const std::shared_ptr& message) { +Promise HybridSlhDsaKeyPair::verify(const ArrayBuffer& signature, const ArrayBuffer& message) { auto nativeSignature = ToNativeArrayBuffer(signature); auto nativeMessage = ToNativeArrayBuffer(message); auto self = this->shared_cast(); return Promise::async([self, nativeSignature, nativeMessage]() { return self->verifySync(nativeSignature, nativeMessage); }); } -bool HybridSlhDsaKeyPair::verifySync(const std::shared_ptr& signature, const std::shared_ptr& message) { +bool HybridSlhDsaKeyPair::verifySync(const ArrayBuffer& signature, const ArrayBuffer& message) { #if !RNQC_HAS_SLH_DSA throw std::runtime_error("SLH-DSA requires OpenSSL 3.5+"); #else @@ -218,7 +216,7 @@ bool HybridSlhDsaKeyPair::verifySync(const std::shared_ptr& signatu throw std::runtime_error("Failed to initialize verification: " + getOpenSSLError()); } - int result = EVP_DigestVerify(md_ctx.get(), signature->data(), signature->size(), message->data(), message->size()); + int result = EVP_DigestVerify(md_ctx.get(), dataOrEmpty(signature), signature.size(), dataOrEmpty(message), message.size()); if (result < 0) { throw std::runtime_error("Verification error: " + getOpenSSLError()); diff --git a/packages/react-native-quick-crypto/cpp/slhdsa/HybridSlhDsaKeyPair.hpp b/packages/react-native-quick-crypto/cpp/slhdsa/HybridSlhDsaKeyPair.hpp index 66423835f..8cd7964d3 100644 --- a/packages/react-native-quick-crypto/cpp/slhdsa/HybridSlhDsaKeyPair.hpp +++ b/packages/react-native-quick-crypto/cpp/slhdsa/HybridSlhDsaKeyPair.hpp @@ -4,30 +4,29 @@ #include #include -#include "HybridSlhDsaKeyPairSpec.hpp" +#include namespace margelo::nitro::crypto { class HybridSlhDsaKeyPair : public HybridSlhDsaKeyPairSpec { public: - HybridSlhDsaKeyPair() : HybridObject(TAG) {} + HybridSlhDsaKeyPair() = default; ~HybridSlhDsaKeyPair() override = default; - std::shared_ptr> generateKeyPair(double publicFormat, double publicType, double privateFormat, double privateType) override; + Promise generateKeyPair(double publicFormat, double publicType, double privateFormat, double privateType) override; void generateKeyPairSync(double publicFormat, double publicType, double privateFormat, double privateType) override; - std::shared_ptr getPublicKey() override; - std::shared_ptr getPrivateKey() override; + ArrayBuffer getPublicKey() override; + ArrayBuffer getPrivateKey() override; - std::shared_ptr>> sign(const std::shared_ptr& message) override; + Promise sign(const ArrayBuffer& message) override; - std::shared_ptr signSync(const std::shared_ptr& message) override; + ArrayBuffer signSync(const ArrayBuffer& message) override; - std::shared_ptr> verify(const std::shared_ptr& signature, - const std::shared_ptr& message) override; + Promise verify(const ArrayBuffer& signature, const ArrayBuffer& message) override; - bool verifySync(const std::shared_ptr& signature, const std::shared_ptr& message) override; + bool verifySync(const ArrayBuffer& signature, const ArrayBuffer& message) override; void setVariant(const std::string& variant) override; diff --git a/packages/react-native-quick-crypto/cpp/turboshake/HybridTurboShake.cpp b/packages/react-native-quick-crypto/cpp/turboshake/HybridTurboShake.cpp index 2e7aa754c..2b71b9485 100644 --- a/packages/react-native-quick-crypto/cpp/turboshake/HybridTurboShake.cpp +++ b/packages/react-native-quick-crypto/cpp/turboshake/HybridTurboShake.cpp @@ -310,9 +310,8 @@ namespace { } // namespace -std::shared_ptr>> HybridTurboShake::turboShake(TurboShakeVariant variant, double domainSeparation, - double outputLength, - const std::shared_ptr& data) { +Promise HybridTurboShake::turboShake(TurboShakeVariant variant, double domainSeparation, double outputLength, + const ArrayBuffer& data) { uint8_t ds = parseDomainSeparation(domainSeparation); uint32_t outLen = parseOutputLength(outputLength); @@ -320,60 +319,58 @@ std::shared_ptr>> HybridTurboShake::turboSh auto nativeData = ToNativeArrayBuffer(data); - return Promise>::async([is128, ds, outLen, nativeData]() -> std::shared_ptr { + return Promise::async([is128, ds, outLen, nativeData]() -> ArrayBuffer { auto outBuf = std::make_unique(outLen); - const uint8_t* in = reinterpret_cast(nativeData->data()); - size_t inLen = nativeData->size(); + const uint8_t* in = dataOrEmpty(nativeData); + size_t inLen = nativeData.size(); if (is128) { TurboSHAKE128(in, inLen, ds, outBuf.get(), outLen); } else { TurboSHAKE256(in, inLen, ds, outBuf.get(), outLen); } - uint8_t* raw = outBuf.get(); - return std::make_shared(outBuf.release(), outLen, [raw]() { delete[] raw; }); + uint8_t* raw = outBuf.release(); + return ArrayBuffer::wrap(raw, outLen, [raw]() { delete[] raw; }); }); } -std::shared_ptr>> -HybridTurboShake::kangarooTwelve(KangarooTwelveVariant variant, double outputLength, const std::shared_ptr& data, - const std::optional>& customization) { +Promise HybridTurboShake::kangarooTwelve(KangarooTwelveVariant variant, double outputLength, const ArrayBuffer& data, + const std::optional& customization) { uint32_t outLen = parseOutputLength(outputLength); bool is128 = variant == KangarooTwelveVariant::KT128; auto nativeData = ToNativeArrayBuffer(data); - std::optional> nativeCustom; + std::optional nativeCustom; if (customization.has_value()) { nativeCustom = ToNativeArrayBuffer(customization.value()); } - return Promise>::async( - [is128, outLen, nativeData, nativeCustom = std::move(nativeCustom)]() -> std::shared_ptr { - const uint8_t* in = reinterpret_cast(nativeData->data()); - size_t inLen = nativeData->size(); - const uint8_t* custom = nullptr; - size_t customLen = 0; - if (nativeCustom.has_value() && nativeCustom.value()->size() > 0) { - custom = reinterpret_cast(nativeCustom.value()->data()); - customLen = nativeCustom.value()->size(); - } + return Promise::async([is128, outLen, nativeData, nativeCustom = std::move(nativeCustom)]() -> ArrayBuffer { + const uint8_t* in = dataOrEmpty(nativeData); + size_t inLen = nativeData.size(); + const uint8_t* custom = nullptr; + size_t customLen = 0; + if (nativeCustom.has_value() && nativeCustom.value().size() > 0) { + custom = reinterpret_cast(nativeCustom.value().data()); + customLen = nativeCustom.value().size(); + } - // Mirror Node's overflow guard for s_len = msg + custom + length_encode(|custom|). - // length_encode produces at most sizeof(size_t) + 1 bytes. - constexpr size_t kMaxLengthEncodeSize = sizeof(size_t) + 1; - if (inLen > SIZE_MAX - customLen || inLen + customLen > SIZE_MAX - kMaxLengthEncodeSize) { - throw std::runtime_error("KangarooTwelve input length overflow"); - } + // Mirror Node's overflow guard for s_len = msg + custom + length_encode(|custom|). + // length_encode produces at most sizeof(size_t) + 1 bytes. + constexpr size_t kMaxLengthEncodeSize = sizeof(size_t) + 1; + if (inLen > SIZE_MAX - customLen || inLen + customLen > SIZE_MAX - kMaxLengthEncodeSize) { + throw std::runtime_error("KangarooTwelve input length overflow"); + } - auto outBuf = std::make_unique(outLen); - if (is128) { - KT128(in, inLen, custom, customLen, outBuf.get(), outLen); - } else { - KT256(in, inLen, custom, customLen, outBuf.get(), outLen); - } - uint8_t* raw = outBuf.get(); - return std::make_shared(outBuf.release(), outLen, [raw]() { delete[] raw; }); - }); + auto outBuf = std::make_unique(outLen); + if (is128) { + KT128(in, inLen, custom, customLen, outBuf.get(), outLen); + } else { + KT256(in, inLen, custom, customLen, outBuf.get(), outLen); + } + uint8_t* raw = outBuf.release(); + return ArrayBuffer::wrap(raw, outLen, [raw]() { delete[] raw; }); + }); } } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/cpp/turboshake/HybridTurboShake.hpp b/packages/react-native-quick-crypto/cpp/turboshake/HybridTurboShake.hpp index 48aa5e69b..d320a3a1b 100644 --- a/packages/react-native-quick-crypto/cpp/turboshake/HybridTurboShake.hpp +++ b/packages/react-native-quick-crypto/cpp/turboshake/HybridTurboShake.hpp @@ -6,7 +6,7 @@ #include #include -#include "HybridTurboShakeSpec.hpp" +#include namespace margelo::nitro::crypto { @@ -14,15 +14,10 @@ using namespace facebook; class HybridTurboShake : public HybridTurboShakeSpec { public: - HybridTurboShake() : HybridObject(TAG) {} + static Promise turboShake(TurboShakeVariant variant, double domainSeparation, double outputLength, const ArrayBuffer& data); - public: - std::shared_ptr>> turboShake(TurboShakeVariant variant, double domainSeparation, double outputLength, - const std::shared_ptr& data) override; - - std::shared_ptr>> - kangarooTwelve(KangarooTwelveVariant variant, double outputLength, const std::shared_ptr& data, - const std::optional>& customization) override; + static Promise kangarooTwelve(KangarooTwelveVariant variant, double outputLength, const ArrayBuffer& data, + const std::optional& customization); }; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/cpp/utils/HybridUtils.cpp b/packages/react-native-quick-crypto/cpp/utils/HybridUtils.cpp index f1ee55df4..99455e0ea 100644 --- a/packages/react-native-quick-crypto/cpp/utils/HybridUtils.cpp +++ b/packages/react-native-quick-crypto/cpp/utils/HybridUtils.cpp @@ -261,15 +261,15 @@ namespace { } // anonymous namespace -bool HybridUtils::timingSafeEqual(const std::shared_ptr& a, const std::shared_ptr& b) { - size_t aLen = a->size(); - size_t bLen = b->size(); +bool HybridUtils::timingSafeEqual(const ArrayBuffer& a, const ArrayBuffer& b) { + size_t aLen = a.size(); + size_t bLen = b.size(); if (aLen != bLen) { throw std::runtime_error("Input buffers must have the same byte length"); } - return CRYPTO_memcmp(a->data(), b->data(), aLen) == 0; + return CRYPTO_memcmp(a.data(), b.data(), aLen) == 0; } bool HybridUtils::isHermesRuntime(facebook::jsi::Runtime& runtime) { @@ -293,9 +293,9 @@ facebook::jsi::Value HybridUtils::bufferToJsiString(facebook::jsi::Runtime& runt try { // bufferToString(buffer: ArrayBuffer, encoding: string, start: number, end: number): string; // Defined in utils/conversion.ts - auto buffer = JSIConverter>::fromJSI(runtime, args[0]); + auto buffer = JSIConverter::fromJSI(runtime, args[0]); std::string encoding = JSIConverter::fromJSI(runtime, args[1]); - const size_t bufferSize = buffer->size(); + const size_t bufferSize = buffer.size(); // `start` and `end` are normalized in the TS code // so it's safe to use `static_cast` here const size_t start = static_cast(JSIConverter::fromJSI(runtime, args[2])); @@ -308,7 +308,7 @@ facebook::jsi::Value HybridUtils::bufferToJsiString(facebook::jsi::Runtime& runt const size_t offset = start; const size_t length = end - start; - const auto* data = reinterpret_cast(buffer->data() + offset); + const auto* data = reinterpret_cast(buffer.data() + offset); if (encoding == "hex") { return facebook::jsi::String::createFromAscii(runtime, encodeHex(data, length)); @@ -360,24 +360,23 @@ facebook::jsi::Value HybridUtils::jsiStringToBuffer(facebook::jsi::Runtime& runt if (encoding == "hex") { auto decoded = decodeHex(str.utf8(runtime)); - return JSIConverter>::toJSI(runtime, ArrayBuffer::move(std::move(decoded))); + return JSIConverter::toJSI(runtime, ArrayBuffer::move(std::move(decoded))); } if (encoding == "base64" || encoding == "base64url") { auto decoded = decodeBase64(str.utf8(runtime)); - return JSIConverter>::toJSI(runtime, ArrayBuffer::move(std::move(decoded))); + return JSIConverter::toJSI(runtime, ArrayBuffer::move(std::move(decoded))); } if (encoding == "utf8" || encoding == "utf-8") { auto utf8Str = str.utf8(runtime); - return JSIConverter>::toJSI( - runtime, ArrayBuffer::copy(reinterpret_cast(utf8Str.data()), utf8Str.size())); + return JSIConverter::toJSI(runtime, ArrayBuffer::copy(reinterpret_cast(utf8Str.data()), utf8Str.size())); } if (encoding == "latin1" || encoding == "binary" || encoding == "ascii") { auto decoded = decodeLatin1(runtime, isHermesRuntime(runtime), str); - return JSIConverter>::toJSI(runtime, ArrayBuffer::move(std::move(decoded))); + return JSIConverter::toJSI(runtime, ArrayBuffer::move(std::move(decoded))); } if (encoding == "utf16le") { auto decoded = decodeUtf16Le(runtime, str); - return JSIConverter>::toJSI(runtime, ArrayBuffer::move(std::move(decoded))); + return JSIConverter::toJSI(runtime, ArrayBuffer::move(std::move(decoded))); } throw std::runtime_error("Unsupported encoding: " + encoding); } catch (const std::exception& exception) { @@ -388,12 +387,12 @@ facebook::jsi::Value HybridUtils::jsiStringToBuffer(facebook::jsi::Runtime& runt } } -void HybridUtils::loadHybridMethods() { - HybridUtilsSpec::loadHybridMethods(); - registerHybrids(this, [](Prototype& prototype) { - prototype.registerRawHybridMethod("bufferToString", 4, &HybridUtils::bufferToJsiString); - prototype.registerRawHybridMethod("stringToBuffer", 2, &HybridUtils::jsiStringToBuffer); +const std::shared_ptr& HybridUtils::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerRawHybridMethod("bufferToString", 4, &HybridUtils::bufferToJsiString); + clazz.registerRawHybridMethod("stringToBuffer", 2, &HybridUtils::jsiStringToBuffer); }); + return hybridClass; } } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/cpp/utils/HybridUtils.hpp b/packages/react-native-quick-crypto/cpp/utils/HybridUtils.hpp index 4859ecbce..c2ef4acb7 100644 --- a/packages/react-native-quick-crypto/cpp/utils/HybridUtils.hpp +++ b/packages/react-native-quick-crypto/cpp/utils/HybridUtils.hpp @@ -1,18 +1,23 @@ #pragma once -#include "HybridUtilsSpec.hpp" +#include namespace margelo::nitro::crypto { class HybridUtils : public HybridUtilsSpec { public: - HybridUtils() : HybridObject(TAG) {} + struct Class { + using Base = HybridUtilsSpec::Class; + static constexpr const char* name = "Utils"; + static const std::shared_ptr& get(); + }; - public: - bool timingSafeEqual(const std::shared_ptr& a, const std::shared_ptr& b) override; + static bool timingSafeEqual(const ArrayBuffer& a, const ArrayBuffer& b); protected: - void loadHybridMethods() override; + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } private: facebook::jsi::Runtime* cachedRuntime_ = nullptr; diff --git a/packages/react-native-quick-crypto/cpp/utils/QuickCryptoUtils.hpp b/packages/react-native-quick-crypto/cpp/utils/QuickCryptoUtils.hpp index 1adc15ebe..b1846437c 100644 --- a/packages/react-native-quick-crypto/cpp/utils/QuickCryptoUtils.hpp +++ b/packages/react-native-quick-crypto/cpp/utils/QuickCryptoUtils.hpp @@ -37,32 +37,27 @@ inline void clearOpenSSLErrors() { ERR_clear_error(); } -// copy a JSArrayBuffer that we do not own into a NativeArrayBuffer that we do own -inline std::shared_ptr ToNativeArrayBuffer(const std::shared_ptr& buffer) { - size_t bufferSize = buffer.get()->size(); - uint8_t* data = new uint8_t[bufferSize]; - memcpy(data, buffer.get()->data(), bufferSize); - return std::make_shared(data, bufferSize, [=]() { delete[] data; }); +// copy a buffer we may not own (e.g. a JS-backed ArrayBuffer) into one we do own +inline margelo::nitro::ArrayBuffer ToNativeArrayBuffer(const margelo::nitro::ArrayBuffer& buffer) { + return margelo::nitro::ArrayBuffer::copy(buffer); } -inline std::shared_ptr ToNativeArrayBuffer(std::string str) { - size_t size = str.size(); - uint8_t* data = new uint8_t[size]; - memcpy(data, str.data(), size); - return std::make_shared(data, size, [=]() { delete[] data; }); +inline margelo::nitro::ArrayBuffer ToNativeArrayBuffer(const std::string& str) { + return margelo::nitro::ArrayBuffer::copy(reinterpret_cast(str.data()), str.size()); } -inline std::shared_ptr ToNativeArrayBuffer(const std::vector& vec) { - size_t size = vec.size(); - uint8_t* data = new uint8_t[size]; - memcpy(data, vec.data(), size); - return std::make_shared(data, size, [=]() { delete[] data; }); +inline margelo::nitro::ArrayBuffer ToNativeArrayBuffer(const std::vector& vec) { + return margelo::nitro::ArrayBuffer::copy(vec); } -inline std::shared_ptr ToNativeArrayBuffer(const uint8_t* ptr, size_t size) { - uint8_t* data = new uint8_t[size]; - memcpy(data, ptr, size); - return std::make_shared(data, size, [=]() { delete[] data; }); +inline margelo::nitro::ArrayBuffer ToNativeArrayBuffer(const uint8_t* ptr, size_t size) { + return margelo::nitro::ArrayBuffer::copy(ptr, size); +} + +// ArrayBuffer::data() is nullptr for empty buffers, which some OpenSSL and libc entry points reject even for length 0 +inline const uint8_t* dataOrEmpty(const margelo::nitro::ArrayBuffer& buffer) { + static const uint8_t kEmpty = 0; + return buffer.data() != nullptr ? buffer.data() : &kEmpty; } inline bool CheckIsUint32(double value) { diff --git a/packages/react-native-quick-crypto/cpp/x509/HybridX509Certificate.cpp b/packages/react-native-quick-crypto/cpp/x509/HybridX509Certificate.cpp index 0503cf3d7..c95a2f392 100644 --- a/packages/react-native-quick-crypto/cpp/x509/HybridX509Certificate.cpp +++ b/packages/react-native-quick-crypto/cpp/x509/HybridX509Certificate.cpp @@ -15,8 +15,8 @@ std::string HybridX509Certificate::bioToString(ncrypto::BIOPointer bio) const { return std::string(mem->data, mem->length); } -void HybridX509Certificate::init(const std::shared_ptr& buffer) { - ncrypto::Buffer buf{.data = reinterpret_cast(buffer->data()), .len = buffer->size()}; +void HybridX509Certificate::init(const ArrayBuffer& buffer) { + ncrypto::Buffer buf{.data = dataOrEmpty(buffer), .len = buffer.size()}; auto result = ncrypto::X509Pointer::Parse(buf); if (!result) { throw std::runtime_error("Failed to parse X509 certificate"); @@ -86,7 +86,7 @@ std::string HybridX509Certificate::fingerprint512() { return cert_.view().getFingerprint(ncrypto::Digest::SHA512).value_or(""); } -std::shared_ptr HybridX509Certificate::raw() { +ArrayBuffer HybridX509Certificate::raw() { auto bio = cert_.view().toDER(); if (!bio) { throw std::runtime_error("Failed to export certificate as DER"); diff --git a/packages/react-native-quick-crypto/cpp/x509/HybridX509Certificate.hpp b/packages/react-native-quick-crypto/cpp/x509/HybridX509Certificate.hpp index 705feb3e7..852007feb 100644 --- a/packages/react-native-quick-crypto/cpp/x509/HybridX509Certificate.hpp +++ b/packages/react-native-quick-crypto/cpp/x509/HybridX509Certificate.hpp @@ -1,6 +1,6 @@ #pragma once -#include "HybridX509CertificateHandleSpec.hpp" +#include #include #include @@ -8,9 +8,9 @@ namespace margelo::nitro::crypto { class HybridX509Certificate : public HybridX509CertificateHandleSpec { public: - HybridX509Certificate() : HybridObject(TAG) {} + HybridX509Certificate() = default; - void init(const std::shared_ptr& buffer) override; + void init(const ArrayBuffer& buffer) override; std::string subject() override; std::string subjectAltName() override; @@ -28,7 +28,7 @@ class HybridX509Certificate : public HybridX509CertificateHandleSpec { std::string fingerprint256() override; std::string fingerprint512() override; - std::shared_ptr raw() override; + ArrayBuffer raw() override; std::string pem() override; std::shared_ptr publicKey() override; diff --git a/packages/react-native-quick-crypto/nitro.json b/packages/react-native-quick-crypto/nitro.json index 3d04ea7de..48ca94081 100644 --- a/packages/react-native-quick-crypto/nitro.json +++ b/packages/react-native-quick-crypto/nitro.json @@ -1,103 +1,7 @@ { + "environment": "bare", "cxxNamespace": ["crypto"], - "ios": { - "iosModuleName": "QuickCrypto" - }, - "android": { - "androidNamespace": ["crypto"], - "androidCxxLibName": "QuickCrypto" - }, - "autolinking": { - "Argon2": { - "cpp": "HybridArgon2" - }, - "Blake3": { - "cpp": "HybridBlake3" - }, - "Certificate": { - "cpp": "HybridCertificate" - }, - "Cipher": { - "cpp": "HybridCipher" - }, - "CipherFactory": { - "cpp": "HybridCipherFactory" - }, - "DhKeyPair": { - "cpp": "HybridDhKeyPair" - }, - "DiffieHellman": { - "cpp": "HybridDiffieHellman" - }, - "DsaKeyPair": { - "cpp": "HybridDsaKeyPair" - }, - "ECDH": { - "cpp": "HybridECDH" - }, - "EcKeyPair": { - "cpp": "HybridEcKeyPair" - }, - "EdKeyPair": { - "cpp": "HybridEdKeyPair" - }, - "Hash": { - "cpp": "HybridHash" - }, - "Hkdf": { - "cpp": "HybridHkdf" - }, - "Hmac": { - "cpp": "HybridHmac" - }, - "Kmac": { - "cpp": "HybridKmac" - }, - "KeyObjectHandle": { - "cpp": "HybridKeyObjectHandle" - }, - "MlDsaKeyPair": { - "cpp": "HybridMlDsaKeyPair" - }, - "MlKemKeyPair": { - "cpp": "HybridMlKemKeyPair" - }, - "SlhDsaKeyPair": { - "cpp": "HybridSlhDsaKeyPair" - }, - "Pbkdf2": { - "cpp": "HybridPbkdf2" - }, - "Prime": { - "cpp": "HybridPrime" - }, - "Random": { - "cpp": "HybridRandom" - }, - "RsaCipher": { - "cpp": "HybridRsaCipher" - }, - "RsaKeyPair": { - "cpp": "HybridRsaKeyPair" - }, - "Scrypt": { - "cpp": "HybridScrypt" - }, - "SignHandle": { - "cpp": "HybridSignHandle" - }, - "TurboShake": { - "cpp": "HybridTurboShake" - }, - "Utils": { - "cpp": "HybridUtils" - }, - "VerifyHandle": { - "cpp": "HybridVerifyHandle" - }, - "X509CertificateHandle": { - "cpp": "HybridX509Certificate" - } - }, + "apple": { "moduleName": "QuickCrypto" }, + "android": { "namespace": ["crypto"], "cxxLibName": "QuickCrypto" }, "ignorePaths": ["node_modules", "lib"] } diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/QuickCrypto+autolinking.cmake b/packages/react-native-quick-crypto/nitrogen/generated/android/QuickCrypto+autolinking.cmake index 6a9cb11a2..d01a6207a 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/android/QuickCrypto+autolinking.cmake +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/QuickCrypto+autolinking.cmake @@ -1,110 +1,90 @@ # # QuickCrypto+autolinking.cmake # This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -# https://github.com/mrousavy/nitro +# https://github.com/margelo/nitro # Copyright © Marc Rousavy @ Margelo # -# This is a CMake file that adds all files generated by Nitrogen -# to the current CMake project. -# -# To use it, add this to your CMakeLists.txt: -# ```cmake -# include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/QuickCrypto+autolinking.cmake) -# ``` - -# Define a flag to check if we are building properly -add_definitions(-DBUILDING_QUICKCRYPTO_WITH_GENERATED_CMAKE_PROJECT) - -# Enable Raw Props parsing in react-native (for Nitro Views) -add_definitions(-DRN_SERIALIZABLE_STATE) - -# Add all headers that were generated by Nitrogen -include_directories( - "../nitrogen/generated/shared/c++" - "../nitrogen/generated/android/c++" - "../nitrogen/generated/android/" +target_compile_features(QuickCrypto PUBLIC cxx_std_20) +target_include_directories(QuickCrypto PRIVATE + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/include" + "${CMAKE_CURRENT_LIST_DIR}/c++/include" + "${CMAKE_CURRENT_LIST_DIR}/include" ) - -# Add all .cpp sources that were generated by Nitrogen -target_sources( - # CMake project name (Android C++ library name) - QuickCrypto PRIVATE - # Autolinking Setup - ../nitrogen/generated/android/QuickCryptoOnLoad.cpp - # Shared Nitrogen C++ sources - ../nitrogen/generated/shared/c++/HybridArgon2Spec.cpp - ../nitrogen/generated/shared/c++/HybridBlake3Spec.cpp - ../nitrogen/generated/shared/c++/HybridCertificateSpec.cpp - ../nitrogen/generated/shared/c++/HybridCipherSpec.cpp - ../nitrogen/generated/shared/c++/HybridCipherFactorySpec.cpp - ../nitrogen/generated/shared/c++/HybridDhKeyPairSpec.cpp - ../nitrogen/generated/shared/c++/HybridDiffieHellmanSpec.cpp - ../nitrogen/generated/shared/c++/HybridDsaKeyPairSpec.cpp - ../nitrogen/generated/shared/c++/HybridECDHSpec.cpp - ../nitrogen/generated/shared/c++/HybridEcKeyPairSpec.cpp - ../nitrogen/generated/shared/c++/HybridEdKeyPairSpec.cpp - ../nitrogen/generated/shared/c++/HybridHashSpec.cpp - ../nitrogen/generated/shared/c++/HybridHkdfSpec.cpp - ../nitrogen/generated/shared/c++/HybridHmacSpec.cpp - ../nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.cpp - ../nitrogen/generated/shared/c++/HybridKmacSpec.cpp - ../nitrogen/generated/shared/c++/HybridMlDsaKeyPairSpec.cpp - ../nitrogen/generated/shared/c++/HybridMlKemKeyPairSpec.cpp - ../nitrogen/generated/shared/c++/HybridPbkdf2Spec.cpp - ../nitrogen/generated/shared/c++/HybridPrimeSpec.cpp - ../nitrogen/generated/shared/c++/HybridRandomSpec.cpp - ../nitrogen/generated/shared/c++/HybridRsaCipherSpec.cpp - ../nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.cpp - ../nitrogen/generated/shared/c++/HybridScryptSpec.cpp - ../nitrogen/generated/shared/c++/HybridSignHandleSpec.cpp - ../nitrogen/generated/shared/c++/HybridVerifyHandleSpec.cpp - ../nitrogen/generated/shared/c++/HybridSlhDsaKeyPairSpec.cpp - ../nitrogen/generated/shared/c++/HybridTurboShakeSpec.cpp - ../nitrogen/generated/shared/c++/HybridUtilsSpec.cpp - ../nitrogen/generated/shared/c++/HybridX509CertificateHandleSpec.cpp - # Android-specific Nitrogen C++ sources - +target_sources(QuickCrypto PRIVATE + "${CMAKE_CURRENT_LIST_DIR}/QuickCryptoOnLoad.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridArgon2SpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridBlake3SpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridCertificateSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridCipherFactorySpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridCipherSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridDhKeyPairSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridDiffieHellmanSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridDsaKeyPairSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridECDHSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridEcKeyPairSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridEdKeyPairSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridHashSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridHkdfSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridHmacSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridKeyObjectHandleSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridKmacSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridMlDsaKeyPairSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridMlKemKeyPairSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridPbkdf2SpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridPrimeSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridRandomSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridRsaCipherSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridRsaKeyPairSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridScryptSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridSignHandleSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridSlhDsaKeyPairSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridTurboShakeSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridUtilsSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridVerifyHandleSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../android/c++/HybridX509CertificateHandleSpecClass.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/CipherArgs.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/CipherInfo.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridArgon2Spec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridBlake3Spec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridCertificateSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridCipherFactorySpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridCipherSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridDhKeyPairSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridDiffieHellmanSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridDsaKeyPairSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridECDHSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridEcKeyPairSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridEdKeyPairSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridHashSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridHkdfSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridHmacSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridKeyObjectHandleSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridKmacSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridMlDsaKeyPairSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridMlKemKeyPairSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridPbkdf2Spec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridPrimeSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridRandomSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridRsaCipherSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridRsaKeyPairSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridScryptSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridSignHandleSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridSlhDsaKeyPairSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridTurboShakeSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridUtilsSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridVerifyHandleSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/HybridX509CertificateHandleSpec.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/JWK.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/KeyDetail.cpp" + "${CMAKE_CURRENT_LIST_DIR}/../shared/c++/KeyObject.cpp" ) -# From node_modules/react-native/ReactAndroid/cmake-utils/folly-flags.cmake -# Used in node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake -target_compile_definitions( - QuickCrypto PRIVATE - -DFOLLY_NO_CONFIG=1 - -DFOLLY_HAVE_CLOCK_GETTIME=1 - -DFOLLY_USE_LIBCPP=1 - -DFOLLY_CFG_NO_COROUTINES=1 - -DFOLLY_MOBILE=1 - -DFOLLY_HAVE_RECVMMSG=1 - -DFOLLY_HAVE_PTHREAD=1 - # Once we target android-23 above, we can comment - # the following line. NDK uses GNU style stderror_r() after API 23. - -DFOLLY_HAVE_XSI_STRERROR_R=1 -) +find_package(fbjni REQUIRED CONFIG) +find_package(nitro-core REQUIRED CONFIG) -# Add all libraries required by the generated specs -find_package(fbjni REQUIRED) # <-- Used for communication between Java <-> C++ -find_package(ReactAndroid REQUIRED) # <-- Used to set up React Native bindings (e.g. CallInvoker/TurboModule) -find_package(react-native-nitro-modules REQUIRED) # <-- Used to create all HybridObjects and use the Nitro core library +target_link_libraries(QuickCrypto + fbjni::fbjni + nitro-core::NitroModules -# Link all libraries together -target_link_libraries( - QuickCrypto - fbjni::fbjni # <-- Facebook C++ JNI helpers - ReactAndroid::jsi # <-- RN: JSI - react-native-nitro-modules::NitroModules # <-- NitroModules Core :) ) - -# Link react-native (different prefab between RN 0.75 and RN 0.76) -if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76) - target_link_libraries( - QuickCrypto - ReactAndroid::reactnative # <-- RN: Native Modules umbrella prefab - ) -else() - target_link_libraries( - QuickCrypto - ReactAndroid::react_nativemodule_core # <-- RN: TurboModules Core - ) -endif() diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/QuickCrypto+autolinking.gradle b/packages/react-native-quick-crypto/nitrogen/generated/android/QuickCrypto+autolinking.gradle index 5b0cc3685..cacb78371 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/android/QuickCrypto+autolinking.gradle +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/QuickCrypto+autolinking.gradle @@ -1,27 +1,10 @@ /// /// QuickCrypto+autolinking.gradle /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -/// This is a Gradle file that adds all files generated by Nitrogen -/// to the current Gradle project. -/// -/// To use it, add this to your build.gradle: -/// ```gradle -/// apply from: '../nitrogen/generated/android/QuickCrypto+autolinking.gradle' -/// ``` - -logger.warn("[NitroModules] 🔥 QuickCrypto is boosted by nitro!") - -android { - sourceSets { - main { - java.srcDirs += [ - // Nitrogen files - "${project.projectDir}/../nitrogen/generated/android/kotlin" - ] - } - } -} +// Resolve beside this script so custom Nitrogen output directories work too. +def nitrogenDirectory = buildscript.sourceFile.parentFile +android.sourceSets.main.java.srcDirs += [new File(nitrogenDirectory, 'kotlin')] diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/QuickCryptoOnLoad.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/QuickCryptoOnLoad.cpp index a34947703..074b1f736 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/android/QuickCryptoOnLoad.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/QuickCryptoOnLoad.cpp @@ -1,334 +1,76 @@ /// /// QuickCryptoOnLoad.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#ifndef BUILDING_QUICKCRYPTO_WITH_GENERATED_CMAKE_PROJECT -#error QuickCryptoOnLoad.cpp is not being built with the autogenerated CMakeLists.txt project. Is a different CMakeLists.txt building this? -#endif - -#include "QuickCryptoOnLoad.hpp" - -#include -#include -#include - -#include "HybridArgon2.hpp" -#include "HybridBlake3.hpp" -#include "HybridCertificate.hpp" -#include "HybridCipher.hpp" -#include "HybridCipherFactory.hpp" -#include "HybridDhKeyPair.hpp" -#include "HybridDiffieHellman.hpp" -#include "HybridDsaKeyPair.hpp" -#include "HybridECDH.hpp" -#include "HybridEcKeyPair.hpp" -#include "HybridEdKeyPair.hpp" -#include "HybridHash.hpp" -#include "HybridHkdf.hpp" -#include "HybridHmac.hpp" -#include "HybridKmac.hpp" -#include "HybridKeyObjectHandle.hpp" -#include "HybridMlDsaKeyPair.hpp" -#include "HybridMlKemKeyPair.hpp" -#include "HybridSlhDsaKeyPair.hpp" -#include "HybridPbkdf2.hpp" -#include "HybridPrime.hpp" -#include "HybridRandom.hpp" -#include "HybridRsaCipher.hpp" -#include "HybridRsaKeyPair.hpp" -#include "HybridScrypt.hpp" -#include "HybridSignHandle.hpp" -#include "HybridTurboShake.hpp" -#include "HybridUtils.hpp" -#include "HybridVerifyHandle.hpp" -#include "HybridX509Certificate.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include namespace margelo::nitro::crypto { + void registerAllNatives() { -int initialize(JavaVM* vm) { - using namespace margelo::nitro; - using namespace margelo::nitro::crypto; - using namespace facebook; - return facebook::jni::initialize(vm, [] { - // Register native JNI methods - - - // Register Nitro Hybrid Objects - HybridObjectRegistry::registerHybridObjectConstructor( - "Argon2", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridArgon2\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Blake3", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridBlake3\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Certificate", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridCertificate\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Cipher", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridCipher\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "CipherFactory", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridCipherFactory\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "DhKeyPair", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridDhKeyPair\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "DiffieHellman", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridDiffieHellman\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "DsaKeyPair", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridDsaKeyPair\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "ECDH", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridECDH\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "EcKeyPair", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridEcKeyPair\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "EdKeyPair", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridEdKeyPair\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Hash", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridHash\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Hkdf", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridHkdf\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Hmac", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridHmac\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Kmac", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridKmac\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "KeyObjectHandle", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridKeyObjectHandle\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "MlDsaKeyPair", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridMlDsaKeyPair\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "MlKemKeyPair", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridMlKemKeyPair\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "SlhDsaKeyPair", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridSlhDsaKeyPair\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Pbkdf2", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridPbkdf2\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Prime", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridPrime\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Random", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridRandom\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "RsaCipher", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridRsaCipher\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "RsaKeyPair", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridRsaKeyPair\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Scrypt", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridScrypt\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "SignHandle", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridSignHandle\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "TurboShake", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridTurboShake\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Utils", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridUtils\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "VerifyHandle", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridVerifyHandle\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "X509CertificateHandle", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridX509Certificate\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - }); + HybridClassRegistry::registerHybridClass("crypto.Argon2", HybridArgon2Spec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Blake3", HybridBlake3Spec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Certificate", HybridCertificateSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Cipher", HybridCipherSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.CipherFactory", HybridCipherFactorySpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.DhKeyPair", HybridDhKeyPairSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.DiffieHellman", HybridDiffieHellmanSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.DsaKeyPair", HybridDsaKeyPairSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.EcKeyPair", HybridEcKeyPairSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.ECDH", HybridECDHSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.EdKeyPair", HybridEdKeyPairSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Hash", HybridHashSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Hkdf", HybridHkdfSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Hmac", HybridHmacSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.KeyObjectHandle", HybridKeyObjectHandleSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Kmac", HybridKmacSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.MlDsaKeyPair", HybridMlDsaKeyPairSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.MlKemKeyPair", HybridMlKemKeyPairSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Pbkdf2", HybridPbkdf2Spec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Prime", HybridPrimeSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Random", HybridRandomSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.RsaCipher", HybridRsaCipherSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.RsaKeyPair", HybridRsaKeyPairSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Scrypt", HybridScryptSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.SignHandle", HybridSignHandleSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.VerifyHandle", HybridVerifyHandleSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.SlhDsaKeyPair", HybridSlhDsaKeyPairSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.TurboShake", HybridTurboShakeSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Utils", HybridUtilsSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.X509CertificateHandle", HybridX509CertificateHandleSpec::Class::get()); + } } - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/QuickCryptoOnLoad.hpp b/packages/react-native-quick-crypto/nitrogen/generated/android/QuickCryptoOnLoad.hpp deleted file mode 100644 index 7086216a8..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/android/QuickCryptoOnLoad.hpp +++ /dev/null @@ -1,25 +0,0 @@ -/// -/// QuickCryptoOnLoad.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#include -#include - -namespace margelo::nitro::crypto { - - /** - * Initializes the native (C++) part of QuickCrypto, and autolinks all Hybrid Objects. - * Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`). - * Example: - * ```cpp (cpp-adapter.cpp) - * JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) { - * return margelo::nitro::crypto::initialize(vm); - * } - * ``` - */ - int initialize(JavaVM* vm); - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridArgon2SpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridArgon2SpecClass.cpp new file mode 100644 index 000000000..ac1c3aec3 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridArgon2SpecClass.cpp @@ -0,0 +1,38 @@ +/// +/// HybridArgon2SpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include "HybridArgon2.hpp" + +namespace margelo::nitro::crypto { + + namespace { + struct HybridArgon2SpecBindings final { + static Promise hash(const std::string& algorithm, const ArrayBuffer& message, const ArrayBuffer& nonce, double parallelism, double tagLength, double memory, double passes, double version, const std::optional& secret, const std::optional& associatedData) { + return ::margelo::nitro::crypto::HybridArgon2::hash(std::forward(algorithm), std::forward(message), std::forward(nonce), std::forward(parallelism), std::forward(tagLength), std::forward(memory), std::forward(passes), std::forward(version), std::forward(secret), std::forward(associatedData)); + } + + static ArrayBuffer hashSync(const std::string& algorithm, const ArrayBuffer& message, const ArrayBuffer& nonce, double parallelism, double tagLength, double memory, double passes, double version, const std::optional& secret, const std::optional& associatedData) { + return ::margelo::nitro::crypto::HybridArgon2::hashSync(std::forward(algorithm), std::forward(message), std::forward(nonce), std::forward(parallelism), std::forward(tagLength), std::forward(memory), std::forward(passes), std::forward(version), std::forward(secret), std::forward(associatedData)); + } + }; + } + + const std::shared_ptr& HybridArgon2Spec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerStaticHybridMethod("hash", &HybridArgon2SpecBindings::hash); + clazz.registerStaticHybridMethod("hashSync", &HybridArgon2SpecBindings::hashSync); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridBlake3SpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridBlake3SpecClass.cpp new file mode 100644 index 000000000..d079b8b89 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridBlake3SpecClass.cpp @@ -0,0 +1,49 @@ +/// +/// HybridBlake3SpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include "HybridBlake3.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridBlake3SpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridBlake3>, + "Blake3: ::margelo::nitro::crypto::HybridBlake3 must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridBlake3>(); + } + + static std::string getVersion() { + return ::margelo::nitro::crypto::HybridBlake3::getVersion(); + } + }; + } + + const std::shared_ptr& HybridBlake3Spec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("initHash", &HybridBlake3Spec::initHash); + clazz.registerHybridMethod("initKeyed", &HybridBlake3Spec::initKeyed); + clazz.registerHybridMethod("initDeriveKey", &HybridBlake3Spec::initDeriveKey); + clazz.registerHybridMethod("update", &HybridBlake3Spec::update); + clazz.registerHybridMethod("digest", &HybridBlake3Spec::digest); + clazz.registerHybridMethod("reset", &HybridBlake3Spec::reset); + clazz.registerHybridMethod("copy", &HybridBlake3Spec::copy); + clazz.registerHybridConstructor(&HybridBlake3SpecBindings::constructor); + clazz.registerStaticHybridMethod("getVersion", &HybridBlake3SpecBindings::getVersion); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridCertificateSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridCertificateSpecClass.cpp new file mode 100644 index 000000000..d197cc044 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridCertificateSpecClass.cpp @@ -0,0 +1,40 @@ +/// +/// HybridCertificateSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include "HybridCertificate.hpp" + +namespace margelo::nitro::crypto { + + namespace { + struct HybridCertificateSpecBindings final { + static bool verifySpkac(const ArrayBuffer& spkac) { + return ::margelo::nitro::crypto::HybridCertificate::verifySpkac(std::forward(spkac)); + } + + static ArrayBuffer exportPublicKey(const ArrayBuffer& spkac) { + return ::margelo::nitro::crypto::HybridCertificate::exportPublicKey(std::forward(spkac)); + } + + static ArrayBuffer exportChallenge(const ArrayBuffer& spkac) { + return ::margelo::nitro::crypto::HybridCertificate::exportChallenge(std::forward(spkac)); + } + }; + } + + const std::shared_ptr& HybridCertificateSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerStaticHybridMethod("verifySpkac", &HybridCertificateSpecBindings::verifySpkac); + clazz.registerStaticHybridMethod("exportPublicKey", &HybridCertificateSpecBindings::exportPublicKey); + clazz.registerStaticHybridMethod("exportChallenge", &HybridCertificateSpecBindings::exportChallenge); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridCipherFactorySpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridCipherFactorySpecClass.cpp new file mode 100644 index 000000000..7b9135886 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridCipherFactorySpecClass.cpp @@ -0,0 +1,32 @@ +/// +/// HybridCipherFactorySpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include "HybridCipherFactory.hpp" + +namespace margelo::nitro::crypto { + + namespace { + struct HybridCipherFactorySpecBindings final { + static std::shared_ptr createCipher(const CipherArgs& args) { + return ::margelo::nitro::crypto::HybridCipherFactory::createCipher(std::forward(args)); + } + }; + } + + const std::shared_ptr& HybridCipherFactorySpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerStaticHybridMethod("createCipher", &HybridCipherFactorySpecBindings::createCipher); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridCipherSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridCipherSpecClass.cpp new file mode 100644 index 000000000..187b58fa5 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridCipherSpecClass.cpp @@ -0,0 +1,47 @@ +/// +/// HybridCipherSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include +#include +#include "HybridCipher.hpp" + +namespace margelo::nitro::crypto { + + namespace { + struct HybridCipherSpecBindings final { + static std::vector getSupportedCiphers() { + return ::margelo::nitro::crypto::HybridCipher::getSupportedCiphers(); + } + + static std::optional getCipherInfo(const std::string& name, const std::optional& keyLength, const std::optional& ivLength) { + return ::margelo::nitro::crypto::HybridCipher::getCipherInfo(std::forward(name), std::forward(keyLength), std::forward(ivLength)); + } + }; + } + + const std::shared_ptr& HybridCipherSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("update", &HybridCipherSpec::update); + clazz.registerHybridMethod("final", &HybridCipherSpec::final); + clazz.registerHybridMethod("setArgs", &HybridCipherSpec::setArgs); + clazz.registerHybridMethod("setAAD", &HybridCipherSpec::setAAD); + clazz.registerHybridMethod("setAutoPadding", &HybridCipherSpec::setAutoPadding); + clazz.registerHybridMethod("setAuthTag", &HybridCipherSpec::setAuthTag); + clazz.registerHybridMethod("getAuthTag", &HybridCipherSpec::getAuthTag); + clazz.registerStaticHybridMethod("getSupportedCiphers", &HybridCipherSpecBindings::getSupportedCiphers); + clazz.registerStaticHybridMethod("getCipherInfo", &HybridCipherSpecBindings::getCipherInfo); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridDhKeyPairSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridDhKeyPairSpecClass.cpp new file mode 100644 index 000000000..bd9f641b6 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridDhKeyPairSpecClass.cpp @@ -0,0 +1,42 @@ +/// +/// HybridDhKeyPairSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include "HybridDhKeyPair.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridDhKeyPairSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridDhKeyPair>, + "DhKeyPair: ::margelo::nitro::crypto::HybridDhKeyPair must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridDhKeyPair>(); + } + }; + } + + const std::shared_ptr& HybridDhKeyPairSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("generateKeyPair", &HybridDhKeyPairSpec::generateKeyPair); + clazz.registerHybridMethod("generateKeyPairSync", &HybridDhKeyPairSpec::generateKeyPairSync); + clazz.registerHybridMethod("setPrimeLength", &HybridDhKeyPairSpec::setPrimeLength); + clazz.registerHybridMethod("setPrime", &HybridDhKeyPairSpec::setPrime); + clazz.registerHybridMethod("setGenerator", &HybridDhKeyPairSpec::setGenerator); + clazz.registerHybridMethod("getPublicKey", &HybridDhKeyPairSpec::getPublicKey); + clazz.registerHybridMethod("getPrivateKey", &HybridDhKeyPairSpec::getPrivateKey); + clazz.registerHybridConstructor(&HybridDhKeyPairSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridDiffieHellmanSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridDiffieHellmanSpecClass.cpp new file mode 100644 index 000000000..7ee9fe0f5 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridDiffieHellmanSpecClass.cpp @@ -0,0 +1,45 @@ +/// +/// HybridDiffieHellmanSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include "HybridDiffieHellman.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridDiffieHellmanSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridDiffieHellman>, + "DiffieHellman: ::margelo::nitro::crypto::HybridDiffieHellman must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridDiffieHellman>(); + } + }; + } + + const std::shared_ptr& HybridDiffieHellmanSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("init", &HybridDiffieHellmanSpec::init); + clazz.registerHybridMethod("initWithSize", &HybridDiffieHellmanSpec::initWithSize); + clazz.registerHybridMethod("generateKeys", &HybridDiffieHellmanSpec::generateKeys); + clazz.registerHybridMethod("computeSecret", &HybridDiffieHellmanSpec::computeSecret); + clazz.registerHybridMethod("getPrime", &HybridDiffieHellmanSpec::getPrime); + clazz.registerHybridMethod("getGenerator", &HybridDiffieHellmanSpec::getGenerator); + clazz.registerHybridMethod("getPublicKey", &HybridDiffieHellmanSpec::getPublicKey); + clazz.registerHybridMethod("getPrivateKey", &HybridDiffieHellmanSpec::getPrivateKey); + clazz.registerHybridMethod("setPublicKey", &HybridDiffieHellmanSpec::setPublicKey); + clazz.registerHybridMethod("setPrivateKey", &HybridDiffieHellmanSpec::setPrivateKey); + clazz.registerHybridMethod("getVerifyError", &HybridDiffieHellmanSpec::getVerifyError); + clazz.registerHybridConstructor(&HybridDiffieHellmanSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridDsaKeyPairSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridDsaKeyPairSpecClass.cpp new file mode 100644 index 000000000..da777f6c4 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridDsaKeyPairSpecClass.cpp @@ -0,0 +1,41 @@ +/// +/// HybridDsaKeyPairSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include "HybridDsaKeyPair.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridDsaKeyPairSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridDsaKeyPair>, + "DsaKeyPair: ::margelo::nitro::crypto::HybridDsaKeyPair must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridDsaKeyPair>(); + } + }; + } + + const std::shared_ptr& HybridDsaKeyPairSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("generateKeyPair", &HybridDsaKeyPairSpec::generateKeyPair); + clazz.registerHybridMethod("generateKeyPairSync", &HybridDsaKeyPairSpec::generateKeyPairSync); + clazz.registerHybridMethod("setModulusLength", &HybridDsaKeyPairSpec::setModulusLength); + clazz.registerHybridMethod("setDivisorLength", &HybridDsaKeyPairSpec::setDivisorLength); + clazz.registerHybridMethod("getPublicKey", &HybridDsaKeyPairSpec::getPublicKey); + clazz.registerHybridMethod("getPrivateKey", &HybridDsaKeyPairSpec::getPrivateKey); + clazz.registerHybridConstructor(&HybridDsaKeyPairSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridECDHSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridECDHSpecClass.cpp new file mode 100644 index 000000000..0544f8b83 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridECDHSpecClass.cpp @@ -0,0 +1,47 @@ +/// +/// HybridECDHSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include "HybridECDH.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridECDHSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridECDH>, + "ECDH: ::margelo::nitro::crypto::HybridECDH must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridECDH>(); + } + + static ArrayBuffer convertKey(const ArrayBuffer& key, const std::string& curve, double format) { + return ::margelo::nitro::crypto::HybridECDH::convertKey(std::forward(key), std::forward(curve), std::forward(format)); + } + }; + } + + const std::shared_ptr& HybridECDHSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("init", &HybridECDHSpec::init); + clazz.registerHybridMethod("generateKeys", &HybridECDHSpec::generateKeys); + clazz.registerHybridMethod("computeSecret", &HybridECDHSpec::computeSecret); + clazz.registerHybridMethod("getPrivateKey", &HybridECDHSpec::getPrivateKey); + clazz.registerHybridMethod("setPrivateKey", &HybridECDHSpec::setPrivateKey); + clazz.registerHybridMethod("getPublicKey", &HybridECDHSpec::getPublicKey); + clazz.registerHybridMethod("setPublicKey", &HybridECDHSpec::setPublicKey); + clazz.registerHybridConstructor(&HybridECDHSpecBindings::constructor); + clazz.registerStaticHybridMethod("convertKey", &HybridECDHSpecBindings::convertKey); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridEcKeyPairSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridEcKeyPairSpecClass.cpp new file mode 100644 index 000000000..406d50d34 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridEcKeyPairSpecClass.cpp @@ -0,0 +1,52 @@ +/// +/// HybridEcKeyPairSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include +#include "HybridEcKeyPair.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridEcKeyPairSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridEcKeyPair>, + "EcKeyPair: ::margelo::nitro::crypto::HybridEcKeyPair must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridEcKeyPair>(); + } + + static std::vector getSupportedCurves() { + return ::margelo::nitro::crypto::HybridEcKeyPair::getSupportedCurves(); + } + }; + } + + const std::shared_ptr& HybridEcKeyPairSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("generateKeyPair", &HybridEcKeyPairSpec::generateKeyPair); + clazz.registerHybridMethod("generateKeyPairSync", &HybridEcKeyPairSpec::generateKeyPairSync); + clazz.registerHybridMethod("importKey", &HybridEcKeyPairSpec::importKey); + clazz.registerHybridMethod("exportKey", &HybridEcKeyPairSpec::exportKey); + clazz.registerHybridMethod("getPublicKey", &HybridEcKeyPairSpec::getPublicKey); + clazz.registerHybridMethod("getPrivateKey", &HybridEcKeyPairSpec::getPrivateKey); + clazz.registerHybridMethod("setCurve", &HybridEcKeyPairSpec::setCurve); + clazz.registerHybridMethod("sign", &HybridEcKeyPairSpec::sign); + clazz.registerHybridMethod("verify", &HybridEcKeyPairSpec::verify); + clazz.registerHybridConstructor(&HybridEcKeyPairSpecBindings::constructor); + clazz.registerStaticHybridMethod("getSupportedCurves", &HybridEcKeyPairSpecBindings::getSupportedCurves); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridEdKeyPairSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridEdKeyPairSpecClass.cpp new file mode 100644 index 000000000..10b8c93d7 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridEdKeyPairSpecClass.cpp @@ -0,0 +1,47 @@ +/// +/// HybridEdKeyPairSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include "HybridEdKeyPair.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridEdKeyPairSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridEdKeyPair>, + "EdKeyPair: ::margelo::nitro::crypto::HybridEdKeyPair must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridEdKeyPair>(); + } + }; + } + + const std::shared_ptr& HybridEdKeyPairSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("diffieHellman", &HybridEdKeyPairSpec::diffieHellman); + clazz.registerHybridMethod("generateKeyPair", &HybridEdKeyPairSpec::generateKeyPair); + clazz.registerHybridMethod("generateKeyPairSync", &HybridEdKeyPairSpec::generateKeyPairSync); + clazz.registerHybridMethod("getPublicKey", &HybridEdKeyPairSpec::getPublicKey); + clazz.registerHybridMethod("getPrivateKey", &HybridEdKeyPairSpec::getPrivateKey); + clazz.registerHybridMethod("sign", &HybridEdKeyPairSpec::sign); + clazz.registerHybridMethod("signSync", &HybridEdKeyPairSpec::signSync); + clazz.registerHybridMethod("verify", &HybridEdKeyPairSpec::verify); + clazz.registerHybridMethod("verifySync", &HybridEdKeyPairSpec::verifySync); + clazz.registerHybridMethod("setCurve", &HybridEdKeyPairSpec::setCurve); + clazz.registerHybridConstructor(&HybridEdKeyPairSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridHashSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridHashSpecClass.cpp new file mode 100644 index 000000000..743aa8ffc --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridHashSpecClass.cpp @@ -0,0 +1,53 @@ +/// +/// HybridHashSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include +#include +#include "HybridHash.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridHashSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridHash>, + "Hash: ::margelo::nitro::crypto::HybridHash must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridHash>(); + } + + static std::vector getSupportedHashAlgorithms() { + return ::margelo::nitro::crypto::HybridHash::getSupportedHashAlgorithms(); + } + + static std::string getOpenSSLVersion() { + return ::margelo::nitro::crypto::HybridHash::getOpenSSLVersion(); + } + }; + } + + const std::shared_ptr& HybridHashSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("createHash", &HybridHashSpec::createHash); + clazz.registerHybridMethod("update", &HybridHashSpec::update); + clazz.registerHybridMethod("digest", &HybridHashSpec::digest); + clazz.registerHybridMethod("copy", &HybridHashSpec::copy); + clazz.registerHybridConstructor(&HybridHashSpecBindings::constructor); + clazz.registerStaticHybridMethod("getSupportedHashAlgorithms", &HybridHashSpecBindings::getSupportedHashAlgorithms); + clazz.registerStaticHybridMethod("getOpenSSLVersion", &HybridHashSpecBindings::getOpenSSLVersion); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridHkdfSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridHkdfSpecClass.cpp new file mode 100644 index 000000000..d98866b17 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridHkdfSpecClass.cpp @@ -0,0 +1,38 @@ +/// +/// HybridHkdfSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include "HybridHkdf.hpp" + +namespace margelo::nitro::crypto { + + namespace { + struct HybridHkdfSpecBindings final { + static ArrayBuffer deriveKeySync(const std::string& algorithm, const ArrayBuffer& key, const ArrayBuffer& salt, const ArrayBuffer& info, double length, HkdfMode mode) { + return ::margelo::nitro::crypto::HybridHkdf::deriveKeySync(std::forward(algorithm), std::forward(key), std::forward(salt), std::forward(info), std::forward(length), std::forward(mode)); + } + + static Promise deriveKey(const std::string& algorithm, const ArrayBuffer& key, const ArrayBuffer& salt, const ArrayBuffer& info, double length, HkdfMode mode) { + return ::margelo::nitro::crypto::HybridHkdf::deriveKey(std::forward(algorithm), std::forward(key), std::forward(salt), std::forward(info), std::forward(length), std::forward(mode)); + } + }; + } + + const std::shared_ptr& HybridHkdfSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerStaticHybridMethod("deriveKeySync", &HybridHkdfSpecBindings::deriveKeySync); + clazz.registerStaticHybridMethod("deriveKey", &HybridHkdfSpecBindings::deriveKey); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridHmacSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridHmacSpecClass.cpp new file mode 100644 index 000000000..3113915ef --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridHmacSpecClass.cpp @@ -0,0 +1,39 @@ +/// +/// HybridHmacSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include "HybridHmac.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridHmacSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridHmac>, + "Hmac: ::margelo::nitro::crypto::HybridHmac must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridHmac>(); + } + }; + } + + const std::shared_ptr& HybridHmacSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("createHmac", &HybridHmacSpec::createHmac); + clazz.registerHybridMethod("update", &HybridHmacSpec::update); + clazz.registerHybridMethod("digest", &HybridHmacSpec::digest); + clazz.registerHybridConstructor(&HybridHmacSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridKeyObjectHandleSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridKeyObjectHandleSpecClass.cpp new file mode 100644 index 000000000..017848c7e --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridKeyObjectHandleSpecClass.cpp @@ -0,0 +1,64 @@ +/// +/// HybridKeyObjectHandleSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "HybridKeyObjectHandle.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridKeyObjectHandleSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridKeyObjectHandle>, + "KeyObjectHandle: ::margelo::nitro::crypto::HybridKeyObjectHandle must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridKeyObjectHandle>(); + } + }; + } + + const std::shared_ptr& HybridKeyObjectHandleSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("exportKey", &HybridKeyObjectHandleSpec::exportKey); + clazz.registerHybridMethod("exportJwk", &HybridKeyObjectHandleSpec::exportJwk); + clazz.registerHybridMethod("exportRawPublic", &HybridKeyObjectHandleSpec::exportRawPublic); + clazz.registerHybridMethod("exportRawPrivate", &HybridKeyObjectHandleSpec::exportRawPrivate); + clazz.registerHybridMethod("exportRawSeed", &HybridKeyObjectHandleSpec::exportRawSeed); + clazz.registerHybridMethod("exportECPublicRaw", &HybridKeyObjectHandleSpec::exportECPublicRaw); + clazz.registerHybridMethod("exportECPrivateRaw", &HybridKeyObjectHandleSpec::exportECPrivateRaw); + clazz.registerHybridMethod("getAsymmetricKeyType", &HybridKeyObjectHandleSpec::getAsymmetricKeyType); + clazz.registerHybridMethod("init", &HybridKeyObjectHandleSpec::init); + clazz.registerHybridMethod("initECRaw", &HybridKeyObjectHandleSpec::initECRaw); + clazz.registerHybridMethod("initPqcRaw", &HybridKeyObjectHandleSpec::initPqcRaw); + clazz.registerHybridMethod("initRawPublic", &HybridKeyObjectHandleSpec::initRawPublic); + clazz.registerHybridMethod("initRawPrivate", &HybridKeyObjectHandleSpec::initRawPrivate); + clazz.registerHybridMethod("initRawSeed", &HybridKeyObjectHandleSpec::initRawSeed); + clazz.registerHybridMethod("initJwk", &HybridKeyObjectHandleSpec::initJwk); + clazz.registerHybridMethod("keyDetail", &HybridKeyObjectHandleSpec::keyDetail); + clazz.registerHybridMethod("keyEquals", &HybridKeyObjectHandleSpec::keyEquals); + clazz.registerHybridMethod("getSymmetricKeySize", &HybridKeyObjectHandleSpec::getSymmetricKeySize); + clazz.registerHybridMethod("checkEcKeyData", &HybridKeyObjectHandleSpec::checkEcKeyData); + clazz.registerHybridConstructor(&HybridKeyObjectHandleSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridKmacSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridKmacSpecClass.cpp new file mode 100644 index 000000000..dc089a14e --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridKmacSpecClass.cpp @@ -0,0 +1,39 @@ +/// +/// HybridKmacSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include "HybridKmac.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridKmacSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridKmac>, + "Kmac: ::margelo::nitro::crypto::HybridKmac must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridKmac>(); + } + }; + } + + const std::shared_ptr& HybridKmacSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("createKmac", &HybridKmacSpec::createKmac); + clazz.registerHybridMethod("update", &HybridKmacSpec::update); + clazz.registerHybridMethod("digest", &HybridKmacSpec::digest); + clazz.registerHybridConstructor(&HybridKmacSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridMlDsaKeyPairSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridMlDsaKeyPairSpecClass.cpp new file mode 100644 index 000000000..c1b7f0381 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridMlDsaKeyPairSpecClass.cpp @@ -0,0 +1,45 @@ +/// +/// HybridMlDsaKeyPairSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include "HybridMlDsaKeyPair.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridMlDsaKeyPairSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridMlDsaKeyPair>, + "MlDsaKeyPair: ::margelo::nitro::crypto::HybridMlDsaKeyPair must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridMlDsaKeyPair>(); + } + }; + } + + const std::shared_ptr& HybridMlDsaKeyPairSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("generateKeyPair", &HybridMlDsaKeyPairSpec::generateKeyPair); + clazz.registerHybridMethod("generateKeyPairSync", &HybridMlDsaKeyPairSpec::generateKeyPairSync); + clazz.registerHybridMethod("getPublicKey", &HybridMlDsaKeyPairSpec::getPublicKey); + clazz.registerHybridMethod("getPrivateKey", &HybridMlDsaKeyPairSpec::getPrivateKey); + clazz.registerHybridMethod("sign", &HybridMlDsaKeyPairSpec::sign); + clazz.registerHybridMethod("signSync", &HybridMlDsaKeyPairSpec::signSync); + clazz.registerHybridMethod("verify", &HybridMlDsaKeyPairSpec::verify); + clazz.registerHybridMethod("verifySync", &HybridMlDsaKeyPairSpec::verifySync); + clazz.registerHybridMethod("setVariant", &HybridMlDsaKeyPairSpec::setVariant); + clazz.registerHybridConstructor(&HybridMlDsaKeyPairSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridMlKemKeyPairSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridMlKemKeyPairSpecClass.cpp new file mode 100644 index 000000000..779ce242d --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridMlKemKeyPairSpecClass.cpp @@ -0,0 +1,47 @@ +/// +/// HybridMlKemKeyPairSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include "HybridMlKemKeyPair.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridMlKemKeyPairSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridMlKemKeyPair>, + "MlKemKeyPair: ::margelo::nitro::crypto::HybridMlKemKeyPair must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridMlKemKeyPair>(); + } + }; + } + + const std::shared_ptr& HybridMlKemKeyPairSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("setVariant", &HybridMlKemKeyPairSpec::setVariant); + clazz.registerHybridMethod("generateKeyPair", &HybridMlKemKeyPairSpec::generateKeyPair); + clazz.registerHybridMethod("generateKeyPairSync", &HybridMlKemKeyPairSpec::generateKeyPairSync); + clazz.registerHybridMethod("getPublicKey", &HybridMlKemKeyPairSpec::getPublicKey); + clazz.registerHybridMethod("getPrivateKey", &HybridMlKemKeyPairSpec::getPrivateKey); + clazz.registerHybridMethod("setPublicKey", &HybridMlKemKeyPairSpec::setPublicKey); + clazz.registerHybridMethod("setPrivateKey", &HybridMlKemKeyPairSpec::setPrivateKey); + clazz.registerHybridMethod("encapsulate", &HybridMlKemKeyPairSpec::encapsulate); + clazz.registerHybridMethod("encapsulateSync", &HybridMlKemKeyPairSpec::encapsulateSync); + clazz.registerHybridMethod("decapsulate", &HybridMlKemKeyPairSpec::decapsulate); + clazz.registerHybridMethod("decapsulateSync", &HybridMlKemKeyPairSpec::decapsulateSync); + clazz.registerHybridConstructor(&HybridMlKemKeyPairSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridPbkdf2SpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridPbkdf2SpecClass.cpp new file mode 100644 index 000000000..144d03cc0 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridPbkdf2SpecClass.cpp @@ -0,0 +1,37 @@ +/// +/// HybridPbkdf2SpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include "HybridPbkdf2.hpp" + +namespace margelo::nitro::crypto { + + namespace { + struct HybridPbkdf2SpecBindings final { + static Promise pbkdf2(const ArrayBuffer& password, const ArrayBuffer& salt, double iterations, double keylen, const std::string& digest) { + return ::margelo::nitro::crypto::HybridPbkdf2::pbkdf2(std::forward(password), std::forward(salt), std::forward(iterations), std::forward(keylen), std::forward(digest)); + } + + static ArrayBuffer pbkdf2Sync(const ArrayBuffer& password, const ArrayBuffer& salt, double iterations, double keylen, const std::string& digest) { + return ::margelo::nitro::crypto::HybridPbkdf2::pbkdf2Sync(std::forward(password), std::forward(salt), std::forward(iterations), std::forward(keylen), std::forward(digest)); + } + }; + } + + const std::shared_ptr& HybridPbkdf2Spec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerStaticHybridMethod("pbkdf2", &HybridPbkdf2SpecBindings::pbkdf2); + clazz.registerStaticHybridMethod("pbkdf2Sync", &HybridPbkdf2SpecBindings::pbkdf2Sync); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridPrimeSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridPrimeSpecClass.cpp new file mode 100644 index 000000000..c9f334dae --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridPrimeSpecClass.cpp @@ -0,0 +1,47 @@ +/// +/// HybridPrimeSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include "HybridPrime.hpp" + +namespace margelo::nitro::crypto { + + namespace { + struct HybridPrimeSpecBindings final { + static Promise generatePrime(double size, bool safe, const std::optional& add, const std::optional& rem) { + return ::margelo::nitro::crypto::HybridPrime::generatePrime(std::forward(size), std::forward(safe), std::forward(add), std::forward(rem)); + } + + static ArrayBuffer generatePrimeSync(double size, bool safe, const std::optional& add, const std::optional& rem) { + return ::margelo::nitro::crypto::HybridPrime::generatePrimeSync(std::forward(size), std::forward(safe), std::forward(add), std::forward(rem)); + } + + static Promise checkPrime(const ArrayBuffer& candidate, double checks) { + return ::margelo::nitro::crypto::HybridPrime::checkPrime(std::forward(candidate), std::forward(checks)); + } + + static bool checkPrimeSync(const ArrayBuffer& candidate, double checks) { + return ::margelo::nitro::crypto::HybridPrime::checkPrimeSync(std::forward(candidate), std::forward(checks)); + } + }; + } + + const std::shared_ptr& HybridPrimeSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerStaticHybridMethod("generatePrime", &HybridPrimeSpecBindings::generatePrime); + clazz.registerStaticHybridMethod("generatePrimeSync", &HybridPrimeSpecBindings::generatePrimeSync); + clazz.registerStaticHybridMethod("checkPrime", &HybridPrimeSpecBindings::checkPrime); + clazz.registerStaticHybridMethod("checkPrimeSync", &HybridPrimeSpecBindings::checkPrimeSync); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridRandomSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridRandomSpecClass.cpp new file mode 100644 index 000000000..603d211d9 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridRandomSpecClass.cpp @@ -0,0 +1,36 @@ +/// +/// HybridRandomSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include "HybridRandom.hpp" + +namespace margelo::nitro::crypto { + + namespace { + struct HybridRandomSpecBindings final { + static Promise randomFill(const ArrayBuffer& buffer, double offset, double size) { + return ::margelo::nitro::crypto::HybridRandom::randomFill(std::forward(buffer), std::forward(offset), std::forward(size)); + } + + static ArrayBuffer randomFillSync(const ArrayBuffer& buffer, double offset, double size) { + return ::margelo::nitro::crypto::HybridRandom::randomFillSync(std::forward(buffer), std::forward(offset), std::forward(size)); + } + }; + } + + const std::shared_ptr& HybridRandomSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerStaticHybridMethod("randomFill", &HybridRandomSpecBindings::randomFill); + clazz.registerStaticHybridMethod("randomFillSync", &HybridRandomSpecBindings::randomFillSync); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridRsaCipherSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridRsaCipherSpecClass.cpp new file mode 100644 index 000000000..3a6873e30 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridRsaCipherSpecClass.cpp @@ -0,0 +1,54 @@ +/// +/// HybridRsaCipherSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include +#include "HybridRsaCipher.hpp" + +namespace margelo::nitro::crypto { + + namespace { + struct HybridRsaCipherSpecBindings final { + static ArrayBuffer encrypt(const std::shared_ptr& keyHandle, const ArrayBuffer& data, double padding, const std::string& hashAlgorithm, const std::optional& label) { + return ::margelo::nitro::crypto::HybridRsaCipher::encrypt(std::forward(keyHandle), std::forward(data), std::forward(padding), std::forward(hashAlgorithm), std::forward(label)); + } + + static ArrayBuffer decrypt(const std::shared_ptr& keyHandle, const ArrayBuffer& data, double padding, const std::string& hashAlgorithm, const std::optional& label) { + return ::margelo::nitro::crypto::HybridRsaCipher::decrypt(std::forward(keyHandle), std::forward(data), std::forward(padding), std::forward(hashAlgorithm), std::forward(label)); + } + + static ArrayBuffer publicDecrypt(const std::shared_ptr& keyHandle, const ArrayBuffer& data, double padding) { + return ::margelo::nitro::crypto::HybridRsaCipher::publicDecrypt(std::forward(keyHandle), std::forward(data), std::forward(padding)); + } + + static ArrayBuffer privateEncrypt(const std::shared_ptr& keyHandle, const ArrayBuffer& data, double padding) { + return ::margelo::nitro::crypto::HybridRsaCipher::privateEncrypt(std::forward(keyHandle), std::forward(data), std::forward(padding)); + } + + static ArrayBuffer privateDecrypt(const std::shared_ptr& keyHandle, const ArrayBuffer& data, double padding, const std::string& hashAlgorithm, const std::optional& label) { + return ::margelo::nitro::crypto::HybridRsaCipher::privateDecrypt(std::forward(keyHandle), std::forward(data), std::forward(padding), std::forward(hashAlgorithm), std::forward(label)); + } + }; + } + + const std::shared_ptr& HybridRsaCipherSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerStaticHybridMethod("encrypt", &HybridRsaCipherSpecBindings::encrypt); + clazz.registerStaticHybridMethod("decrypt", &HybridRsaCipherSpecBindings::decrypt); + clazz.registerStaticHybridMethod("publicDecrypt", &HybridRsaCipherSpecBindings::publicDecrypt); + clazz.registerStaticHybridMethod("privateEncrypt", &HybridRsaCipherSpecBindings::privateEncrypt); + clazz.registerStaticHybridMethod("privateDecrypt", &HybridRsaCipherSpecBindings::privateDecrypt); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridRsaKeyPairSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridRsaKeyPairSpecClass.cpp new file mode 100644 index 000000000..f19df8f9b --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridRsaKeyPairSpecClass.cpp @@ -0,0 +1,47 @@ +/// +/// HybridRsaKeyPairSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include +#include "HybridRsaKeyPair.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridRsaKeyPairSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridRsaKeyPair>, + "RsaKeyPair: ::margelo::nitro::crypto::HybridRsaKeyPair must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridRsaKeyPair>(); + } + }; + } + + const std::shared_ptr& HybridRsaKeyPairSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("generateKeyPair", &HybridRsaKeyPairSpec::generateKeyPair); + clazz.registerHybridMethod("generateKeyPairSync", &HybridRsaKeyPairSpec::generateKeyPairSync); + clazz.registerHybridMethod("setModulusLength", &HybridRsaKeyPairSpec::setModulusLength); + clazz.registerHybridMethod("setPublicExponent", &HybridRsaKeyPairSpec::setPublicExponent); + clazz.registerHybridMethod("setHashAlgorithm", &HybridRsaKeyPairSpec::setHashAlgorithm); + clazz.registerHybridMethod("importKey", &HybridRsaKeyPairSpec::importKey); + clazz.registerHybridMethod("exportKey", &HybridRsaKeyPairSpec::exportKey); + clazz.registerHybridMethod("getPublicKey", &HybridRsaKeyPairSpec::getPublicKey); + clazz.registerHybridMethod("getPrivateKey", &HybridRsaKeyPairSpec::getPrivateKey); + clazz.registerHybridConstructor(&HybridRsaKeyPairSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridScryptSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridScryptSpecClass.cpp new file mode 100644 index 000000000..5ac17d9ab --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridScryptSpecClass.cpp @@ -0,0 +1,36 @@ +/// +/// HybridScryptSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include "HybridScrypt.hpp" + +namespace margelo::nitro::crypto { + + namespace { + struct HybridScryptSpecBindings final { + static Promise deriveKey(const ArrayBuffer& password, const ArrayBuffer& salt, double N, double r, double p, double maxmem, double keylen) { + return ::margelo::nitro::crypto::HybridScrypt::deriveKey(std::forward(password), std::forward(salt), std::forward(N), std::forward(r), std::forward(p), std::forward(maxmem), std::forward(keylen)); + } + + static ArrayBuffer deriveKeySync(const ArrayBuffer& password, const ArrayBuffer& salt, double N, double r, double p, double maxmem, double keylen) { + return ::margelo::nitro::crypto::HybridScrypt::deriveKeySync(std::forward(password), std::forward(salt), std::forward(N), std::forward(r), std::forward(p), std::forward(maxmem), std::forward(keylen)); + } + }; + } + + const std::shared_ptr& HybridScryptSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerStaticHybridMethod("deriveKey", &HybridScryptSpecBindings::deriveKey); + clazz.registerStaticHybridMethod("deriveKeySync", &HybridScryptSpecBindings::deriveKeySync); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridSignHandleSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridSignHandleSpecClass.cpp new file mode 100644 index 000000000..22aa1dd2d --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridSignHandleSpecClass.cpp @@ -0,0 +1,41 @@ +/// +/// HybridSignHandleSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include +#include "HybridSignHandle.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridSignHandleSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridSignHandle>, + "SignHandle: ::margelo::nitro::crypto::HybridSignHandle must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridSignHandle>(); + } + }; + } + + const std::shared_ptr& HybridSignHandleSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("init", &HybridSignHandleSpec::init); + clazz.registerHybridMethod("update", &HybridSignHandleSpec::update); + clazz.registerHybridMethod("sign", &HybridSignHandleSpec::sign); + clazz.registerHybridConstructor(&HybridSignHandleSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridSlhDsaKeyPairSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridSlhDsaKeyPairSpecClass.cpp new file mode 100644 index 000000000..216cbd4aa --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridSlhDsaKeyPairSpecClass.cpp @@ -0,0 +1,45 @@ +/// +/// HybridSlhDsaKeyPairSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include "HybridSlhDsaKeyPair.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridSlhDsaKeyPairSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridSlhDsaKeyPair>, + "SlhDsaKeyPair: ::margelo::nitro::crypto::HybridSlhDsaKeyPair must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridSlhDsaKeyPair>(); + } + }; + } + + const std::shared_ptr& HybridSlhDsaKeyPairSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("generateKeyPair", &HybridSlhDsaKeyPairSpec::generateKeyPair); + clazz.registerHybridMethod("generateKeyPairSync", &HybridSlhDsaKeyPairSpec::generateKeyPairSync); + clazz.registerHybridMethod("getPublicKey", &HybridSlhDsaKeyPairSpec::getPublicKey); + clazz.registerHybridMethod("getPrivateKey", &HybridSlhDsaKeyPairSpec::getPrivateKey); + clazz.registerHybridMethod("sign", &HybridSlhDsaKeyPairSpec::sign); + clazz.registerHybridMethod("signSync", &HybridSlhDsaKeyPairSpec::signSync); + clazz.registerHybridMethod("verify", &HybridSlhDsaKeyPairSpec::verify); + clazz.registerHybridMethod("verifySync", &HybridSlhDsaKeyPairSpec::verifySync); + clazz.registerHybridMethod("setVariant", &HybridSlhDsaKeyPairSpec::setVariant); + clazz.registerHybridConstructor(&HybridSlhDsaKeyPairSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridTurboShakeSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridTurboShakeSpecClass.cpp new file mode 100644 index 000000000..9ff813ab7 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridTurboShakeSpecClass.cpp @@ -0,0 +1,39 @@ +/// +/// HybridTurboShakeSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include +#include "HybridTurboShake.hpp" + +namespace margelo::nitro::crypto { + + namespace { + struct HybridTurboShakeSpecBindings final { + static Promise turboShake(TurboShakeVariant variant, double domainSeparation, double outputLength, const ArrayBuffer& data) { + return ::margelo::nitro::crypto::HybridTurboShake::turboShake(std::forward(variant), std::forward(domainSeparation), std::forward(outputLength), std::forward(data)); + } + + static Promise kangarooTwelve(KangarooTwelveVariant variant, double outputLength, const ArrayBuffer& data, const std::optional& customization) { + return ::margelo::nitro::crypto::HybridTurboShake::kangarooTwelve(std::forward(variant), std::forward(outputLength), std::forward(data), std::forward(customization)); + } + }; + } + + const std::shared_ptr& HybridTurboShakeSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerStaticHybridMethod("turboShake", &HybridTurboShakeSpecBindings::turboShake); + clazz.registerStaticHybridMethod("kangarooTwelve", &HybridTurboShakeSpecBindings::kangarooTwelve); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridUtilsSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridUtilsSpecClass.cpp new file mode 100644 index 000000000..ce4afb651 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridUtilsSpecClass.cpp @@ -0,0 +1,39 @@ +/// +/// HybridUtilsSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include "HybridUtils.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridUtilsSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridUtils>, + "Utils: ::margelo::nitro::crypto::HybridUtils must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridUtils>(); + } + + static bool timingSafeEqual(const ArrayBuffer& a, const ArrayBuffer& b) { + return ::margelo::nitro::crypto::HybridUtils::timingSafeEqual(std::forward(a), std::forward(b)); + } + }; + } + + const std::shared_ptr& HybridUtilsSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridConstructor(&HybridUtilsSpecBindings::constructor); + clazz.registerStaticHybridMethod("timingSafeEqual", &HybridUtilsSpecBindings::timingSafeEqual); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridVerifyHandleSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridVerifyHandleSpecClass.cpp new file mode 100644 index 000000000..aca5c65b4 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridVerifyHandleSpecClass.cpp @@ -0,0 +1,41 @@ +/// +/// HybridVerifyHandleSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include +#include "HybridVerifyHandle.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridVerifyHandleSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridVerifyHandle>, + "VerifyHandle: ::margelo::nitro::crypto::HybridVerifyHandle must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridVerifyHandle>(); + } + }; + } + + const std::shared_ptr& HybridVerifyHandleSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("init", &HybridVerifyHandleSpec::init); + clazz.registerHybridMethod("update", &HybridVerifyHandleSpec::update); + clazz.registerHybridMethod("verify", &HybridVerifyHandleSpec::verify); + clazz.registerHybridConstructor(&HybridVerifyHandleSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridX509CertificateHandleSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridX509CertificateHandleSpecClass.cpp new file mode 100644 index 000000000..be9a58260 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/c++/HybridX509CertificateHandleSpecClass.cpp @@ -0,0 +1,65 @@ +/// +/// HybridX509CertificateHandleSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include +#include +#include "HybridX509Certificate.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridX509CertificateHandleSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridX509Certificate>, + "X509CertificateHandle: ::margelo::nitro::crypto::HybridX509Certificate must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridX509Certificate>(); + } + }; + } + + const std::shared_ptr& HybridX509CertificateHandleSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("init", &HybridX509CertificateHandleSpec::init); + clazz.registerHybridMethod("subject", &HybridX509CertificateHandleSpec::subject); + clazz.registerHybridMethod("subjectAltName", &HybridX509CertificateHandleSpec::subjectAltName); + clazz.registerHybridMethod("issuer", &HybridX509CertificateHandleSpec::issuer); + clazz.registerHybridMethod("infoAccess", &HybridX509CertificateHandleSpec::infoAccess); + clazz.registerHybridMethod("validFrom", &HybridX509CertificateHandleSpec::validFrom); + clazz.registerHybridMethod("validTo", &HybridX509CertificateHandleSpec::validTo); + clazz.registerHybridMethod("validFromDate", &HybridX509CertificateHandleSpec::validFromDate); + clazz.registerHybridMethod("validToDate", &HybridX509CertificateHandleSpec::validToDate); + clazz.registerHybridMethod("signatureAlgorithm", &HybridX509CertificateHandleSpec::signatureAlgorithm); + clazz.registerHybridMethod("signatureAlgorithmOid", &HybridX509CertificateHandleSpec::signatureAlgorithmOid); + clazz.registerHybridMethod("serialNumber", &HybridX509CertificateHandleSpec::serialNumber); + clazz.registerHybridMethod("fingerprint", &HybridX509CertificateHandleSpec::fingerprint); + clazz.registerHybridMethod("fingerprint256", &HybridX509CertificateHandleSpec::fingerprint256); + clazz.registerHybridMethod("fingerprint512", &HybridX509CertificateHandleSpec::fingerprint512); + clazz.registerHybridMethod("raw", &HybridX509CertificateHandleSpec::raw); + clazz.registerHybridMethod("pem", &HybridX509CertificateHandleSpec::pem); + clazz.registerHybridMethod("publicKey", &HybridX509CertificateHandleSpec::publicKey); + clazz.registerHybridMethod("keyUsage", &HybridX509CertificateHandleSpec::keyUsage); + clazz.registerHybridMethod("ca", &HybridX509CertificateHandleSpec::ca); + clazz.registerHybridMethod("checkIssued", &HybridX509CertificateHandleSpec::checkIssued); + clazz.registerHybridMethod("checkPrivateKey", &HybridX509CertificateHandleSpec::checkPrivateKey); + clazz.registerHybridMethod("verify", &HybridX509CertificateHandleSpec::verify); + clazz.registerHybridMethod("checkHost", &HybridX509CertificateHandleSpec::checkHost); + clazz.registerHybridMethod("checkEmail", &HybridX509CertificateHandleSpec::checkEmail); + clazz.registerHybridMethod("checkIP", &HybridX509CertificateHandleSpec::checkIP); + clazz.registerHybridConstructor(&HybridX509CertificateHandleSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/include/QuickCrypto/private/QuickCryptoOnLoad.hpp b/packages/react-native-quick-crypto/nitrogen/generated/android/include/QuickCrypto/private/QuickCryptoOnLoad.hpp new file mode 100644 index 000000000..423457ac9 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/include/QuickCrypto/private/QuickCryptoOnLoad.hpp @@ -0,0 +1,13 @@ +/// +/// QuickCryptoOnLoad.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +namespace margelo::nitro::crypto { + // Call inside facebook::jni::initialize() from JNI_OnLoad. + void registerAllNatives(); +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/android/kotlin/com/margelo/nitro/crypto/QuickCryptoOnLoad.kt b/packages/react-native-quick-crypto/nitrogen/generated/android/kotlin/com/margelo/nitro/crypto/QuickCryptoOnLoad.kt index d4d164a48..86f87479b 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/android/kotlin/com/margelo/nitro/crypto/QuickCryptoOnLoad.kt +++ b/packages/react-native-quick-crypto/nitrogen/generated/android/kotlin/com/margelo/nitro/crypto/QuickCryptoOnLoad.kt @@ -1,35 +1,22 @@ /// /// QuickCryptoOnLoad.kt /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// package com.margelo.nitro.crypto -import android.util.Log - internal class QuickCryptoOnLoad { companion object { - private const val TAG = "QuickCryptoOnLoad" private var didLoad = false - /** - * Initializes the native part of "QuickCrypto". - * This method is idempotent and can be called more than once. - */ + @JvmStatic + @Synchronized fun initializeNative() { if (didLoad) return - try { - Log.i(TAG, "Loading QuickCrypto C++ library...") - System.loadLibrary("QuickCrypto") - Log.i(TAG, "Successfully loaded QuickCrypto C++ library!") - didLoad = true - } catch (e: Error) { - Log.e(TAG, "Failed to load QuickCrypto C++ library! Is it properly installed and linked? " + - "Is the name correct? (see `CMakeLists.txt`, at `add_library(...)`)", e) - throw e - } + System.loadLibrary("QuickCrypto") + didLoad = true } } } diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/QuickCrypto-Swift-Cxx-Bridge.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/QuickCrypto-Swift-Cxx-Bridge.cpp new file mode 100644 index 000000000..54bc5a617 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/QuickCrypto-Swift-Cxx-Bridge.cpp @@ -0,0 +1,12 @@ +/// +/// QuickCrypto-Swift-Cxx-Bridge.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// +#include + + +namespace margelo::nitro::crypto::swift_bridge { + +} // namespace margelo::nitro::crypto::swift_bridge diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/QuickCryptoAppleCxx/QuickCryptoAppleCxx.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/QuickCryptoAppleCxx/QuickCryptoAppleCxx.cpp new file mode 100644 index 000000000..764d9dc46 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/QuickCryptoAppleCxx/QuickCryptoAppleCxx.cpp @@ -0,0 +1,9 @@ +/// +/// QuickCryptoAppleCxx.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// Swift packages require at least one source file per C++ target. +#include diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/QuickCryptoAppleCxx/include/QuickCryptoAppleCxx/QuickCryptoAppleCxx.h b/packages/react-native-quick-crypto/nitrogen/generated/apple/QuickCryptoAppleCxx/include/QuickCryptoAppleCxx/QuickCryptoAppleCxx.h new file mode 100644 index 000000000..553f92703 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/QuickCryptoAppleCxx/include/QuickCryptoAppleCxx/QuickCryptoAppleCxx.h @@ -0,0 +1,14 @@ +/// +/// QuickCryptoAppleCxx.h +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + + + +namespace margelo::nitro::crypto::swift_bridge { + +} // namespace margelo::nitro::crypto::swift_bridge diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/QuickCryptoAutolinking.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/QuickCryptoAutolinking.cpp new file mode 100644 index 000000000..9a39e1a94 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/QuickCryptoAutolinking.cpp @@ -0,0 +1,78 @@ +/// +/// QuickCryptoAutolinking.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace margelo::nitro::crypto { + void registerHybridClasses() { + using namespace margelo::nitro; + using namespace margelo::nitro::crypto; + + HybridClassRegistry::registerHybridClass("crypto.Argon2", HybridArgon2Spec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Blake3", HybridBlake3Spec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Certificate", HybridCertificateSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Cipher", HybridCipherSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.CipherFactory", HybridCipherFactorySpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.DhKeyPair", HybridDhKeyPairSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.DiffieHellman", HybridDiffieHellmanSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.DsaKeyPair", HybridDsaKeyPairSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.EcKeyPair", HybridEcKeyPairSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.ECDH", HybridECDHSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.EdKeyPair", HybridEdKeyPairSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Hash", HybridHashSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Hkdf", HybridHkdfSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Hmac", HybridHmacSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.KeyObjectHandle", HybridKeyObjectHandleSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Kmac", HybridKmacSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.MlDsaKeyPair", HybridMlDsaKeyPairSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.MlKemKeyPair", HybridMlKemKeyPairSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Pbkdf2", HybridPbkdf2Spec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Prime", HybridPrimeSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Random", HybridRandomSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.RsaCipher", HybridRsaCipherSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.RsaKeyPair", HybridRsaKeyPairSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Scrypt", HybridScryptSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.SignHandle", HybridSignHandleSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.VerifyHandle", HybridVerifyHandleSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.SlhDsaKeyPair", HybridSlhDsaKeyPairSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.TurboShake", HybridTurboShakeSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.Utils", HybridUtilsSpec::Class::get()); + HybridClassRegistry::registerHybridClass("crypto.X509CertificateHandle", HybridX509CertificateHandleSpec::Class::get()); + } +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/QuickCryptoAutolinking.mm b/packages/react-native-quick-crypto/nitrogen/generated/apple/QuickCryptoAutolinking.mm new file mode 100644 index 000000000..ce858aa0d --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/QuickCryptoAutolinking.mm @@ -0,0 +1,24 @@ +/// +/// QuickCryptoAutolinking.mm +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#import +#include + +/** + * Registers all HybridObject classes of QuickCrypto + * when the app loads, so JS can look them up by name. + */ +@interface QuickCryptoAutolinking : NSObject +@end + +@implementation QuickCryptoAutolinking + ++ (void)load { + margelo::nitro::crypto::registerHybridClasses(); +} + +@end diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridArgon2SpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridArgon2SpecClass.cpp new file mode 100644 index 000000000..ac1c3aec3 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridArgon2SpecClass.cpp @@ -0,0 +1,38 @@ +/// +/// HybridArgon2SpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include "HybridArgon2.hpp" + +namespace margelo::nitro::crypto { + + namespace { + struct HybridArgon2SpecBindings final { + static Promise hash(const std::string& algorithm, const ArrayBuffer& message, const ArrayBuffer& nonce, double parallelism, double tagLength, double memory, double passes, double version, const std::optional& secret, const std::optional& associatedData) { + return ::margelo::nitro::crypto::HybridArgon2::hash(std::forward(algorithm), std::forward(message), std::forward(nonce), std::forward(parallelism), std::forward(tagLength), std::forward(memory), std::forward(passes), std::forward(version), std::forward(secret), std::forward(associatedData)); + } + + static ArrayBuffer hashSync(const std::string& algorithm, const ArrayBuffer& message, const ArrayBuffer& nonce, double parallelism, double tagLength, double memory, double passes, double version, const std::optional& secret, const std::optional& associatedData) { + return ::margelo::nitro::crypto::HybridArgon2::hashSync(std::forward(algorithm), std::forward(message), std::forward(nonce), std::forward(parallelism), std::forward(tagLength), std::forward(memory), std::forward(passes), std::forward(version), std::forward(secret), std::forward(associatedData)); + } + }; + } + + const std::shared_ptr& HybridArgon2Spec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerStaticHybridMethod("hash", &HybridArgon2SpecBindings::hash); + clazz.registerStaticHybridMethod("hashSync", &HybridArgon2SpecBindings::hashSync); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridBlake3SpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridBlake3SpecClass.cpp new file mode 100644 index 000000000..d079b8b89 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridBlake3SpecClass.cpp @@ -0,0 +1,49 @@ +/// +/// HybridBlake3SpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include "HybridBlake3.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridBlake3SpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridBlake3>, + "Blake3: ::margelo::nitro::crypto::HybridBlake3 must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridBlake3>(); + } + + static std::string getVersion() { + return ::margelo::nitro::crypto::HybridBlake3::getVersion(); + } + }; + } + + const std::shared_ptr& HybridBlake3Spec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("initHash", &HybridBlake3Spec::initHash); + clazz.registerHybridMethod("initKeyed", &HybridBlake3Spec::initKeyed); + clazz.registerHybridMethod("initDeriveKey", &HybridBlake3Spec::initDeriveKey); + clazz.registerHybridMethod("update", &HybridBlake3Spec::update); + clazz.registerHybridMethod("digest", &HybridBlake3Spec::digest); + clazz.registerHybridMethod("reset", &HybridBlake3Spec::reset); + clazz.registerHybridMethod("copy", &HybridBlake3Spec::copy); + clazz.registerHybridConstructor(&HybridBlake3SpecBindings::constructor); + clazz.registerStaticHybridMethod("getVersion", &HybridBlake3SpecBindings::getVersion); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridCertificateSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridCertificateSpecClass.cpp new file mode 100644 index 000000000..d197cc044 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridCertificateSpecClass.cpp @@ -0,0 +1,40 @@ +/// +/// HybridCertificateSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include "HybridCertificate.hpp" + +namespace margelo::nitro::crypto { + + namespace { + struct HybridCertificateSpecBindings final { + static bool verifySpkac(const ArrayBuffer& spkac) { + return ::margelo::nitro::crypto::HybridCertificate::verifySpkac(std::forward(spkac)); + } + + static ArrayBuffer exportPublicKey(const ArrayBuffer& spkac) { + return ::margelo::nitro::crypto::HybridCertificate::exportPublicKey(std::forward(spkac)); + } + + static ArrayBuffer exportChallenge(const ArrayBuffer& spkac) { + return ::margelo::nitro::crypto::HybridCertificate::exportChallenge(std::forward(spkac)); + } + }; + } + + const std::shared_ptr& HybridCertificateSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerStaticHybridMethod("verifySpkac", &HybridCertificateSpecBindings::verifySpkac); + clazz.registerStaticHybridMethod("exportPublicKey", &HybridCertificateSpecBindings::exportPublicKey); + clazz.registerStaticHybridMethod("exportChallenge", &HybridCertificateSpecBindings::exportChallenge); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridCipherFactorySpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridCipherFactorySpecClass.cpp new file mode 100644 index 000000000..7b9135886 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridCipherFactorySpecClass.cpp @@ -0,0 +1,32 @@ +/// +/// HybridCipherFactorySpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include "HybridCipherFactory.hpp" + +namespace margelo::nitro::crypto { + + namespace { + struct HybridCipherFactorySpecBindings final { + static std::shared_ptr createCipher(const CipherArgs& args) { + return ::margelo::nitro::crypto::HybridCipherFactory::createCipher(std::forward(args)); + } + }; + } + + const std::shared_ptr& HybridCipherFactorySpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerStaticHybridMethod("createCipher", &HybridCipherFactorySpecBindings::createCipher); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridCipherSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridCipherSpecClass.cpp new file mode 100644 index 000000000..187b58fa5 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridCipherSpecClass.cpp @@ -0,0 +1,47 @@ +/// +/// HybridCipherSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include +#include +#include "HybridCipher.hpp" + +namespace margelo::nitro::crypto { + + namespace { + struct HybridCipherSpecBindings final { + static std::vector getSupportedCiphers() { + return ::margelo::nitro::crypto::HybridCipher::getSupportedCiphers(); + } + + static std::optional getCipherInfo(const std::string& name, const std::optional& keyLength, const std::optional& ivLength) { + return ::margelo::nitro::crypto::HybridCipher::getCipherInfo(std::forward(name), std::forward(keyLength), std::forward(ivLength)); + } + }; + } + + const std::shared_ptr& HybridCipherSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("update", &HybridCipherSpec::update); + clazz.registerHybridMethod("final", &HybridCipherSpec::final); + clazz.registerHybridMethod("setArgs", &HybridCipherSpec::setArgs); + clazz.registerHybridMethod("setAAD", &HybridCipherSpec::setAAD); + clazz.registerHybridMethod("setAutoPadding", &HybridCipherSpec::setAutoPadding); + clazz.registerHybridMethod("setAuthTag", &HybridCipherSpec::setAuthTag); + clazz.registerHybridMethod("getAuthTag", &HybridCipherSpec::getAuthTag); + clazz.registerStaticHybridMethod("getSupportedCiphers", &HybridCipherSpecBindings::getSupportedCiphers); + clazz.registerStaticHybridMethod("getCipherInfo", &HybridCipherSpecBindings::getCipherInfo); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridDhKeyPairSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridDhKeyPairSpecClass.cpp new file mode 100644 index 000000000..bd9f641b6 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridDhKeyPairSpecClass.cpp @@ -0,0 +1,42 @@ +/// +/// HybridDhKeyPairSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include "HybridDhKeyPair.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridDhKeyPairSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridDhKeyPair>, + "DhKeyPair: ::margelo::nitro::crypto::HybridDhKeyPair must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridDhKeyPair>(); + } + }; + } + + const std::shared_ptr& HybridDhKeyPairSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("generateKeyPair", &HybridDhKeyPairSpec::generateKeyPair); + clazz.registerHybridMethod("generateKeyPairSync", &HybridDhKeyPairSpec::generateKeyPairSync); + clazz.registerHybridMethod("setPrimeLength", &HybridDhKeyPairSpec::setPrimeLength); + clazz.registerHybridMethod("setPrime", &HybridDhKeyPairSpec::setPrime); + clazz.registerHybridMethod("setGenerator", &HybridDhKeyPairSpec::setGenerator); + clazz.registerHybridMethod("getPublicKey", &HybridDhKeyPairSpec::getPublicKey); + clazz.registerHybridMethod("getPrivateKey", &HybridDhKeyPairSpec::getPrivateKey); + clazz.registerHybridConstructor(&HybridDhKeyPairSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridDiffieHellmanSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridDiffieHellmanSpecClass.cpp new file mode 100644 index 000000000..7ee9fe0f5 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridDiffieHellmanSpecClass.cpp @@ -0,0 +1,45 @@ +/// +/// HybridDiffieHellmanSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include "HybridDiffieHellman.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridDiffieHellmanSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridDiffieHellman>, + "DiffieHellman: ::margelo::nitro::crypto::HybridDiffieHellman must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridDiffieHellman>(); + } + }; + } + + const std::shared_ptr& HybridDiffieHellmanSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("init", &HybridDiffieHellmanSpec::init); + clazz.registerHybridMethod("initWithSize", &HybridDiffieHellmanSpec::initWithSize); + clazz.registerHybridMethod("generateKeys", &HybridDiffieHellmanSpec::generateKeys); + clazz.registerHybridMethod("computeSecret", &HybridDiffieHellmanSpec::computeSecret); + clazz.registerHybridMethod("getPrime", &HybridDiffieHellmanSpec::getPrime); + clazz.registerHybridMethod("getGenerator", &HybridDiffieHellmanSpec::getGenerator); + clazz.registerHybridMethod("getPublicKey", &HybridDiffieHellmanSpec::getPublicKey); + clazz.registerHybridMethod("getPrivateKey", &HybridDiffieHellmanSpec::getPrivateKey); + clazz.registerHybridMethod("setPublicKey", &HybridDiffieHellmanSpec::setPublicKey); + clazz.registerHybridMethod("setPrivateKey", &HybridDiffieHellmanSpec::setPrivateKey); + clazz.registerHybridMethod("getVerifyError", &HybridDiffieHellmanSpec::getVerifyError); + clazz.registerHybridConstructor(&HybridDiffieHellmanSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridDsaKeyPairSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridDsaKeyPairSpecClass.cpp new file mode 100644 index 000000000..da777f6c4 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridDsaKeyPairSpecClass.cpp @@ -0,0 +1,41 @@ +/// +/// HybridDsaKeyPairSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include "HybridDsaKeyPair.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridDsaKeyPairSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridDsaKeyPair>, + "DsaKeyPair: ::margelo::nitro::crypto::HybridDsaKeyPair must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridDsaKeyPair>(); + } + }; + } + + const std::shared_ptr& HybridDsaKeyPairSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("generateKeyPair", &HybridDsaKeyPairSpec::generateKeyPair); + clazz.registerHybridMethod("generateKeyPairSync", &HybridDsaKeyPairSpec::generateKeyPairSync); + clazz.registerHybridMethod("setModulusLength", &HybridDsaKeyPairSpec::setModulusLength); + clazz.registerHybridMethod("setDivisorLength", &HybridDsaKeyPairSpec::setDivisorLength); + clazz.registerHybridMethod("getPublicKey", &HybridDsaKeyPairSpec::getPublicKey); + clazz.registerHybridMethod("getPrivateKey", &HybridDsaKeyPairSpec::getPrivateKey); + clazz.registerHybridConstructor(&HybridDsaKeyPairSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridECDHSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridECDHSpecClass.cpp new file mode 100644 index 000000000..0544f8b83 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridECDHSpecClass.cpp @@ -0,0 +1,47 @@ +/// +/// HybridECDHSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include "HybridECDH.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridECDHSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridECDH>, + "ECDH: ::margelo::nitro::crypto::HybridECDH must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridECDH>(); + } + + static ArrayBuffer convertKey(const ArrayBuffer& key, const std::string& curve, double format) { + return ::margelo::nitro::crypto::HybridECDH::convertKey(std::forward(key), std::forward(curve), std::forward(format)); + } + }; + } + + const std::shared_ptr& HybridECDHSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("init", &HybridECDHSpec::init); + clazz.registerHybridMethod("generateKeys", &HybridECDHSpec::generateKeys); + clazz.registerHybridMethod("computeSecret", &HybridECDHSpec::computeSecret); + clazz.registerHybridMethod("getPrivateKey", &HybridECDHSpec::getPrivateKey); + clazz.registerHybridMethod("setPrivateKey", &HybridECDHSpec::setPrivateKey); + clazz.registerHybridMethod("getPublicKey", &HybridECDHSpec::getPublicKey); + clazz.registerHybridMethod("setPublicKey", &HybridECDHSpec::setPublicKey); + clazz.registerHybridConstructor(&HybridECDHSpecBindings::constructor); + clazz.registerStaticHybridMethod("convertKey", &HybridECDHSpecBindings::convertKey); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridEcKeyPairSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridEcKeyPairSpecClass.cpp new file mode 100644 index 000000000..406d50d34 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridEcKeyPairSpecClass.cpp @@ -0,0 +1,52 @@ +/// +/// HybridEcKeyPairSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include +#include "HybridEcKeyPair.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridEcKeyPairSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridEcKeyPair>, + "EcKeyPair: ::margelo::nitro::crypto::HybridEcKeyPair must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridEcKeyPair>(); + } + + static std::vector getSupportedCurves() { + return ::margelo::nitro::crypto::HybridEcKeyPair::getSupportedCurves(); + } + }; + } + + const std::shared_ptr& HybridEcKeyPairSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("generateKeyPair", &HybridEcKeyPairSpec::generateKeyPair); + clazz.registerHybridMethod("generateKeyPairSync", &HybridEcKeyPairSpec::generateKeyPairSync); + clazz.registerHybridMethod("importKey", &HybridEcKeyPairSpec::importKey); + clazz.registerHybridMethod("exportKey", &HybridEcKeyPairSpec::exportKey); + clazz.registerHybridMethod("getPublicKey", &HybridEcKeyPairSpec::getPublicKey); + clazz.registerHybridMethod("getPrivateKey", &HybridEcKeyPairSpec::getPrivateKey); + clazz.registerHybridMethod("setCurve", &HybridEcKeyPairSpec::setCurve); + clazz.registerHybridMethod("sign", &HybridEcKeyPairSpec::sign); + clazz.registerHybridMethod("verify", &HybridEcKeyPairSpec::verify); + clazz.registerHybridConstructor(&HybridEcKeyPairSpecBindings::constructor); + clazz.registerStaticHybridMethod("getSupportedCurves", &HybridEcKeyPairSpecBindings::getSupportedCurves); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridEdKeyPairSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridEdKeyPairSpecClass.cpp new file mode 100644 index 000000000..10b8c93d7 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridEdKeyPairSpecClass.cpp @@ -0,0 +1,47 @@ +/// +/// HybridEdKeyPairSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include "HybridEdKeyPair.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridEdKeyPairSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridEdKeyPair>, + "EdKeyPair: ::margelo::nitro::crypto::HybridEdKeyPair must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridEdKeyPair>(); + } + }; + } + + const std::shared_ptr& HybridEdKeyPairSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("diffieHellman", &HybridEdKeyPairSpec::diffieHellman); + clazz.registerHybridMethod("generateKeyPair", &HybridEdKeyPairSpec::generateKeyPair); + clazz.registerHybridMethod("generateKeyPairSync", &HybridEdKeyPairSpec::generateKeyPairSync); + clazz.registerHybridMethod("getPublicKey", &HybridEdKeyPairSpec::getPublicKey); + clazz.registerHybridMethod("getPrivateKey", &HybridEdKeyPairSpec::getPrivateKey); + clazz.registerHybridMethod("sign", &HybridEdKeyPairSpec::sign); + clazz.registerHybridMethod("signSync", &HybridEdKeyPairSpec::signSync); + clazz.registerHybridMethod("verify", &HybridEdKeyPairSpec::verify); + clazz.registerHybridMethod("verifySync", &HybridEdKeyPairSpec::verifySync); + clazz.registerHybridMethod("setCurve", &HybridEdKeyPairSpec::setCurve); + clazz.registerHybridConstructor(&HybridEdKeyPairSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridHashSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridHashSpecClass.cpp new file mode 100644 index 000000000..743aa8ffc --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridHashSpecClass.cpp @@ -0,0 +1,53 @@ +/// +/// HybridHashSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include +#include +#include "HybridHash.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridHashSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridHash>, + "Hash: ::margelo::nitro::crypto::HybridHash must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridHash>(); + } + + static std::vector getSupportedHashAlgorithms() { + return ::margelo::nitro::crypto::HybridHash::getSupportedHashAlgorithms(); + } + + static std::string getOpenSSLVersion() { + return ::margelo::nitro::crypto::HybridHash::getOpenSSLVersion(); + } + }; + } + + const std::shared_ptr& HybridHashSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("createHash", &HybridHashSpec::createHash); + clazz.registerHybridMethod("update", &HybridHashSpec::update); + clazz.registerHybridMethod("digest", &HybridHashSpec::digest); + clazz.registerHybridMethod("copy", &HybridHashSpec::copy); + clazz.registerHybridConstructor(&HybridHashSpecBindings::constructor); + clazz.registerStaticHybridMethod("getSupportedHashAlgorithms", &HybridHashSpecBindings::getSupportedHashAlgorithms); + clazz.registerStaticHybridMethod("getOpenSSLVersion", &HybridHashSpecBindings::getOpenSSLVersion); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridHkdfSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridHkdfSpecClass.cpp new file mode 100644 index 000000000..d98866b17 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridHkdfSpecClass.cpp @@ -0,0 +1,38 @@ +/// +/// HybridHkdfSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include "HybridHkdf.hpp" + +namespace margelo::nitro::crypto { + + namespace { + struct HybridHkdfSpecBindings final { + static ArrayBuffer deriveKeySync(const std::string& algorithm, const ArrayBuffer& key, const ArrayBuffer& salt, const ArrayBuffer& info, double length, HkdfMode mode) { + return ::margelo::nitro::crypto::HybridHkdf::deriveKeySync(std::forward(algorithm), std::forward(key), std::forward(salt), std::forward(info), std::forward(length), std::forward(mode)); + } + + static Promise deriveKey(const std::string& algorithm, const ArrayBuffer& key, const ArrayBuffer& salt, const ArrayBuffer& info, double length, HkdfMode mode) { + return ::margelo::nitro::crypto::HybridHkdf::deriveKey(std::forward(algorithm), std::forward(key), std::forward(salt), std::forward(info), std::forward(length), std::forward(mode)); + } + }; + } + + const std::shared_ptr& HybridHkdfSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerStaticHybridMethod("deriveKeySync", &HybridHkdfSpecBindings::deriveKeySync); + clazz.registerStaticHybridMethod("deriveKey", &HybridHkdfSpecBindings::deriveKey); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridHmacSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridHmacSpecClass.cpp new file mode 100644 index 000000000..3113915ef --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridHmacSpecClass.cpp @@ -0,0 +1,39 @@ +/// +/// HybridHmacSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include "HybridHmac.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridHmacSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridHmac>, + "Hmac: ::margelo::nitro::crypto::HybridHmac must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridHmac>(); + } + }; + } + + const std::shared_ptr& HybridHmacSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("createHmac", &HybridHmacSpec::createHmac); + clazz.registerHybridMethod("update", &HybridHmacSpec::update); + clazz.registerHybridMethod("digest", &HybridHmacSpec::digest); + clazz.registerHybridConstructor(&HybridHmacSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridKeyObjectHandleSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridKeyObjectHandleSpecClass.cpp new file mode 100644 index 000000000..017848c7e --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridKeyObjectHandleSpecClass.cpp @@ -0,0 +1,64 @@ +/// +/// HybridKeyObjectHandleSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "HybridKeyObjectHandle.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridKeyObjectHandleSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridKeyObjectHandle>, + "KeyObjectHandle: ::margelo::nitro::crypto::HybridKeyObjectHandle must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridKeyObjectHandle>(); + } + }; + } + + const std::shared_ptr& HybridKeyObjectHandleSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("exportKey", &HybridKeyObjectHandleSpec::exportKey); + clazz.registerHybridMethod("exportJwk", &HybridKeyObjectHandleSpec::exportJwk); + clazz.registerHybridMethod("exportRawPublic", &HybridKeyObjectHandleSpec::exportRawPublic); + clazz.registerHybridMethod("exportRawPrivate", &HybridKeyObjectHandleSpec::exportRawPrivate); + clazz.registerHybridMethod("exportRawSeed", &HybridKeyObjectHandleSpec::exportRawSeed); + clazz.registerHybridMethod("exportECPublicRaw", &HybridKeyObjectHandleSpec::exportECPublicRaw); + clazz.registerHybridMethod("exportECPrivateRaw", &HybridKeyObjectHandleSpec::exportECPrivateRaw); + clazz.registerHybridMethod("getAsymmetricKeyType", &HybridKeyObjectHandleSpec::getAsymmetricKeyType); + clazz.registerHybridMethod("init", &HybridKeyObjectHandleSpec::init); + clazz.registerHybridMethod("initECRaw", &HybridKeyObjectHandleSpec::initECRaw); + clazz.registerHybridMethod("initPqcRaw", &HybridKeyObjectHandleSpec::initPqcRaw); + clazz.registerHybridMethod("initRawPublic", &HybridKeyObjectHandleSpec::initRawPublic); + clazz.registerHybridMethod("initRawPrivate", &HybridKeyObjectHandleSpec::initRawPrivate); + clazz.registerHybridMethod("initRawSeed", &HybridKeyObjectHandleSpec::initRawSeed); + clazz.registerHybridMethod("initJwk", &HybridKeyObjectHandleSpec::initJwk); + clazz.registerHybridMethod("keyDetail", &HybridKeyObjectHandleSpec::keyDetail); + clazz.registerHybridMethod("keyEquals", &HybridKeyObjectHandleSpec::keyEquals); + clazz.registerHybridMethod("getSymmetricKeySize", &HybridKeyObjectHandleSpec::getSymmetricKeySize); + clazz.registerHybridMethod("checkEcKeyData", &HybridKeyObjectHandleSpec::checkEcKeyData); + clazz.registerHybridConstructor(&HybridKeyObjectHandleSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridKmacSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridKmacSpecClass.cpp new file mode 100644 index 000000000..dc089a14e --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridKmacSpecClass.cpp @@ -0,0 +1,39 @@ +/// +/// HybridKmacSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include "HybridKmac.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridKmacSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridKmac>, + "Kmac: ::margelo::nitro::crypto::HybridKmac must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridKmac>(); + } + }; + } + + const std::shared_ptr& HybridKmacSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("createKmac", &HybridKmacSpec::createKmac); + clazz.registerHybridMethod("update", &HybridKmacSpec::update); + clazz.registerHybridMethod("digest", &HybridKmacSpec::digest); + clazz.registerHybridConstructor(&HybridKmacSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridMlDsaKeyPairSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridMlDsaKeyPairSpecClass.cpp new file mode 100644 index 000000000..c1b7f0381 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridMlDsaKeyPairSpecClass.cpp @@ -0,0 +1,45 @@ +/// +/// HybridMlDsaKeyPairSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include "HybridMlDsaKeyPair.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridMlDsaKeyPairSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridMlDsaKeyPair>, + "MlDsaKeyPair: ::margelo::nitro::crypto::HybridMlDsaKeyPair must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridMlDsaKeyPair>(); + } + }; + } + + const std::shared_ptr& HybridMlDsaKeyPairSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("generateKeyPair", &HybridMlDsaKeyPairSpec::generateKeyPair); + clazz.registerHybridMethod("generateKeyPairSync", &HybridMlDsaKeyPairSpec::generateKeyPairSync); + clazz.registerHybridMethod("getPublicKey", &HybridMlDsaKeyPairSpec::getPublicKey); + clazz.registerHybridMethod("getPrivateKey", &HybridMlDsaKeyPairSpec::getPrivateKey); + clazz.registerHybridMethod("sign", &HybridMlDsaKeyPairSpec::sign); + clazz.registerHybridMethod("signSync", &HybridMlDsaKeyPairSpec::signSync); + clazz.registerHybridMethod("verify", &HybridMlDsaKeyPairSpec::verify); + clazz.registerHybridMethod("verifySync", &HybridMlDsaKeyPairSpec::verifySync); + clazz.registerHybridMethod("setVariant", &HybridMlDsaKeyPairSpec::setVariant); + clazz.registerHybridConstructor(&HybridMlDsaKeyPairSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridMlKemKeyPairSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridMlKemKeyPairSpecClass.cpp new file mode 100644 index 000000000..779ce242d --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridMlKemKeyPairSpecClass.cpp @@ -0,0 +1,47 @@ +/// +/// HybridMlKemKeyPairSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include "HybridMlKemKeyPair.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridMlKemKeyPairSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridMlKemKeyPair>, + "MlKemKeyPair: ::margelo::nitro::crypto::HybridMlKemKeyPair must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridMlKemKeyPair>(); + } + }; + } + + const std::shared_ptr& HybridMlKemKeyPairSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("setVariant", &HybridMlKemKeyPairSpec::setVariant); + clazz.registerHybridMethod("generateKeyPair", &HybridMlKemKeyPairSpec::generateKeyPair); + clazz.registerHybridMethod("generateKeyPairSync", &HybridMlKemKeyPairSpec::generateKeyPairSync); + clazz.registerHybridMethod("getPublicKey", &HybridMlKemKeyPairSpec::getPublicKey); + clazz.registerHybridMethod("getPrivateKey", &HybridMlKemKeyPairSpec::getPrivateKey); + clazz.registerHybridMethod("setPublicKey", &HybridMlKemKeyPairSpec::setPublicKey); + clazz.registerHybridMethod("setPrivateKey", &HybridMlKemKeyPairSpec::setPrivateKey); + clazz.registerHybridMethod("encapsulate", &HybridMlKemKeyPairSpec::encapsulate); + clazz.registerHybridMethod("encapsulateSync", &HybridMlKemKeyPairSpec::encapsulateSync); + clazz.registerHybridMethod("decapsulate", &HybridMlKemKeyPairSpec::decapsulate); + clazz.registerHybridMethod("decapsulateSync", &HybridMlKemKeyPairSpec::decapsulateSync); + clazz.registerHybridConstructor(&HybridMlKemKeyPairSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridPbkdf2SpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridPbkdf2SpecClass.cpp new file mode 100644 index 000000000..144d03cc0 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridPbkdf2SpecClass.cpp @@ -0,0 +1,37 @@ +/// +/// HybridPbkdf2SpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include "HybridPbkdf2.hpp" + +namespace margelo::nitro::crypto { + + namespace { + struct HybridPbkdf2SpecBindings final { + static Promise pbkdf2(const ArrayBuffer& password, const ArrayBuffer& salt, double iterations, double keylen, const std::string& digest) { + return ::margelo::nitro::crypto::HybridPbkdf2::pbkdf2(std::forward(password), std::forward(salt), std::forward(iterations), std::forward(keylen), std::forward(digest)); + } + + static ArrayBuffer pbkdf2Sync(const ArrayBuffer& password, const ArrayBuffer& salt, double iterations, double keylen, const std::string& digest) { + return ::margelo::nitro::crypto::HybridPbkdf2::pbkdf2Sync(std::forward(password), std::forward(salt), std::forward(iterations), std::forward(keylen), std::forward(digest)); + } + }; + } + + const std::shared_ptr& HybridPbkdf2Spec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerStaticHybridMethod("pbkdf2", &HybridPbkdf2SpecBindings::pbkdf2); + clazz.registerStaticHybridMethod("pbkdf2Sync", &HybridPbkdf2SpecBindings::pbkdf2Sync); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridPrimeSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridPrimeSpecClass.cpp new file mode 100644 index 000000000..c9f334dae --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridPrimeSpecClass.cpp @@ -0,0 +1,47 @@ +/// +/// HybridPrimeSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include "HybridPrime.hpp" + +namespace margelo::nitro::crypto { + + namespace { + struct HybridPrimeSpecBindings final { + static Promise generatePrime(double size, bool safe, const std::optional& add, const std::optional& rem) { + return ::margelo::nitro::crypto::HybridPrime::generatePrime(std::forward(size), std::forward(safe), std::forward(add), std::forward(rem)); + } + + static ArrayBuffer generatePrimeSync(double size, bool safe, const std::optional& add, const std::optional& rem) { + return ::margelo::nitro::crypto::HybridPrime::generatePrimeSync(std::forward(size), std::forward(safe), std::forward(add), std::forward(rem)); + } + + static Promise checkPrime(const ArrayBuffer& candidate, double checks) { + return ::margelo::nitro::crypto::HybridPrime::checkPrime(std::forward(candidate), std::forward(checks)); + } + + static bool checkPrimeSync(const ArrayBuffer& candidate, double checks) { + return ::margelo::nitro::crypto::HybridPrime::checkPrimeSync(std::forward(candidate), std::forward(checks)); + } + }; + } + + const std::shared_ptr& HybridPrimeSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerStaticHybridMethod("generatePrime", &HybridPrimeSpecBindings::generatePrime); + clazz.registerStaticHybridMethod("generatePrimeSync", &HybridPrimeSpecBindings::generatePrimeSync); + clazz.registerStaticHybridMethod("checkPrime", &HybridPrimeSpecBindings::checkPrime); + clazz.registerStaticHybridMethod("checkPrimeSync", &HybridPrimeSpecBindings::checkPrimeSync); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridRandomSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridRandomSpecClass.cpp new file mode 100644 index 000000000..603d211d9 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridRandomSpecClass.cpp @@ -0,0 +1,36 @@ +/// +/// HybridRandomSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include "HybridRandom.hpp" + +namespace margelo::nitro::crypto { + + namespace { + struct HybridRandomSpecBindings final { + static Promise randomFill(const ArrayBuffer& buffer, double offset, double size) { + return ::margelo::nitro::crypto::HybridRandom::randomFill(std::forward(buffer), std::forward(offset), std::forward(size)); + } + + static ArrayBuffer randomFillSync(const ArrayBuffer& buffer, double offset, double size) { + return ::margelo::nitro::crypto::HybridRandom::randomFillSync(std::forward(buffer), std::forward(offset), std::forward(size)); + } + }; + } + + const std::shared_ptr& HybridRandomSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerStaticHybridMethod("randomFill", &HybridRandomSpecBindings::randomFill); + clazz.registerStaticHybridMethod("randomFillSync", &HybridRandomSpecBindings::randomFillSync); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridRsaCipherSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridRsaCipherSpecClass.cpp new file mode 100644 index 000000000..3a6873e30 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridRsaCipherSpecClass.cpp @@ -0,0 +1,54 @@ +/// +/// HybridRsaCipherSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include +#include "HybridRsaCipher.hpp" + +namespace margelo::nitro::crypto { + + namespace { + struct HybridRsaCipherSpecBindings final { + static ArrayBuffer encrypt(const std::shared_ptr& keyHandle, const ArrayBuffer& data, double padding, const std::string& hashAlgorithm, const std::optional& label) { + return ::margelo::nitro::crypto::HybridRsaCipher::encrypt(std::forward(keyHandle), std::forward(data), std::forward(padding), std::forward(hashAlgorithm), std::forward(label)); + } + + static ArrayBuffer decrypt(const std::shared_ptr& keyHandle, const ArrayBuffer& data, double padding, const std::string& hashAlgorithm, const std::optional& label) { + return ::margelo::nitro::crypto::HybridRsaCipher::decrypt(std::forward(keyHandle), std::forward(data), std::forward(padding), std::forward(hashAlgorithm), std::forward(label)); + } + + static ArrayBuffer publicDecrypt(const std::shared_ptr& keyHandle, const ArrayBuffer& data, double padding) { + return ::margelo::nitro::crypto::HybridRsaCipher::publicDecrypt(std::forward(keyHandle), std::forward(data), std::forward(padding)); + } + + static ArrayBuffer privateEncrypt(const std::shared_ptr& keyHandle, const ArrayBuffer& data, double padding) { + return ::margelo::nitro::crypto::HybridRsaCipher::privateEncrypt(std::forward(keyHandle), std::forward(data), std::forward(padding)); + } + + static ArrayBuffer privateDecrypt(const std::shared_ptr& keyHandle, const ArrayBuffer& data, double padding, const std::string& hashAlgorithm, const std::optional& label) { + return ::margelo::nitro::crypto::HybridRsaCipher::privateDecrypt(std::forward(keyHandle), std::forward(data), std::forward(padding), std::forward(hashAlgorithm), std::forward(label)); + } + }; + } + + const std::shared_ptr& HybridRsaCipherSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerStaticHybridMethod("encrypt", &HybridRsaCipherSpecBindings::encrypt); + clazz.registerStaticHybridMethod("decrypt", &HybridRsaCipherSpecBindings::decrypt); + clazz.registerStaticHybridMethod("publicDecrypt", &HybridRsaCipherSpecBindings::publicDecrypt); + clazz.registerStaticHybridMethod("privateEncrypt", &HybridRsaCipherSpecBindings::privateEncrypt); + clazz.registerStaticHybridMethod("privateDecrypt", &HybridRsaCipherSpecBindings::privateDecrypt); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridRsaKeyPairSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridRsaKeyPairSpecClass.cpp new file mode 100644 index 000000000..f19df8f9b --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridRsaKeyPairSpecClass.cpp @@ -0,0 +1,47 @@ +/// +/// HybridRsaKeyPairSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include +#include "HybridRsaKeyPair.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridRsaKeyPairSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridRsaKeyPair>, + "RsaKeyPair: ::margelo::nitro::crypto::HybridRsaKeyPair must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridRsaKeyPair>(); + } + }; + } + + const std::shared_ptr& HybridRsaKeyPairSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("generateKeyPair", &HybridRsaKeyPairSpec::generateKeyPair); + clazz.registerHybridMethod("generateKeyPairSync", &HybridRsaKeyPairSpec::generateKeyPairSync); + clazz.registerHybridMethod("setModulusLength", &HybridRsaKeyPairSpec::setModulusLength); + clazz.registerHybridMethod("setPublicExponent", &HybridRsaKeyPairSpec::setPublicExponent); + clazz.registerHybridMethod("setHashAlgorithm", &HybridRsaKeyPairSpec::setHashAlgorithm); + clazz.registerHybridMethod("importKey", &HybridRsaKeyPairSpec::importKey); + clazz.registerHybridMethod("exportKey", &HybridRsaKeyPairSpec::exportKey); + clazz.registerHybridMethod("getPublicKey", &HybridRsaKeyPairSpec::getPublicKey); + clazz.registerHybridMethod("getPrivateKey", &HybridRsaKeyPairSpec::getPrivateKey); + clazz.registerHybridConstructor(&HybridRsaKeyPairSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridScryptSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridScryptSpecClass.cpp new file mode 100644 index 000000000..5ac17d9ab --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridScryptSpecClass.cpp @@ -0,0 +1,36 @@ +/// +/// HybridScryptSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include "HybridScrypt.hpp" + +namespace margelo::nitro::crypto { + + namespace { + struct HybridScryptSpecBindings final { + static Promise deriveKey(const ArrayBuffer& password, const ArrayBuffer& salt, double N, double r, double p, double maxmem, double keylen) { + return ::margelo::nitro::crypto::HybridScrypt::deriveKey(std::forward(password), std::forward(salt), std::forward(N), std::forward(r), std::forward(p), std::forward(maxmem), std::forward(keylen)); + } + + static ArrayBuffer deriveKeySync(const ArrayBuffer& password, const ArrayBuffer& salt, double N, double r, double p, double maxmem, double keylen) { + return ::margelo::nitro::crypto::HybridScrypt::deriveKeySync(std::forward(password), std::forward(salt), std::forward(N), std::forward(r), std::forward(p), std::forward(maxmem), std::forward(keylen)); + } + }; + } + + const std::shared_ptr& HybridScryptSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerStaticHybridMethod("deriveKey", &HybridScryptSpecBindings::deriveKey); + clazz.registerStaticHybridMethod("deriveKeySync", &HybridScryptSpecBindings::deriveKeySync); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridSignHandleSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridSignHandleSpecClass.cpp new file mode 100644 index 000000000..22aa1dd2d --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridSignHandleSpecClass.cpp @@ -0,0 +1,41 @@ +/// +/// HybridSignHandleSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include +#include "HybridSignHandle.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridSignHandleSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridSignHandle>, + "SignHandle: ::margelo::nitro::crypto::HybridSignHandle must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridSignHandle>(); + } + }; + } + + const std::shared_ptr& HybridSignHandleSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("init", &HybridSignHandleSpec::init); + clazz.registerHybridMethod("update", &HybridSignHandleSpec::update); + clazz.registerHybridMethod("sign", &HybridSignHandleSpec::sign); + clazz.registerHybridConstructor(&HybridSignHandleSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridSlhDsaKeyPairSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridSlhDsaKeyPairSpecClass.cpp new file mode 100644 index 000000000..216cbd4aa --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridSlhDsaKeyPairSpecClass.cpp @@ -0,0 +1,45 @@ +/// +/// HybridSlhDsaKeyPairSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include "HybridSlhDsaKeyPair.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridSlhDsaKeyPairSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridSlhDsaKeyPair>, + "SlhDsaKeyPair: ::margelo::nitro::crypto::HybridSlhDsaKeyPair must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridSlhDsaKeyPair>(); + } + }; + } + + const std::shared_ptr& HybridSlhDsaKeyPairSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("generateKeyPair", &HybridSlhDsaKeyPairSpec::generateKeyPair); + clazz.registerHybridMethod("generateKeyPairSync", &HybridSlhDsaKeyPairSpec::generateKeyPairSync); + clazz.registerHybridMethod("getPublicKey", &HybridSlhDsaKeyPairSpec::getPublicKey); + clazz.registerHybridMethod("getPrivateKey", &HybridSlhDsaKeyPairSpec::getPrivateKey); + clazz.registerHybridMethod("sign", &HybridSlhDsaKeyPairSpec::sign); + clazz.registerHybridMethod("signSync", &HybridSlhDsaKeyPairSpec::signSync); + clazz.registerHybridMethod("verify", &HybridSlhDsaKeyPairSpec::verify); + clazz.registerHybridMethod("verifySync", &HybridSlhDsaKeyPairSpec::verifySync); + clazz.registerHybridMethod("setVariant", &HybridSlhDsaKeyPairSpec::setVariant); + clazz.registerHybridConstructor(&HybridSlhDsaKeyPairSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridTurboShakeSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridTurboShakeSpecClass.cpp new file mode 100644 index 000000000..9ff813ab7 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridTurboShakeSpecClass.cpp @@ -0,0 +1,39 @@ +/// +/// HybridTurboShakeSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include +#include "HybridTurboShake.hpp" + +namespace margelo::nitro::crypto { + + namespace { + struct HybridTurboShakeSpecBindings final { + static Promise turboShake(TurboShakeVariant variant, double domainSeparation, double outputLength, const ArrayBuffer& data) { + return ::margelo::nitro::crypto::HybridTurboShake::turboShake(std::forward(variant), std::forward(domainSeparation), std::forward(outputLength), std::forward(data)); + } + + static Promise kangarooTwelve(KangarooTwelveVariant variant, double outputLength, const ArrayBuffer& data, const std::optional& customization) { + return ::margelo::nitro::crypto::HybridTurboShake::kangarooTwelve(std::forward(variant), std::forward(outputLength), std::forward(data), std::forward(customization)); + } + }; + } + + const std::shared_ptr& HybridTurboShakeSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerStaticHybridMethod("turboShake", &HybridTurboShakeSpecBindings::turboShake); + clazz.registerStaticHybridMethod("kangarooTwelve", &HybridTurboShakeSpecBindings::kangarooTwelve); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridUtilsSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridUtilsSpecClass.cpp new file mode 100644 index 000000000..ce4afb651 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridUtilsSpecClass.cpp @@ -0,0 +1,39 @@ +/// +/// HybridUtilsSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include "HybridUtils.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridUtilsSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridUtils>, + "Utils: ::margelo::nitro::crypto::HybridUtils must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridUtils>(); + } + + static bool timingSafeEqual(const ArrayBuffer& a, const ArrayBuffer& b) { + return ::margelo::nitro::crypto::HybridUtils::timingSafeEqual(std::forward(a), std::forward(b)); + } + }; + } + + const std::shared_ptr& HybridUtilsSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridConstructor(&HybridUtilsSpecBindings::constructor); + clazz.registerStaticHybridMethod("timingSafeEqual", &HybridUtilsSpecBindings::timingSafeEqual); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridVerifyHandleSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridVerifyHandleSpecClass.cpp new file mode 100644 index 000000000..aca5c65b4 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridVerifyHandleSpecClass.cpp @@ -0,0 +1,41 @@ +/// +/// HybridVerifyHandleSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include +#include "HybridVerifyHandle.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridVerifyHandleSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridVerifyHandle>, + "VerifyHandle: ::margelo::nitro::crypto::HybridVerifyHandle must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridVerifyHandle>(); + } + }; + } + + const std::shared_ptr& HybridVerifyHandleSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("init", &HybridVerifyHandleSpec::init); + clazz.registerHybridMethod("update", &HybridVerifyHandleSpec::update); + clazz.registerHybridMethod("verify", &HybridVerifyHandleSpec::verify); + clazz.registerHybridConstructor(&HybridVerifyHandleSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridX509CertificateHandleSpecClass.cpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridX509CertificateHandleSpecClass.cpp new file mode 100644 index 000000000..be9a58260 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/HybridX509CertificateHandleSpecClass.cpp @@ -0,0 +1,65 @@ +/// +/// HybridX509CertificateHandleSpecClass.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include +#include +#include "HybridX509Certificate.hpp" +#include +#include + +namespace margelo::nitro::crypto { + + namespace { + struct HybridX509CertificateHandleSpecBindings final { + static std::shared_ptr constructor() { + static_assert(std::is_constructible_v<::margelo::nitro::crypto::HybridX509Certificate>, + "X509CertificateHandle: ::margelo::nitro::crypto::HybridX509Certificate must implement the declared public constructor."); + return std::make_shared<::margelo::nitro::crypto::HybridX509Certificate>(); + } + }; + } + + const std::shared_ptr& HybridX509CertificateHandleSpec::Class::get() { + static const auto hybridClass = HybridClass::create([](HybridClass& clazz) { + clazz.registerHybridMethod("init", &HybridX509CertificateHandleSpec::init); + clazz.registerHybridMethod("subject", &HybridX509CertificateHandleSpec::subject); + clazz.registerHybridMethod("subjectAltName", &HybridX509CertificateHandleSpec::subjectAltName); + clazz.registerHybridMethod("issuer", &HybridX509CertificateHandleSpec::issuer); + clazz.registerHybridMethod("infoAccess", &HybridX509CertificateHandleSpec::infoAccess); + clazz.registerHybridMethod("validFrom", &HybridX509CertificateHandleSpec::validFrom); + clazz.registerHybridMethod("validTo", &HybridX509CertificateHandleSpec::validTo); + clazz.registerHybridMethod("validFromDate", &HybridX509CertificateHandleSpec::validFromDate); + clazz.registerHybridMethod("validToDate", &HybridX509CertificateHandleSpec::validToDate); + clazz.registerHybridMethod("signatureAlgorithm", &HybridX509CertificateHandleSpec::signatureAlgorithm); + clazz.registerHybridMethod("signatureAlgorithmOid", &HybridX509CertificateHandleSpec::signatureAlgorithmOid); + clazz.registerHybridMethod("serialNumber", &HybridX509CertificateHandleSpec::serialNumber); + clazz.registerHybridMethod("fingerprint", &HybridX509CertificateHandleSpec::fingerprint); + clazz.registerHybridMethod("fingerprint256", &HybridX509CertificateHandleSpec::fingerprint256); + clazz.registerHybridMethod("fingerprint512", &HybridX509CertificateHandleSpec::fingerprint512); + clazz.registerHybridMethod("raw", &HybridX509CertificateHandleSpec::raw); + clazz.registerHybridMethod("pem", &HybridX509CertificateHandleSpec::pem); + clazz.registerHybridMethod("publicKey", &HybridX509CertificateHandleSpec::publicKey); + clazz.registerHybridMethod("keyUsage", &HybridX509CertificateHandleSpec::keyUsage); + clazz.registerHybridMethod("ca", &HybridX509CertificateHandleSpec::ca); + clazz.registerHybridMethod("checkIssued", &HybridX509CertificateHandleSpec::checkIssued); + clazz.registerHybridMethod("checkPrivateKey", &HybridX509CertificateHandleSpec::checkPrivateKey); + clazz.registerHybridMethod("verify", &HybridX509CertificateHandleSpec::verify); + clazz.registerHybridMethod("checkHost", &HybridX509CertificateHandleSpec::checkHost); + clazz.registerHybridMethod("checkEmail", &HybridX509CertificateHandleSpec::checkEmail); + clazz.registerHybridMethod("checkIP", &HybridX509CertificateHandleSpec::checkIP); + clazz.registerHybridConstructor(&HybridX509CertificateHandleSpecBindings::constructor); + }); + return hybridClass; + } + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/include/QuickCrypto/QuickCryptoAutolinking.hpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/include/QuickCrypto/QuickCryptoAutolinking.hpp new file mode 100644 index 000000000..9e462dc10 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/include/QuickCrypto/QuickCryptoAutolinking.hpp @@ -0,0 +1,13 @@ +/// +/// QuickCryptoAutolinking.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +namespace margelo::nitro::crypto { + // Register all generated HybridObject classes + void registerHybridClasses(); +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/include/QuickCrypto/private/QuickCrypto-Swift-Cxx-Umbrella.hpp similarity index 64% rename from packages/react-native-quick-crypto/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp rename to packages/react-native-quick-crypto/nitrogen/generated/apple/c++/include/QuickCrypto/private/QuickCrypto-Swift-Cxx-Umbrella.hpp index c8e16f4ff..59a9ac586 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Umbrella.hpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/include/QuickCrypto/private/QuickCrypto-Swift-Cxx-Umbrella.hpp @@ -1,31 +1,20 @@ /// /// QuickCrypto-Swift-Cxx-Umbrella.hpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// #pragma once -// Forward declarations of C++ defined types - - -// Include C++ defined types - +// Private C++ implementation includes. Never import this umbrella from Swift. +// Include Swift defined types. They define swift::Optional and swift::Array, +// which the C++ helpers below only forward-declare for Swift's importer. +#include // C++ helpers for Swift -#include "QuickCrypto-Swift-Cxx-Bridge.hpp" - -// Common C++ types used in Swift -#include -#include -#include -#include - -// Forward declarations of Swift defined types - +#include -// Include Swift defined types #if __has_include("QuickCrypto-Swift.h") // This header is generated by Xcode/Swift on every app build. // If it cannot be found, make sure the Swift module's name (= podspec name) is actually "QuickCrypto". diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/include/module.modulemap b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/include/module.modulemap new file mode 100644 index 000000000..eff7ea578 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/c++/include/module.modulemap @@ -0,0 +1,12 @@ +/// +/// module.modulemap +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// Headers used by Swift belong to the AppleCxx module. +// This implementation target must not claim them through an umbrella directory. +module QuickCryptoSwiftBridge { + requires cplusplus +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/apple/swift/QuickCryptoModule.swift b/packages/react-native-quick-crypto/nitrogen/generated/apple/swift/QuickCryptoModule.swift new file mode 100644 index 000000000..30ebff883 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/apple/swift/QuickCryptoModule.swift @@ -0,0 +1,2 @@ +// Generated by nitrogen. Keeps the SwiftPM module available to its C++ bridge. +internal import NitroModules diff --git a/packages/react-native-quick-crypto/nitrogen/generated/hybrid-classes.json b/packages/react-native-quick-crypto/nitrogen/generated/hybrid-classes.json new file mode 100644 index 000000000..d40367028 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/hybrid-classes.json @@ -0,0 +1,485 @@ +{ + "version": 2, + "classes": { + "Argon2": { + "android": { + "implementation": { + "className": "HybridArgon2", + "include": "\"HybridArgon2.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridArgon2", + "include": "\"HybridArgon2.hpp\"" + }, + "language": "c++" + } + }, + "Blake3": { + "android": { + "implementation": { + "className": "HybridBlake3", + "include": "\"HybridBlake3.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridBlake3", + "include": "\"HybridBlake3.hpp\"" + }, + "language": "c++" + } + }, + "Certificate": { + "android": { + "implementation": { + "className": "HybridCertificate", + "include": "\"HybridCertificate.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridCertificate", + "include": "\"HybridCertificate.hpp\"" + }, + "language": "c++" + } + }, + "Cipher": { + "android": { + "implementation": { + "className": "HybridCipher", + "include": "\"HybridCipher.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridCipher", + "include": "\"HybridCipher.hpp\"" + }, + "language": "c++" + } + }, + "CipherFactory": { + "android": { + "implementation": { + "className": "HybridCipherFactory", + "include": "\"HybridCipherFactory.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridCipherFactory", + "include": "\"HybridCipherFactory.hpp\"" + }, + "language": "c++" + } + }, + "DhKeyPair": { + "android": { + "implementation": { + "className": "HybridDhKeyPair", + "include": "\"HybridDhKeyPair.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridDhKeyPair", + "include": "\"HybridDhKeyPair.hpp\"" + }, + "language": "c++" + } + }, + "DiffieHellman": { + "android": { + "implementation": { + "className": "HybridDiffieHellman", + "include": "\"HybridDiffieHellman.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridDiffieHellman", + "include": "\"HybridDiffieHellman.hpp\"" + }, + "language": "c++" + } + }, + "DsaKeyPair": { + "android": { + "implementation": { + "className": "HybridDsaKeyPair", + "include": "\"HybridDsaKeyPair.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridDsaKeyPair", + "include": "\"HybridDsaKeyPair.hpp\"" + }, + "language": "c++" + } + }, + "ECDH": { + "android": { + "implementation": { + "className": "HybridECDH", + "include": "\"HybridECDH.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridECDH", + "include": "\"HybridECDH.hpp\"" + }, + "language": "c++" + } + }, + "EcKeyPair": { + "android": { + "implementation": { + "className": "HybridEcKeyPair", + "include": "\"HybridEcKeyPair.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridEcKeyPair", + "include": "\"HybridEcKeyPair.hpp\"" + }, + "language": "c++" + } + }, + "EdKeyPair": { + "android": { + "implementation": { + "className": "HybridEdKeyPair", + "include": "\"HybridEdKeyPair.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridEdKeyPair", + "include": "\"HybridEdKeyPair.hpp\"" + }, + "language": "c++" + } + }, + "Hash": { + "android": { + "implementation": { + "className": "HybridHash", + "include": "\"HybridHash.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridHash", + "include": "\"HybridHash.hpp\"" + }, + "language": "c++" + } + }, + "Hkdf": { + "android": { + "implementation": { + "className": "HybridHkdf", + "include": "\"HybridHkdf.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridHkdf", + "include": "\"HybridHkdf.hpp\"" + }, + "language": "c++" + } + }, + "Hmac": { + "android": { + "implementation": { + "className": "HybridHmac", + "include": "\"HybridHmac.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridHmac", + "include": "\"HybridHmac.hpp\"" + }, + "language": "c++" + } + }, + "KeyObjectHandle": { + "android": { + "implementation": { + "className": "HybridKeyObjectHandle", + "include": "\"HybridKeyObjectHandle.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridKeyObjectHandle", + "include": "\"HybridKeyObjectHandle.hpp\"" + }, + "language": "c++" + } + }, + "Kmac": { + "android": { + "implementation": { + "className": "HybridKmac", + "include": "\"HybridKmac.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridKmac", + "include": "\"HybridKmac.hpp\"" + }, + "language": "c++" + } + }, + "MlDsaKeyPair": { + "android": { + "implementation": { + "className": "HybridMlDsaKeyPair", + "include": "\"HybridMlDsaKeyPair.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridMlDsaKeyPair", + "include": "\"HybridMlDsaKeyPair.hpp\"" + }, + "language": "c++" + } + }, + "MlKemKeyPair": { + "android": { + "implementation": { + "className": "HybridMlKemKeyPair", + "include": "\"HybridMlKemKeyPair.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridMlKemKeyPair", + "include": "\"HybridMlKemKeyPair.hpp\"" + }, + "language": "c++" + } + }, + "Pbkdf2": { + "android": { + "implementation": { + "className": "HybridPbkdf2", + "include": "\"HybridPbkdf2.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridPbkdf2", + "include": "\"HybridPbkdf2.hpp\"" + }, + "language": "c++" + } + }, + "Prime": { + "android": { + "implementation": { + "className": "HybridPrime", + "include": "\"HybridPrime.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridPrime", + "include": "\"HybridPrime.hpp\"" + }, + "language": "c++" + } + }, + "Random": { + "android": { + "implementation": { + "className": "HybridRandom", + "include": "\"HybridRandom.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridRandom", + "include": "\"HybridRandom.hpp\"" + }, + "language": "c++" + } + }, + "RsaCipher": { + "android": { + "implementation": { + "className": "HybridRsaCipher", + "include": "\"HybridRsaCipher.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridRsaCipher", + "include": "\"HybridRsaCipher.hpp\"" + }, + "language": "c++" + } + }, + "RsaKeyPair": { + "android": { + "implementation": { + "className": "HybridRsaKeyPair", + "include": "\"HybridRsaKeyPair.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridRsaKeyPair", + "include": "\"HybridRsaKeyPair.hpp\"" + }, + "language": "c++" + } + }, + "Scrypt": { + "android": { + "implementation": { + "className": "HybridScrypt", + "include": "\"HybridScrypt.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridScrypt", + "include": "\"HybridScrypt.hpp\"" + }, + "language": "c++" + } + }, + "SignHandle": { + "android": { + "implementation": { + "className": "HybridSignHandle", + "include": "\"HybridSignHandle.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridSignHandle", + "include": "\"HybridSignHandle.hpp\"" + }, + "language": "c++" + } + }, + "SlhDsaKeyPair": { + "android": { + "implementation": { + "className": "HybridSlhDsaKeyPair", + "include": "\"HybridSlhDsaKeyPair.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridSlhDsaKeyPair", + "include": "\"HybridSlhDsaKeyPair.hpp\"" + }, + "language": "c++" + } + }, + "TurboShake": { + "android": { + "implementation": { + "className": "HybridTurboShake", + "include": "\"HybridTurboShake.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridTurboShake", + "include": "\"HybridTurboShake.hpp\"" + }, + "language": "c++" + } + }, + "Utils": { + "android": { + "implementation": { + "className": "HybridUtils", + "include": "\"HybridUtils.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridUtils", + "include": "\"HybridUtils.hpp\"" + }, + "language": "c++" + } + }, + "VerifyHandle": { + "android": { + "implementation": { + "className": "HybridVerifyHandle", + "include": "\"HybridVerifyHandle.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridVerifyHandle", + "include": "\"HybridVerifyHandle.hpp\"" + }, + "language": "c++" + } + }, + "X509CertificateHandle": { + "android": { + "implementation": { + "className": "HybridX509Certificate", + "include": "\"HybridX509Certificate.hpp\"" + }, + "language": "c++" + }, + "apple": { + "implementation": { + "className": "HybridX509Certificate", + "include": "\"HybridX509Certificate.hpp\"" + }, + "language": "c++" + } + } + } +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/ios/QuickCrypto+autolinking.rb b/packages/react-native-quick-crypto/nitrogen/generated/ios/QuickCrypto+autolinking.rb deleted file mode 100644 index dece5ea57..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/ios/QuickCrypto+autolinking.rb +++ /dev/null @@ -1,60 +0,0 @@ -# -# QuickCrypto+autolinking.rb -# This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -# https://github.com/mrousavy/nitro -# Copyright © Marc Rousavy @ Margelo -# - -# This is a Ruby script that adds all files generated by Nitrogen -# to the given podspec. -# -# To use it, add this to your .podspec: -# ```ruby -# Pod::Spec.new do |spec| -# # ... -# -# # Add all files generated by Nitrogen -# load 'nitrogen/generated/ios/QuickCrypto+autolinking.rb' -# add_nitrogen_files(spec) -# end -# ``` - -def add_nitrogen_files(spec) - Pod::UI.puts "[NitroModules] 🔥 QuickCrypto is boosted by nitro!" - - spec.dependency "NitroModules" - - current_source_files = Array(spec.attributes_hash['source_files']) - spec.source_files = current_source_files + [ - # Generated cross-platform specs - "nitrogen/generated/shared/**/*.{h,hpp,c,cpp,swift}", - # Generated bridges for the cross-platform specs - "nitrogen/generated/ios/**/*.{h,hpp,c,cpp,mm,swift}", - ] - - current_public_header_files = Array(spec.attributes_hash['public_header_files']) - spec.public_header_files = current_public_header_files + [ - # Generated specs - "nitrogen/generated/shared/**/*.{h,hpp}", - # Swift to C++ bridging helpers - "nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp" - ] - - current_private_header_files = Array(spec.attributes_hash['private_header_files']) - spec.private_header_files = current_private_header_files + [ - # iOS specific specs - "nitrogen/generated/ios/c++/**/*.{h,hpp}", - # Views are framework-specific and should be private - "nitrogen/generated/shared/**/views/**/*" - ] - - current_pod_target_xcconfig = spec.attributes_hash['pod_target_xcconfig'] || {} - spec.pod_target_xcconfig = current_pod_target_xcconfig.merge({ - # Use C++ 20 - "CLANG_CXX_LANGUAGE_STANDARD" => "c++20", - # Enables C++ <-> Swift interop (by default it's only ObjC) - "SWIFT_OBJC_INTEROP_MODE" => "objcxx", - # Enables stricter modular headers - "DEFINES_MODULE" => "YES", - }) -end diff --git a/packages/react-native-quick-crypto/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp b/packages/react-native-quick-crypto/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp deleted file mode 100644 index adde9e531..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.cpp +++ /dev/null @@ -1,17 +0,0 @@ -/// -/// QuickCrypto-Swift-Cxx-Bridge.cpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#include "QuickCrypto-Swift-Cxx-Bridge.hpp" - -// Include C++ implementation defined types - - -namespace margelo::nitro::crypto::bridge::swift { - - - -} // namespace margelo::nitro::crypto::bridge::swift diff --git a/packages/react-native-quick-crypto/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp b/packages/react-native-quick-crypto/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp deleted file mode 100644 index ce14819b8..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/ios/QuickCrypto-Swift-Cxx-Bridge.hpp +++ /dev/null @@ -1,27 +0,0 @@ -/// -/// QuickCrypto-Swift-Cxx-Bridge.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -// Forward declarations of C++ defined types - - -// Forward declarations of Swift defined types - - -// Include C++ defined types - - -/** - * Contains specialized versions of C++ templated types so they can be accessed from Swift, - * as well as helper functions to interact with those C++ types from Swift. - */ -namespace margelo::nitro::crypto::bridge::swift { - - - -} // namespace margelo::nitro::crypto::bridge::swift diff --git a/packages/react-native-quick-crypto/nitrogen/generated/ios/QuickCryptoAutolinking.mm b/packages/react-native-quick-crypto/nitrogen/generated/ios/QuickCryptoAutolinking.mm deleted file mode 100644 index f38afc9e4..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/ios/QuickCryptoAutolinking.mm +++ /dev/null @@ -1,325 +0,0 @@ -/// -/// QuickCryptoAutolinking.mm -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#import -#import - -#import - -#include "HybridArgon2.hpp" -#include "HybridBlake3.hpp" -#include "HybridCertificate.hpp" -#include "HybridCipher.hpp" -#include "HybridCipherFactory.hpp" -#include "HybridDhKeyPair.hpp" -#include "HybridDiffieHellman.hpp" -#include "HybridDsaKeyPair.hpp" -#include "HybridECDH.hpp" -#include "HybridEcKeyPair.hpp" -#include "HybridEdKeyPair.hpp" -#include "HybridHash.hpp" -#include "HybridHkdf.hpp" -#include "HybridHmac.hpp" -#include "HybridKmac.hpp" -#include "HybridKeyObjectHandle.hpp" -#include "HybridMlDsaKeyPair.hpp" -#include "HybridMlKemKeyPair.hpp" -#include "HybridSlhDsaKeyPair.hpp" -#include "HybridPbkdf2.hpp" -#include "HybridPrime.hpp" -#include "HybridRandom.hpp" -#include "HybridRsaCipher.hpp" -#include "HybridRsaKeyPair.hpp" -#include "HybridScrypt.hpp" -#include "HybridSignHandle.hpp" -#include "HybridTurboShake.hpp" -#include "HybridUtils.hpp" -#include "HybridVerifyHandle.hpp" -#include "HybridX509Certificate.hpp" - -@interface QuickCryptoAutolinking : NSObject -@end - -@implementation QuickCryptoAutolinking - -+ (void) load { - using namespace margelo::nitro; - using namespace margelo::nitro::crypto; - - HybridObjectRegistry::registerHybridObjectConstructor( - "Argon2", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridArgon2\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Blake3", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridBlake3\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Certificate", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridCertificate\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Cipher", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridCipher\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "CipherFactory", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridCipherFactory\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "DhKeyPair", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridDhKeyPair\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "DiffieHellman", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridDiffieHellman\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "DsaKeyPair", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridDsaKeyPair\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "ECDH", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridECDH\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "EcKeyPair", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridEcKeyPair\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "EdKeyPair", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridEdKeyPair\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Hash", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridHash\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Hkdf", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridHkdf\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Hmac", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridHmac\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Kmac", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridKmac\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "KeyObjectHandle", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridKeyObjectHandle\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "MlDsaKeyPair", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridMlDsaKeyPair\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "MlKemKeyPair", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridMlKemKeyPair\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "SlhDsaKeyPair", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridSlhDsaKeyPair\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Pbkdf2", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridPbkdf2\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Prime", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridPrime\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Random", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridRandom\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "RsaCipher", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridRsaCipher\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "RsaKeyPair", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridRsaKeyPair\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Scrypt", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridScrypt\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "SignHandle", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridSignHandle\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "TurboShake", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridTurboShake\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "Utils", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridUtils\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "VerifyHandle", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridVerifyHandle\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); - HybridObjectRegistry::registerHybridObjectConstructor( - "X509CertificateHandle", - []() -> std::shared_ptr { - static_assert(std::is_default_constructible_v, - "The HybridObject \"HybridX509Certificate\" is not default-constructible! " - "Create a public constructor that takes zero arguments to be able to autolink this HybridObject."); - return std::make_shared(); - } - ); -} - -@end diff --git a/packages/react-native-quick-crypto/nitrogen/generated/ios/QuickCryptoAutolinking.swift b/packages/react-native-quick-crypto/nitrogen/generated/ios/QuickCryptoAutolinking.swift deleted file mode 100644 index 226adcf62..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/ios/QuickCryptoAutolinking.swift +++ /dev/null @@ -1,16 +0,0 @@ -/// -/// QuickCryptoAutolinking.swift -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -import NitroModules - -// TODO: Use empty enums once Swift supports exporting them as namespaces -// See: https://github.com/swiftlang/swift/pull/83616 -public final class QuickCryptoAutolinking { - public typealias bridge = margelo.nitro.crypto.bridge.swift - - -} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/CipherArgs.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/CipherArgs.cpp new file mode 100644 index 000000000..95de65252 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/CipherArgs.cpp @@ -0,0 +1,54 @@ +/// +/// CipherArgs.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include + +namespace margelo::nitro { + + margelo::nitro::crypto::CipherArgs JSIConverter::fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { + jsi::Object obj = arg.asObject(runtime); + return margelo::nitro::crypto::CipherArgs( + JSIConverter::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "isCipher"))), + JSIConverter::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "cipherType"))), + JSIConverter::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "cipherKey"))), + JSIConverter::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "iv"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "authTagLen"))) + ); + } + + jsi::Value JSIConverter::toJSI(jsi::Runtime& runtime, const margelo::nitro::crypto::CipherArgs& arg) { + jsi::Object obj(runtime); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "isCipher"), JSIConverter::toJSI(runtime, arg.isCipher)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "cipherType"), JSIConverter::toJSI(runtime, arg.cipherType)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "cipherKey"), JSIConverter::toJSI(runtime, arg.cipherKey)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "iv"), JSIConverter::toJSI(runtime, arg.iv)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "authTagLen"), JSIConverter>::toJSI(runtime, arg.authTagLen)); + return obj; + } + + bool JSIConverter::canConvert(jsi::Runtime& runtime, const jsi::Value& value) { + if (!value.isObject()) { + return false; + } + jsi::Object obj = value.getObject(runtime); + if (!nitro::isPlainObject(runtime, obj)) { + return false; + } + if (!JSIConverter::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "isCipher")))) return false; + if (!JSIConverter::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "cipherType")))) return false; + if (!JSIConverter::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "cipherKey")))) return false; + if (!JSIConverter::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "iv")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "authTagLen")))) return false; + return true; + } + +} // namespace margelo::nitro diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/CipherArgs.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/CipherArgs.hpp deleted file mode 100644 index 232e0363d..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/CipherArgs.hpp +++ /dev/null @@ -1,101 +0,0 @@ -/// -/// CipherArgs.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - - - -#include -#include -#include - -namespace margelo::nitro::crypto { - - /** - * A struct which can be represented as a JavaScript object (CipherArgs). - */ - struct CipherArgs final { - public: - bool isCipher SWIFT_PRIVATE; - std::string cipherType SWIFT_PRIVATE; - std::shared_ptr cipherKey SWIFT_PRIVATE; - std::shared_ptr iv SWIFT_PRIVATE; - std::optional authTagLen SWIFT_PRIVATE; - - public: - CipherArgs() = default; - explicit CipherArgs(bool isCipher, std::string cipherType, std::shared_ptr cipherKey, std::shared_ptr iv, std::optional authTagLen): isCipher(isCipher), cipherType(cipherType), cipherKey(cipherKey), iv(iv), authTagLen(authTagLen) {} - - public: - friend bool operator==(const CipherArgs& lhs, const CipherArgs& rhs) = default; - }; - -} // namespace margelo::nitro::crypto - -namespace margelo::nitro { - - // C++ CipherArgs <> JS CipherArgs (object) - template <> - struct JSIConverter final { - static inline margelo::nitro::crypto::CipherArgs fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { - jsi::Object obj = arg.asObject(runtime); - return margelo::nitro::crypto::CipherArgs( - JSIConverter::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "isCipher"))), - JSIConverter::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "cipherType"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "cipherKey"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "iv"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "authTagLen"))) - ); - } - static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::crypto::CipherArgs& arg) { - jsi::Object obj(runtime); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "isCipher"), JSIConverter::toJSI(runtime, arg.isCipher)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "cipherType"), JSIConverter::toJSI(runtime, arg.cipherType)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "cipherKey"), JSIConverter>::toJSI(runtime, arg.cipherKey)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "iv"), JSIConverter>::toJSI(runtime, arg.iv)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "authTagLen"), JSIConverter>::toJSI(runtime, arg.authTagLen)); - return obj; - } - static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) { - if (!value.isObject()) { - return false; - } - jsi::Object obj = value.getObject(runtime); - if (!nitro::isPlainObject(runtime, obj)) { - return false; - } - if (!JSIConverter::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "isCipher")))) return false; - if (!JSIConverter::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "cipherType")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "cipherKey")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "iv")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "authTagLen")))) return false; - return true; - } - }; - -} // namespace margelo::nitro diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/CipherInfo.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/CipherInfo.cpp new file mode 100644 index 000000000..2ec3fd25a --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/CipherInfo.cpp @@ -0,0 +1,56 @@ +/// +/// CipherInfo.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include + +namespace margelo::nitro { + + margelo::nitro::crypto::CipherInfo JSIConverter::fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { + jsi::Object obj = arg.asObject(runtime); + return margelo::nitro::crypto::CipherInfo( + JSIConverter::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "name"))), + JSIConverter::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "nid"))), + JSIConverter::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mode"))), + JSIConverter::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "keyLength"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "blockSize"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ivLength"))) + ); + } + + jsi::Value JSIConverter::toJSI(jsi::Runtime& runtime, const margelo::nitro::crypto::CipherInfo& arg) { + jsi::Object obj(runtime); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "name"), JSIConverter::toJSI(runtime, arg.name)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "nid"), JSIConverter::toJSI(runtime, arg.nid)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "mode"), JSIConverter::toJSI(runtime, arg.mode)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "keyLength"), JSIConverter::toJSI(runtime, arg.keyLength)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "blockSize"), JSIConverter>::toJSI(runtime, arg.blockSize)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "ivLength"), JSIConverter>::toJSI(runtime, arg.ivLength)); + return obj; + } + + bool JSIConverter::canConvert(jsi::Runtime& runtime, const jsi::Value& value) { + if (!value.isObject()) { + return false; + } + jsi::Object obj = value.getObject(runtime); + if (!nitro::isPlainObject(runtime, obj)) { + return false; + } + if (!JSIConverter::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "name")))) return false; + if (!JSIConverter::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "nid")))) return false; + if (!JSIConverter::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mode")))) return false; + if (!JSIConverter::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "keyLength")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "blockSize")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ivLength")))) return false; + return true; + } + +} // namespace margelo::nitro diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/CipherInfo.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/CipherInfo.hpp deleted file mode 100644 index 36c3b84f2..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/CipherInfo.hpp +++ /dev/null @@ -1,104 +0,0 @@ -/// -/// CipherInfo.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - - - -#include -#include - -namespace margelo::nitro::crypto { - - /** - * A struct which can be represented as a JavaScript object (CipherInfo). - */ - struct CipherInfo final { - public: - std::string name SWIFT_PRIVATE; - double nid SWIFT_PRIVATE; - std::string mode SWIFT_PRIVATE; - double keyLength SWIFT_PRIVATE; - std::optional blockSize SWIFT_PRIVATE; - std::optional ivLength SWIFT_PRIVATE; - - public: - CipherInfo() = default; - explicit CipherInfo(std::string name, double nid, std::string mode, double keyLength, std::optional blockSize, std::optional ivLength): name(name), nid(nid), mode(mode), keyLength(keyLength), blockSize(blockSize), ivLength(ivLength) {} - - public: - friend bool operator==(const CipherInfo& lhs, const CipherInfo& rhs) = default; - }; - -} // namespace margelo::nitro::crypto - -namespace margelo::nitro { - - // C++ CipherInfo <> JS CipherInfo (object) - template <> - struct JSIConverter final { - static inline margelo::nitro::crypto::CipherInfo fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { - jsi::Object obj = arg.asObject(runtime); - return margelo::nitro::crypto::CipherInfo( - JSIConverter::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "name"))), - JSIConverter::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "nid"))), - JSIConverter::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mode"))), - JSIConverter::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "keyLength"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "blockSize"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ivLength"))) - ); - } - static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::crypto::CipherInfo& arg) { - jsi::Object obj(runtime); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "name"), JSIConverter::toJSI(runtime, arg.name)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "nid"), JSIConverter::toJSI(runtime, arg.nid)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "mode"), JSIConverter::toJSI(runtime, arg.mode)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "keyLength"), JSIConverter::toJSI(runtime, arg.keyLength)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "blockSize"), JSIConverter>::toJSI(runtime, arg.blockSize)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "ivLength"), JSIConverter>::toJSI(runtime, arg.ivLength)); - return obj; - } - static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) { - if (!value.isObject()) { - return false; - } - jsi::Object obj = value.getObject(runtime); - if (!nitro::isPlainObject(runtime, obj)) { - return false; - } - if (!JSIConverter::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "name")))) return false; - if (!JSIConverter::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "nid")))) return false; - if (!JSIConverter::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mode")))) return false; - if (!JSIConverter::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "keyLength")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "blockSize")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ivLength")))) return false; - return true; - } - }; - -} // namespace margelo::nitro diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridArgon2Spec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridArgon2Spec.cpp index 851ec0da4..59eedab78 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridArgon2Spec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridArgon2Spec.cpp @@ -1,22 +1,14 @@ /// /// HybridArgon2Spec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridArgon2Spec.hpp" +#include namespace margelo::nitro::crypto { - void HybridArgon2Spec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("hash", &HybridArgon2Spec::hash); - prototype.registerHybridMethod("hashSync", &HybridArgon2Spec::hashSync); - }); - } + HybridArgon2Spec::~HybridArgon2Spec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridArgon2Spec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridArgon2Spec.hpp deleted file mode 100644 index e521d90ca..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridArgon2Spec.hpp +++ /dev/null @@ -1,66 +0,0 @@ -/// -/// HybridArgon2Spec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - - - -#include -#include -#include -#include - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `Argon2` - * Inherit this class to create instances of `HybridArgon2Spec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridArgon2: public HybridArgon2Spec { - * public: - * HybridArgon2(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridArgon2Spec: public virtual HybridObject { - public: - // Constructor - explicit HybridArgon2Spec(): HybridObject(TAG) { } - - // Destructor - ~HybridArgon2Spec() override = default; - - public: - // Properties - - - public: - // Methods - virtual std::shared_ptr>> hash(const std::string& algorithm, const std::shared_ptr& message, const std::shared_ptr& nonce, double parallelism, double tagLength, double memory, double passes, double version, const std::optional>& secret, const std::optional>& associatedData) = 0; - virtual std::shared_ptr hashSync(const std::string& algorithm, const std::shared_ptr& message, const std::shared_ptr& nonce, double parallelism, double tagLength, double memory, double passes, double version, const std::optional>& secret, const std::optional>& associatedData) = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "Argon2"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridBlake3Spec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridBlake3Spec.cpp index 076881af5..91b7d5455 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridBlake3Spec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridBlake3Spec.cpp @@ -1,28 +1,14 @@ /// /// HybridBlake3Spec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridBlake3Spec.hpp" +#include namespace margelo::nitro::crypto { - void HybridBlake3Spec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("initHash", &HybridBlake3Spec::initHash); - prototype.registerHybridMethod("initKeyed", &HybridBlake3Spec::initKeyed); - prototype.registerHybridMethod("initDeriveKey", &HybridBlake3Spec::initDeriveKey); - prototype.registerHybridMethod("update", &HybridBlake3Spec::update); - prototype.registerHybridMethod("digest", &HybridBlake3Spec::digest); - prototype.registerHybridMethod("reset", &HybridBlake3Spec::reset); - prototype.registerHybridMethod("copy", &HybridBlake3Spec::copy); - prototype.registerHybridMethod("getVersion", &HybridBlake3Spec::getVersion); - }); - } + HybridBlake3Spec::~HybridBlake3Spec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridCertificateSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridCertificateSpec.cpp index 82c6ef67d..f6afc4719 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridCertificateSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridCertificateSpec.cpp @@ -1,23 +1,14 @@ /// /// HybridCertificateSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridCertificateSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridCertificateSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("verifySpkac", &HybridCertificateSpec::verifySpkac); - prototype.registerHybridMethod("exportPublicKey", &HybridCertificateSpec::exportPublicKey); - prototype.registerHybridMethod("exportChallenge", &HybridCertificateSpec::exportChallenge); - }); - } + HybridCertificateSpec::~HybridCertificateSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridCertificateSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridCertificateSpec.hpp deleted file mode 100644 index 1057d80ca..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridCertificateSpec.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/// -/// HybridCertificateSpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - - - -#include - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `Certificate` - * Inherit this class to create instances of `HybridCertificateSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridCertificate: public HybridCertificateSpec { - * public: - * HybridCertificate(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridCertificateSpec: public virtual HybridObject { - public: - // Constructor - explicit HybridCertificateSpec(): HybridObject(TAG) { } - - // Destructor - ~HybridCertificateSpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual bool verifySpkac(const std::shared_ptr& spkac) = 0; - virtual std::shared_ptr exportPublicKey(const std::shared_ptr& spkac) = 0; - virtual std::shared_ptr exportChallenge(const std::shared_ptr& spkac) = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "Certificate"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridCipherFactorySpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridCipherFactorySpec.cpp index cd945cf4e..7203c32f6 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridCipherFactorySpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridCipherFactorySpec.cpp @@ -1,21 +1,14 @@ /// /// HybridCipherFactorySpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridCipherFactorySpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridCipherFactorySpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("createCipher", &HybridCipherFactorySpec::createCipher); - }); - } + HybridCipherFactorySpec::~HybridCipherFactorySpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridCipherFactorySpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridCipherFactorySpec.hpp deleted file mode 100644 index 1af6d714b..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridCipherFactorySpec.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/// -/// HybridCipherFactorySpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - -// Forward declaration of `HybridCipherSpec` to properly resolve imports. -namespace margelo::nitro::crypto { class HybridCipherSpec; } -// Forward declaration of `CipherArgs` to properly resolve imports. -namespace margelo::nitro::crypto { struct CipherArgs; } - -#include -#include "HybridCipherSpec.hpp" -#include "CipherArgs.hpp" - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `CipherFactory` - * Inherit this class to create instances of `HybridCipherFactorySpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridCipherFactory: public HybridCipherFactorySpec { - * public: - * HybridCipherFactory(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridCipherFactorySpec: public virtual HybridObject { - public: - // Constructor - explicit HybridCipherFactorySpec(): HybridObject(TAG) { } - - // Destructor - ~HybridCipherFactorySpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual std::shared_ptr createCipher(const CipherArgs& args) = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "CipherFactory"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridCipherSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridCipherSpec.cpp index 552b0fd4b..1e7e6f4d3 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridCipherSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridCipherSpec.cpp @@ -1,29 +1,14 @@ /// /// HybridCipherSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridCipherSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridCipherSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("update", &HybridCipherSpec::update); - prototype.registerHybridMethod("final", &HybridCipherSpec::final); - prototype.registerHybridMethod("setArgs", &HybridCipherSpec::setArgs); - prototype.registerHybridMethod("setAAD", &HybridCipherSpec::setAAD); - prototype.registerHybridMethod("setAutoPadding", &HybridCipherSpec::setAutoPadding); - prototype.registerHybridMethod("setAuthTag", &HybridCipherSpec::setAuthTag); - prototype.registerHybridMethod("getAuthTag", &HybridCipherSpec::getAuthTag); - prototype.registerHybridMethod("getSupportedCiphers", &HybridCipherSpec::getSupportedCiphers); - prototype.registerHybridMethod("getCipherInfo", &HybridCipherSpec::getCipherInfo); - }); - } + HybridCipherSpec::~HybridCipherSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridCipherSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridCipherSpec.hpp deleted file mode 100644 index 45736ad38..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridCipherSpec.hpp +++ /dev/null @@ -1,78 +0,0 @@ -/// -/// HybridCipherSpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - -// Forward declaration of `CipherArgs` to properly resolve imports. -namespace margelo::nitro::crypto { struct CipherArgs; } -// Forward declaration of `CipherInfo` to properly resolve imports. -namespace margelo::nitro::crypto { struct CipherInfo; } - -#include -#include "CipherArgs.hpp" -#include -#include -#include -#include "CipherInfo.hpp" - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `Cipher` - * Inherit this class to create instances of `HybridCipherSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridCipher: public HybridCipherSpec { - * public: - * HybridCipher(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridCipherSpec: public virtual HybridObject { - public: - // Constructor - explicit HybridCipherSpec(): HybridObject(TAG) { } - - // Destructor - ~HybridCipherSpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual std::shared_ptr update(const std::shared_ptr& data) = 0; - virtual std::shared_ptr final() = 0; - virtual void setArgs(const CipherArgs& args) = 0; - virtual bool setAAD(const std::shared_ptr& data, std::optional plaintextLength) = 0; - virtual bool setAutoPadding(bool autoPad) = 0; - virtual bool setAuthTag(const std::shared_ptr& tag) = 0; - virtual std::shared_ptr getAuthTag() = 0; - virtual std::vector getSupportedCiphers() = 0; - virtual std::optional getCipherInfo(const std::string& name, std::optional keyLength, std::optional ivLength) = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "Cipher"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridDhKeyPairSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridDhKeyPairSpec.cpp index 196fcb2d8..d6f128dea 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridDhKeyPairSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridDhKeyPairSpec.cpp @@ -1,27 +1,14 @@ /// /// HybridDhKeyPairSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridDhKeyPairSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridDhKeyPairSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("generateKeyPair", &HybridDhKeyPairSpec::generateKeyPair); - prototype.registerHybridMethod("generateKeyPairSync", &HybridDhKeyPairSpec::generateKeyPairSync); - prototype.registerHybridMethod("setPrimeLength", &HybridDhKeyPairSpec::setPrimeLength); - prototype.registerHybridMethod("setPrime", &HybridDhKeyPairSpec::setPrime); - prototype.registerHybridMethod("setGenerator", &HybridDhKeyPairSpec::setGenerator); - prototype.registerHybridMethod("getPublicKey", &HybridDhKeyPairSpec::getPublicKey); - prototype.registerHybridMethod("getPrivateKey", &HybridDhKeyPairSpec::getPrivateKey); - }); - } + HybridDhKeyPairSpec::~HybridDhKeyPairSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridDhKeyPairSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridDhKeyPairSpec.hpp deleted file mode 100644 index 85421c042..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridDhKeyPairSpec.hpp +++ /dev/null @@ -1,69 +0,0 @@ -/// -/// HybridDhKeyPairSpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - - - -#include -#include - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `DhKeyPair` - * Inherit this class to create instances of `HybridDhKeyPairSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridDhKeyPair: public HybridDhKeyPairSpec { - * public: - * HybridDhKeyPair(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridDhKeyPairSpec: public virtual HybridObject { - public: - // Constructor - explicit HybridDhKeyPairSpec(): HybridObject(TAG) { } - - // Destructor - ~HybridDhKeyPairSpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual std::shared_ptr> generateKeyPair() = 0; - virtual void generateKeyPairSync() = 0; - virtual void setPrimeLength(double primeLength) = 0; - virtual void setPrime(const std::shared_ptr& prime) = 0; - virtual void setGenerator(double generator) = 0; - virtual std::shared_ptr getPublicKey() = 0; - virtual std::shared_ptr getPrivateKey() = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "DhKeyPair"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridDiffieHellmanSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridDiffieHellmanSpec.cpp index 57c1b1f63..b99c2dd8b 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridDiffieHellmanSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridDiffieHellmanSpec.cpp @@ -1,31 +1,14 @@ /// /// HybridDiffieHellmanSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridDiffieHellmanSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridDiffieHellmanSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("init", &HybridDiffieHellmanSpec::init); - prototype.registerHybridMethod("initWithSize", &HybridDiffieHellmanSpec::initWithSize); - prototype.registerHybridMethod("generateKeys", &HybridDiffieHellmanSpec::generateKeys); - prototype.registerHybridMethod("computeSecret", &HybridDiffieHellmanSpec::computeSecret); - prototype.registerHybridMethod("getPrime", &HybridDiffieHellmanSpec::getPrime); - prototype.registerHybridMethod("getGenerator", &HybridDiffieHellmanSpec::getGenerator); - prototype.registerHybridMethod("getPublicKey", &HybridDiffieHellmanSpec::getPublicKey); - prototype.registerHybridMethod("getPrivateKey", &HybridDiffieHellmanSpec::getPrivateKey); - prototype.registerHybridMethod("setPublicKey", &HybridDiffieHellmanSpec::setPublicKey); - prototype.registerHybridMethod("setPrivateKey", &HybridDiffieHellmanSpec::setPrivateKey); - prototype.registerHybridMethod("getVerifyError", &HybridDiffieHellmanSpec::getVerifyError); - }); - } + HybridDiffieHellmanSpec::~HybridDiffieHellmanSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridDiffieHellmanSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridDiffieHellmanSpec.hpp deleted file mode 100644 index 667c6b51c..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridDiffieHellmanSpec.hpp +++ /dev/null @@ -1,72 +0,0 @@ -/// -/// HybridDiffieHellmanSpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - - - -#include - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `DiffieHellman` - * Inherit this class to create instances of `HybridDiffieHellmanSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridDiffieHellman: public HybridDiffieHellmanSpec { - * public: - * HybridDiffieHellman(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridDiffieHellmanSpec: public virtual HybridObject { - public: - // Constructor - explicit HybridDiffieHellmanSpec(): HybridObject(TAG) { } - - // Destructor - ~HybridDiffieHellmanSpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual void init(const std::shared_ptr& prime, const std::shared_ptr& generator) = 0; - virtual void initWithSize(double primeLength, double generator) = 0; - virtual std::shared_ptr generateKeys() = 0; - virtual std::shared_ptr computeSecret(const std::shared_ptr& otherPublicKey) = 0; - virtual std::shared_ptr getPrime() = 0; - virtual std::shared_ptr getGenerator() = 0; - virtual std::shared_ptr getPublicKey() = 0; - virtual std::shared_ptr getPrivateKey() = 0; - virtual void setPublicKey(const std::shared_ptr& publicKey) = 0; - virtual void setPrivateKey(const std::shared_ptr& privateKey) = 0; - virtual double getVerifyError() = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "DiffieHellman"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridDsaKeyPairSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridDsaKeyPairSpec.cpp index 494251346..35a69ced0 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridDsaKeyPairSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridDsaKeyPairSpec.cpp @@ -1,26 +1,14 @@ /// /// HybridDsaKeyPairSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridDsaKeyPairSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridDsaKeyPairSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("generateKeyPair", &HybridDsaKeyPairSpec::generateKeyPair); - prototype.registerHybridMethod("generateKeyPairSync", &HybridDsaKeyPairSpec::generateKeyPairSync); - prototype.registerHybridMethod("setModulusLength", &HybridDsaKeyPairSpec::setModulusLength); - prototype.registerHybridMethod("setDivisorLength", &HybridDsaKeyPairSpec::setDivisorLength); - prototype.registerHybridMethod("getPublicKey", &HybridDsaKeyPairSpec::getPublicKey); - prototype.registerHybridMethod("getPrivateKey", &HybridDsaKeyPairSpec::getPrivateKey); - }); - } + HybridDsaKeyPairSpec::~HybridDsaKeyPairSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridECDHSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridECDHSpec.cpp index 63fefb9a8..d5bfa0baf 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridECDHSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridECDHSpec.cpp @@ -1,28 +1,14 @@ /// /// HybridECDHSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridECDHSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridECDHSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("init", &HybridECDHSpec::init); - prototype.registerHybridMethod("generateKeys", &HybridECDHSpec::generateKeys); - prototype.registerHybridMethod("computeSecret", &HybridECDHSpec::computeSecret); - prototype.registerHybridMethod("getPrivateKey", &HybridECDHSpec::getPrivateKey); - prototype.registerHybridMethod("setPrivateKey", &HybridECDHSpec::setPrivateKey); - prototype.registerHybridMethod("getPublicKey", &HybridECDHSpec::getPublicKey); - prototype.registerHybridMethod("setPublicKey", &HybridECDHSpec::setPublicKey); - prototype.registerHybridMethod("convertKey", &HybridECDHSpec::convertKey); - }); - } + HybridECDHSpec::~HybridECDHSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridECDHSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridECDHSpec.hpp deleted file mode 100644 index 29c745665..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridECDHSpec.hpp +++ /dev/null @@ -1,70 +0,0 @@ -/// -/// HybridECDHSpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - - - -#include -#include - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `ECDH` - * Inherit this class to create instances of `HybridECDHSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridECDH: public HybridECDHSpec { - * public: - * HybridECDH(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridECDHSpec: public virtual HybridObject { - public: - // Constructor - explicit HybridECDHSpec(): HybridObject(TAG) { } - - // Destructor - ~HybridECDHSpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual void init(const std::string& curveName) = 0; - virtual std::shared_ptr generateKeys() = 0; - virtual std::shared_ptr computeSecret(const std::shared_ptr& otherPublicKey) = 0; - virtual std::shared_ptr getPrivateKey() = 0; - virtual void setPrivateKey(const std::shared_ptr& privateKey) = 0; - virtual std::shared_ptr getPublicKey() = 0; - virtual void setPublicKey(const std::shared_ptr& publicKey) = 0; - virtual std::shared_ptr convertKey(const std::shared_ptr& key, const std::string& curve, double format) = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "ECDH"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridEcKeyPairSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridEcKeyPairSpec.cpp index 0ae1c8830..3cd7fe56e 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridEcKeyPairSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridEcKeyPairSpec.cpp @@ -1,30 +1,14 @@ /// /// HybridEcKeyPairSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridEcKeyPairSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridEcKeyPairSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("generateKeyPair", &HybridEcKeyPairSpec::generateKeyPair); - prototype.registerHybridMethod("generateKeyPairSync", &HybridEcKeyPairSpec::generateKeyPairSync); - prototype.registerHybridMethod("importKey", &HybridEcKeyPairSpec::importKey); - prototype.registerHybridMethod("exportKey", &HybridEcKeyPairSpec::exportKey); - prototype.registerHybridMethod("getPublicKey", &HybridEcKeyPairSpec::getPublicKey); - prototype.registerHybridMethod("getPrivateKey", &HybridEcKeyPairSpec::getPrivateKey); - prototype.registerHybridMethod("setCurve", &HybridEcKeyPairSpec::setCurve); - prototype.registerHybridMethod("sign", &HybridEcKeyPairSpec::sign); - prototype.registerHybridMethod("verify", &HybridEcKeyPairSpec::verify); - prototype.registerHybridMethod("getSupportedCurves", &HybridEcKeyPairSpec::getSupportedCurves); - }); - } + HybridEcKeyPairSpec::~HybridEcKeyPairSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridEcKeyPairSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridEcKeyPairSpec.hpp deleted file mode 100644 index 7ef4ea24e..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridEcKeyPairSpec.hpp +++ /dev/null @@ -1,76 +0,0 @@ -/// -/// HybridEcKeyPairSpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - -// Forward declaration of `KeyObject` to properly resolve imports. -namespace margelo::nitro::crypto { struct KeyObject; } - -#include -#include "KeyObject.hpp" -#include -#include -#include - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `EcKeyPair` - * Inherit this class to create instances of `HybridEcKeyPairSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridEcKeyPair: public HybridEcKeyPairSpec { - * public: - * HybridEcKeyPair(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridEcKeyPairSpec: public virtual HybridObject { - public: - // Constructor - explicit HybridEcKeyPairSpec(): HybridObject(TAG) { } - - // Destructor - ~HybridEcKeyPairSpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual std::shared_ptr> generateKeyPair() = 0; - virtual void generateKeyPairSync() = 0; - virtual KeyObject importKey(const std::string& format, const std::shared_ptr& keyData, const std::string& algorithm, bool extractable, const std::vector& keyUsages) = 0; - virtual std::shared_ptr exportKey(const KeyObject& key, const std::string& format) = 0; - virtual std::shared_ptr getPublicKey() = 0; - virtual std::shared_ptr getPrivateKey() = 0; - virtual void setCurve(const std::string& curve) = 0; - virtual std::shared_ptr sign(const std::shared_ptr& data, const std::string& hashAlgorithm) = 0; - virtual bool verify(const std::shared_ptr& data, const std::shared_ptr& signature, const std::string& hashAlgorithm) = 0; - virtual std::vector getSupportedCurves() = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "EcKeyPair"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.cpp index d53a0735a..e6831f622 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.cpp @@ -1,30 +1,14 @@ /// /// HybridEdKeyPairSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridEdKeyPairSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridEdKeyPairSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("diffieHellman", &HybridEdKeyPairSpec::diffieHellman); - prototype.registerHybridMethod("generateKeyPair", &HybridEdKeyPairSpec::generateKeyPair); - prototype.registerHybridMethod("generateKeyPairSync", &HybridEdKeyPairSpec::generateKeyPairSync); - prototype.registerHybridMethod("getPublicKey", &HybridEdKeyPairSpec::getPublicKey); - prototype.registerHybridMethod("getPrivateKey", &HybridEdKeyPairSpec::getPrivateKey); - prototype.registerHybridMethod("sign", &HybridEdKeyPairSpec::sign); - prototype.registerHybridMethod("signSync", &HybridEdKeyPairSpec::signSync); - prototype.registerHybridMethod("verify", &HybridEdKeyPairSpec::verify); - prototype.registerHybridMethod("verifySync", &HybridEdKeyPairSpec::verifySync); - prototype.registerHybridMethod("setCurve", &HybridEdKeyPairSpec::setCurve); - }); - } + HybridEdKeyPairSpec::~HybridEdKeyPairSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.hpp deleted file mode 100644 index f91ea004a..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridEdKeyPairSpec.hpp +++ /dev/null @@ -1,74 +0,0 @@ -/// -/// HybridEdKeyPairSpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - - - -#include -#include -#include -#include - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `EdKeyPair` - * Inherit this class to create instances of `HybridEdKeyPairSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridEdKeyPair: public HybridEdKeyPairSpec { - * public: - * HybridEdKeyPair(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridEdKeyPairSpec: public virtual HybridObject { - public: - // Constructor - explicit HybridEdKeyPairSpec(): HybridObject(TAG) { } - - // Destructor - ~HybridEdKeyPairSpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual std::shared_ptr diffieHellman(const std::shared_ptr& privateKey, const std::shared_ptr& publicKey) = 0; - virtual std::shared_ptr> generateKeyPair(double publicFormat, double publicType, double privateFormat, double privateType, const std::optional& cipher, const std::optional>& passphrase) = 0; - virtual void generateKeyPairSync(double publicFormat, double publicType, double privateFormat, double privateType, const std::optional& cipher, const std::optional>& passphrase) = 0; - virtual std::shared_ptr getPublicKey() = 0; - virtual std::shared_ptr getPrivateKey() = 0; - virtual std::shared_ptr>> sign(const std::shared_ptr& message, const std::optional>& key) = 0; - virtual std::shared_ptr signSync(const std::shared_ptr& message, const std::optional>& key) = 0; - virtual std::shared_ptr> verify(const std::shared_ptr& signature, const std::shared_ptr& message, const std::optional>& key) = 0; - virtual bool verifySync(const std::shared_ptr& signature, const std::shared_ptr& message, const std::optional>& key) = 0; - virtual void setCurve(const std::string& curve) = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "EdKeyPair"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridHashSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridHashSpec.cpp index 594866841..2effb0d2a 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridHashSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridHashSpec.cpp @@ -1,26 +1,14 @@ /// /// HybridHashSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridHashSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridHashSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("createHash", &HybridHashSpec::createHash); - prototype.registerHybridMethod("update", &HybridHashSpec::update); - prototype.registerHybridMethod("digest", &HybridHashSpec::digest); - prototype.registerHybridMethod("copy", &HybridHashSpec::copy); - prototype.registerHybridMethod("getSupportedHashAlgorithms", &HybridHashSpec::getSupportedHashAlgorithms); - prototype.registerHybridMethod("getOpenSSLVersion", &HybridHashSpec::getOpenSSLVersion); - }); - } + HybridHashSpec::~HybridHashSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridHashSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridHashSpec.hpp deleted file mode 100644 index 3f819fe88..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridHashSpec.hpp +++ /dev/null @@ -1,74 +0,0 @@ -/// -/// HybridHashSpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - -// Forward declaration of `HybridHashSpec` to properly resolve imports. -namespace margelo::nitro::crypto { class HybridHashSpec; } - -#include -#include -#include -#include -#include -#include "HybridHashSpec.hpp" -#include - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `Hash` - * Inherit this class to create instances of `HybridHashSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridHash: public HybridHashSpec { - * public: - * HybridHash(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridHashSpec: public virtual HybridObject { - public: - // Constructor - explicit HybridHashSpec(): HybridObject(TAG) { } - - // Destructor - ~HybridHashSpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual void createHash(const std::string& algorithm, std::optional outputLength) = 0; - virtual void update(const std::variant, std::string>& data) = 0; - virtual std::shared_ptr digest(const std::optional& encoding) = 0; - virtual std::shared_ptr copy(std::optional outputLength) = 0; - virtual std::vector getSupportedHashAlgorithms() = 0; - virtual std::string getOpenSSLVersion() = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "Hash"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridHkdfSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridHkdfSpec.cpp index a4a1c5a9b..d02307d91 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridHkdfSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridHkdfSpec.cpp @@ -1,22 +1,14 @@ /// /// HybridHkdfSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridHkdfSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridHkdfSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("deriveKeySync", &HybridHkdfSpec::deriveKeySync); - prototype.registerHybridMethod("deriveKey", &HybridHkdfSpec::deriveKey); - }); - } + HybridHkdfSpec::~HybridHkdfSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridHkdfSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridHkdfSpec.hpp deleted file mode 100644 index 4cd9ea9f2..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridHkdfSpec.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/// -/// HybridHkdfSpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - -// Forward declaration of `HkdfMode` to properly resolve imports. -namespace margelo::nitro::crypto { enum class HkdfMode; } - -#include -#include -#include "HkdfMode.hpp" -#include - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `Hkdf` - * Inherit this class to create instances of `HybridHkdfSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridHkdf: public HybridHkdfSpec { - * public: - * HybridHkdf(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridHkdfSpec: public virtual HybridObject { - public: - // Constructor - explicit HybridHkdfSpec(): HybridObject(TAG) { } - - // Destructor - ~HybridHkdfSpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual std::shared_ptr deriveKeySync(const std::string& algorithm, const std::shared_ptr& key, const std::shared_ptr& salt, const std::shared_ptr& info, double length, HkdfMode mode) = 0; - virtual std::shared_ptr>> deriveKey(const std::string& algorithm, const std::shared_ptr& key, const std::shared_ptr& salt, const std::shared_ptr& info, double length, HkdfMode mode) = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "Hkdf"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridHmacSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridHmacSpec.cpp index 44b8d2e9a..e3e2e34e8 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridHmacSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridHmacSpec.cpp @@ -1,23 +1,14 @@ /// /// HybridHmacSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridHmacSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridHmacSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("createHmac", &HybridHmacSpec::createHmac); - prototype.registerHybridMethod("update", &HybridHmacSpec::update); - prototype.registerHybridMethod("digest", &HybridHmacSpec::digest); - }); - } + HybridHmacSpec::~HybridHmacSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridHmacSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridHmacSpec.hpp deleted file mode 100644 index 90b9a2b8c..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridHmacSpec.hpp +++ /dev/null @@ -1,66 +0,0 @@ -/// -/// HybridHmacSpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - - - -#include -#include -#include - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `Hmac` - * Inherit this class to create instances of `HybridHmacSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridHmac: public HybridHmacSpec { - * public: - * HybridHmac(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridHmacSpec: public virtual HybridObject { - public: - // Constructor - explicit HybridHmacSpec(): HybridObject(TAG) { } - - // Destructor - ~HybridHmacSpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual void createHmac(const std::string& algorithm, const std::shared_ptr& key) = 0; - virtual void update(const std::variant, std::string>& data) = 0; - virtual std::shared_ptr digest() = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "Hmac"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.cpp index e9ac57f16..0d5a69193 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.cpp @@ -1,39 +1,14 @@ /// /// HybridKeyObjectHandleSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridKeyObjectHandleSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridKeyObjectHandleSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("exportKey", &HybridKeyObjectHandleSpec::exportKey); - prototype.registerHybridMethod("exportJwk", &HybridKeyObjectHandleSpec::exportJwk); - prototype.registerHybridMethod("exportRawPublic", &HybridKeyObjectHandleSpec::exportRawPublic); - prototype.registerHybridMethod("exportRawPrivate", &HybridKeyObjectHandleSpec::exportRawPrivate); - prototype.registerHybridMethod("exportRawSeed", &HybridKeyObjectHandleSpec::exportRawSeed); - prototype.registerHybridMethod("exportECPublicRaw", &HybridKeyObjectHandleSpec::exportECPublicRaw); - prototype.registerHybridMethod("exportECPrivateRaw", &HybridKeyObjectHandleSpec::exportECPrivateRaw); - prototype.registerHybridMethod("getAsymmetricKeyType", &HybridKeyObjectHandleSpec::getAsymmetricKeyType); - prototype.registerHybridMethod("init", &HybridKeyObjectHandleSpec::init); - prototype.registerHybridMethod("initECRaw", &HybridKeyObjectHandleSpec::initECRaw); - prototype.registerHybridMethod("initPqcRaw", &HybridKeyObjectHandleSpec::initPqcRaw); - prototype.registerHybridMethod("initRawPublic", &HybridKeyObjectHandleSpec::initRawPublic); - prototype.registerHybridMethod("initRawPrivate", &HybridKeyObjectHandleSpec::initRawPrivate); - prototype.registerHybridMethod("initRawSeed", &HybridKeyObjectHandleSpec::initRawSeed); - prototype.registerHybridMethod("initJwk", &HybridKeyObjectHandleSpec::initJwk); - prototype.registerHybridMethod("keyDetail", &HybridKeyObjectHandleSpec::keyDetail); - prototype.registerHybridMethod("keyEquals", &HybridKeyObjectHandleSpec::keyEquals); - prototype.registerHybridMethod("getSymmetricKeySize", &HybridKeyObjectHandleSpec::getSymmetricKeySize); - prototype.registerHybridMethod("checkEcKeyData", &HybridKeyObjectHandleSpec::checkEcKeyData); - }); - } + HybridKeyObjectHandleSpec::~HybridKeyObjectHandleSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.hpp deleted file mode 100644 index c22cfde2f..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.hpp +++ /dev/null @@ -1,107 +0,0 @@ -/// -/// HybridKeyObjectHandleSpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - -// Forward declaration of `KFormatType` to properly resolve imports. -namespace margelo::nitro::crypto { enum class KFormatType; } -// Forward declaration of `KeyEncoding` to properly resolve imports. -namespace margelo::nitro::crypto { enum class KeyEncoding; } -// Forward declaration of `JWK` to properly resolve imports. -namespace margelo::nitro::crypto { struct JWK; } -// Forward declaration of `AsymmetricKeyType` to properly resolve imports. -namespace margelo::nitro::crypto { enum class AsymmetricKeyType; } -// Forward declaration of `KeyType` to properly resolve imports. -namespace margelo::nitro::crypto { enum class KeyType; } -// Forward declaration of `NamedCurve` to properly resolve imports. -namespace margelo::nitro::crypto { enum class NamedCurve; } -// Forward declaration of `KeyDetail` to properly resolve imports. -namespace margelo::nitro::crypto { struct KeyDetail; } -// Forward declaration of `HybridKeyObjectHandleSpec` to properly resolve imports. -namespace margelo::nitro::crypto { class HybridKeyObjectHandleSpec; } - -#include -#include "KFormatType.hpp" -#include -#include "KeyEncoding.hpp" -#include -#include "JWK.hpp" -#include "AsymmetricKeyType.hpp" -#include "KeyType.hpp" -#include -#include "NamedCurve.hpp" -#include "KeyDetail.hpp" -#include -#include "HybridKeyObjectHandleSpec.hpp" - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `KeyObjectHandle` - * Inherit this class to create instances of `HybridKeyObjectHandleSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridKeyObjectHandle: public HybridKeyObjectHandleSpec { - * public: - * HybridKeyObjectHandle(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridKeyObjectHandleSpec: public virtual HybridObject { - public: - // Constructor - explicit HybridKeyObjectHandleSpec(): HybridObject(TAG) { } - - // Destructor - ~HybridKeyObjectHandleSpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual std::shared_ptr exportKey(std::optional format, std::optional type, const std::optional& cipher, const std::optional>& passphrase) = 0; - virtual JWK exportJwk(const JWK& key, bool handleRsaPss) = 0; - virtual std::shared_ptr exportRawPublic() = 0; - virtual std::shared_ptr exportRawPrivate() = 0; - virtual std::shared_ptr exportRawSeed() = 0; - virtual std::shared_ptr exportECPublicRaw(bool compressed) = 0; - virtual std::shared_ptr exportECPrivateRaw() = 0; - virtual AsymmetricKeyType getAsymmetricKeyType() = 0; - virtual bool init(KeyType keyType, const std::variant, std::string>& key, std::optional format, std::optional type, const std::optional>& passphrase) = 0; - virtual bool initECRaw(const std::string& namedCurve, const std::shared_ptr& keyData) = 0; - virtual bool initPqcRaw(const std::string& algorithmName, const std::shared_ptr& keyData, bool isPublic) = 0; - virtual bool initRawPublic(const std::string& asymmetricKeyType, const std::shared_ptr& keyData, const std::optional& namedCurve) = 0; - virtual bool initRawPrivate(const std::string& asymmetricKeyType, const std::shared_ptr& keyData, const std::optional& namedCurve) = 0; - virtual bool initRawSeed(const std::string& asymmetricKeyType, const std::shared_ptr& keyData) = 0; - virtual std::optional initJwk(const JWK& keyData, std::optional namedCurve) = 0; - virtual KeyDetail keyDetail() = 0; - virtual bool keyEquals(const std::shared_ptr& other) = 0; - virtual double getSymmetricKeySize() = 0; - virtual bool checkEcKeyData() = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "KeyObjectHandle"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridKmacSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridKmacSpec.cpp index 8d726a0c2..e444b30eb 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridKmacSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridKmacSpec.cpp @@ -1,23 +1,14 @@ /// /// HybridKmacSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridKmacSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridKmacSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("createKmac", &HybridKmacSpec::createKmac); - prototype.registerHybridMethod("update", &HybridKmacSpec::update); - prototype.registerHybridMethod("digest", &HybridKmacSpec::digest); - }); - } + HybridKmacSpec::~HybridKmacSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridKmacSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridKmacSpec.hpp deleted file mode 100644 index 882f528f6..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridKmacSpec.hpp +++ /dev/null @@ -1,66 +0,0 @@ -/// -/// HybridKmacSpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - - - -#include -#include -#include - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `Kmac` - * Inherit this class to create instances of `HybridKmacSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridKmac: public HybridKmacSpec { - * public: - * HybridKmac(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridKmacSpec: public virtual HybridObject { - public: - // Constructor - explicit HybridKmacSpec(): HybridObject(TAG) { } - - // Destructor - ~HybridKmacSpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual void createKmac(const std::string& algorithm, const std::shared_ptr& key, double outputLength, const std::optional>& customization) = 0; - virtual void update(const std::shared_ptr& data) = 0; - virtual std::shared_ptr digest() = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "Kmac"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridMlDsaKeyPairSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridMlDsaKeyPairSpec.cpp index 3afa0e1d2..1b5c8e739 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridMlDsaKeyPairSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridMlDsaKeyPairSpec.cpp @@ -1,29 +1,14 @@ /// /// HybridMlDsaKeyPairSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridMlDsaKeyPairSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridMlDsaKeyPairSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("generateKeyPair", &HybridMlDsaKeyPairSpec::generateKeyPair); - prototype.registerHybridMethod("generateKeyPairSync", &HybridMlDsaKeyPairSpec::generateKeyPairSync); - prototype.registerHybridMethod("getPublicKey", &HybridMlDsaKeyPairSpec::getPublicKey); - prototype.registerHybridMethod("getPrivateKey", &HybridMlDsaKeyPairSpec::getPrivateKey); - prototype.registerHybridMethod("sign", &HybridMlDsaKeyPairSpec::sign); - prototype.registerHybridMethod("signSync", &HybridMlDsaKeyPairSpec::signSync); - prototype.registerHybridMethod("verify", &HybridMlDsaKeyPairSpec::verify); - prototype.registerHybridMethod("verifySync", &HybridMlDsaKeyPairSpec::verifySync); - prototype.registerHybridMethod("setVariant", &HybridMlDsaKeyPairSpec::setVariant); - }); - } + HybridMlDsaKeyPairSpec::~HybridMlDsaKeyPairSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridMlDsaKeyPairSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridMlDsaKeyPairSpec.hpp deleted file mode 100644 index 3f3408f8d..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridMlDsaKeyPairSpec.hpp +++ /dev/null @@ -1,72 +0,0 @@ -/// -/// HybridMlDsaKeyPairSpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - - - -#include -#include -#include - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `MlDsaKeyPair` - * Inherit this class to create instances of `HybridMlDsaKeyPairSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridMlDsaKeyPair: public HybridMlDsaKeyPairSpec { - * public: - * HybridMlDsaKeyPair(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridMlDsaKeyPairSpec: public virtual HybridObject { - public: - // Constructor - explicit HybridMlDsaKeyPairSpec(): HybridObject(TAG) { } - - // Destructor - ~HybridMlDsaKeyPairSpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual std::shared_ptr> generateKeyPair(double publicFormat, double publicType, double privateFormat, double privateType) = 0; - virtual void generateKeyPairSync(double publicFormat, double publicType, double privateFormat, double privateType) = 0; - virtual std::shared_ptr getPublicKey() = 0; - virtual std::shared_ptr getPrivateKey() = 0; - virtual std::shared_ptr>> sign(const std::shared_ptr& message) = 0; - virtual std::shared_ptr signSync(const std::shared_ptr& message) = 0; - virtual std::shared_ptr> verify(const std::shared_ptr& signature, const std::shared_ptr& message) = 0; - virtual bool verifySync(const std::shared_ptr& signature, const std::shared_ptr& message) = 0; - virtual void setVariant(const std::string& variant) = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "MlDsaKeyPair"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridMlKemKeyPairSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridMlKemKeyPairSpec.cpp index 976406860..dfb0a735a 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridMlKemKeyPairSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridMlKemKeyPairSpec.cpp @@ -1,31 +1,14 @@ /// /// HybridMlKemKeyPairSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridMlKemKeyPairSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridMlKemKeyPairSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("setVariant", &HybridMlKemKeyPairSpec::setVariant); - prototype.registerHybridMethod("generateKeyPair", &HybridMlKemKeyPairSpec::generateKeyPair); - prototype.registerHybridMethod("generateKeyPairSync", &HybridMlKemKeyPairSpec::generateKeyPairSync); - prototype.registerHybridMethod("getPublicKey", &HybridMlKemKeyPairSpec::getPublicKey); - prototype.registerHybridMethod("getPrivateKey", &HybridMlKemKeyPairSpec::getPrivateKey); - prototype.registerHybridMethod("setPublicKey", &HybridMlKemKeyPairSpec::setPublicKey); - prototype.registerHybridMethod("setPrivateKey", &HybridMlKemKeyPairSpec::setPrivateKey); - prototype.registerHybridMethod("encapsulate", &HybridMlKemKeyPairSpec::encapsulate); - prototype.registerHybridMethod("encapsulateSync", &HybridMlKemKeyPairSpec::encapsulateSync); - prototype.registerHybridMethod("decapsulate", &HybridMlKemKeyPairSpec::decapsulate); - prototype.registerHybridMethod("decapsulateSync", &HybridMlKemKeyPairSpec::decapsulateSync); - }); - } + HybridMlKemKeyPairSpec::~HybridMlKemKeyPairSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridMlKemKeyPairSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridMlKemKeyPairSpec.hpp deleted file mode 100644 index f84a94f89..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridMlKemKeyPairSpec.hpp +++ /dev/null @@ -1,74 +0,0 @@ -/// -/// HybridMlKemKeyPairSpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - - - -#include -#include -#include - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `MlKemKeyPair` - * Inherit this class to create instances of `HybridMlKemKeyPairSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridMlKemKeyPair: public HybridMlKemKeyPairSpec { - * public: - * HybridMlKemKeyPair(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridMlKemKeyPairSpec: public virtual HybridObject { - public: - // Constructor - explicit HybridMlKemKeyPairSpec(): HybridObject(TAG) { } - - // Destructor - ~HybridMlKemKeyPairSpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual void setVariant(const std::string& variant) = 0; - virtual std::shared_ptr> generateKeyPair(double publicFormat, double publicType, double privateFormat, double privateType) = 0; - virtual void generateKeyPairSync(double publicFormat, double publicType, double privateFormat, double privateType) = 0; - virtual std::shared_ptr getPublicKey() = 0; - virtual std::shared_ptr getPrivateKey() = 0; - virtual void setPublicKey(const std::shared_ptr& keyData, double format, double type) = 0; - virtual void setPrivateKey(const std::shared_ptr& keyData, double format, double type) = 0; - virtual std::shared_ptr>> encapsulate() = 0; - virtual std::shared_ptr encapsulateSync() = 0; - virtual std::shared_ptr>> decapsulate(const std::shared_ptr& ciphertext) = 0; - virtual std::shared_ptr decapsulateSync(const std::shared_ptr& ciphertext) = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "MlKemKeyPair"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridPbkdf2Spec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridPbkdf2Spec.cpp index 4e8b981b0..97d8d96b7 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridPbkdf2Spec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridPbkdf2Spec.cpp @@ -1,22 +1,14 @@ /// /// HybridPbkdf2Spec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridPbkdf2Spec.hpp" +#include namespace margelo::nitro::crypto { - void HybridPbkdf2Spec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("pbkdf2", &HybridPbkdf2Spec::pbkdf2); - prototype.registerHybridMethod("pbkdf2Sync", &HybridPbkdf2Spec::pbkdf2Sync); - }); - } + HybridPbkdf2Spec::~HybridPbkdf2Spec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridPbkdf2Spec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridPbkdf2Spec.hpp deleted file mode 100644 index c00d8a424..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridPbkdf2Spec.hpp +++ /dev/null @@ -1,65 +0,0 @@ -/// -/// HybridPbkdf2Spec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - - - -#include -#include -#include - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `Pbkdf2` - * Inherit this class to create instances of `HybridPbkdf2Spec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridPbkdf2: public HybridPbkdf2Spec { - * public: - * HybridPbkdf2(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridPbkdf2Spec: public virtual HybridObject { - public: - // Constructor - explicit HybridPbkdf2Spec(): HybridObject(TAG) { } - - // Destructor - ~HybridPbkdf2Spec() override = default; - - public: - // Properties - - - public: - // Methods - virtual std::shared_ptr>> pbkdf2(const std::shared_ptr& password, const std::shared_ptr& salt, double iterations, double keylen, const std::string& digest) = 0; - virtual std::shared_ptr pbkdf2Sync(const std::shared_ptr& password, const std::shared_ptr& salt, double iterations, double keylen, const std::string& digest) = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "Pbkdf2"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridPrimeSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridPrimeSpec.cpp index e448736aa..43b798b86 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridPrimeSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridPrimeSpec.cpp @@ -1,24 +1,14 @@ /// /// HybridPrimeSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridPrimeSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridPrimeSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("generatePrime", &HybridPrimeSpec::generatePrime); - prototype.registerHybridMethod("generatePrimeSync", &HybridPrimeSpec::generatePrimeSync); - prototype.registerHybridMethod("checkPrime", &HybridPrimeSpec::checkPrime); - prototype.registerHybridMethod("checkPrimeSync", &HybridPrimeSpec::checkPrimeSync); - }); - } + HybridPrimeSpec::~HybridPrimeSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridPrimeSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridPrimeSpec.hpp deleted file mode 100644 index 7a730673b..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridPrimeSpec.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/// -/// HybridPrimeSpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - - - -#include -#include -#include - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `Prime` - * Inherit this class to create instances of `HybridPrimeSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridPrime: public HybridPrimeSpec { - * public: - * HybridPrime(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridPrimeSpec: public virtual HybridObject { - public: - // Constructor - explicit HybridPrimeSpec(): HybridObject(TAG) { } - - // Destructor - ~HybridPrimeSpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual std::shared_ptr>> generatePrime(double size, bool safe, const std::optional>& add, const std::optional>& rem) = 0; - virtual std::shared_ptr generatePrimeSync(double size, bool safe, const std::optional>& add, const std::optional>& rem) = 0; - virtual std::shared_ptr> checkPrime(const std::shared_ptr& candidate, double checks) = 0; - virtual bool checkPrimeSync(const std::shared_ptr& candidate, double checks) = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "Prime"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridRandomSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridRandomSpec.cpp index 98ae37141..f3b99705a 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridRandomSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridRandomSpec.cpp @@ -1,22 +1,14 @@ /// /// HybridRandomSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridRandomSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridRandomSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("randomFill", &HybridRandomSpec::randomFill); - prototype.registerHybridMethod("randomFillSync", &HybridRandomSpec::randomFillSync); - }); - } + HybridRandomSpec::~HybridRandomSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridRandomSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridRandomSpec.hpp deleted file mode 100644 index ec34b8e40..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridRandomSpec.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/// -/// HybridRandomSpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - - - -#include -#include - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `Random` - * Inherit this class to create instances of `HybridRandomSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridRandom: public HybridRandomSpec { - * public: - * HybridRandom(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridRandomSpec: public virtual HybridObject { - public: - // Constructor - explicit HybridRandomSpec(): HybridObject(TAG) { } - - // Destructor - ~HybridRandomSpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual std::shared_ptr>> randomFill(const std::shared_ptr& buffer, double offset, double size) = 0; - virtual std::shared_ptr randomFillSync(const std::shared_ptr& buffer, double offset, double size) = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "Random"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridRsaCipherSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridRsaCipherSpec.cpp index 25628b4f6..6157eb545 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridRsaCipherSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridRsaCipherSpec.cpp @@ -1,25 +1,14 @@ /// /// HybridRsaCipherSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridRsaCipherSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridRsaCipherSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("encrypt", &HybridRsaCipherSpec::encrypt); - prototype.registerHybridMethod("decrypt", &HybridRsaCipherSpec::decrypt); - prototype.registerHybridMethod("publicDecrypt", &HybridRsaCipherSpec::publicDecrypt); - prototype.registerHybridMethod("privateEncrypt", &HybridRsaCipherSpec::privateEncrypt); - prototype.registerHybridMethod("privateDecrypt", &HybridRsaCipherSpec::privateDecrypt); - }); - } + HybridRsaCipherSpec::~HybridRsaCipherSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridRsaCipherSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridRsaCipherSpec.hpp deleted file mode 100644 index b3486872e..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridRsaCipherSpec.hpp +++ /dev/null @@ -1,71 +0,0 @@ -/// -/// HybridRsaCipherSpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - -// Forward declaration of `HybridKeyObjectHandleSpec` to properly resolve imports. -namespace margelo::nitro::crypto { class HybridKeyObjectHandleSpec; } - -#include -#include -#include "HybridKeyObjectHandleSpec.hpp" -#include -#include - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `RsaCipher` - * Inherit this class to create instances of `HybridRsaCipherSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridRsaCipher: public HybridRsaCipherSpec { - * public: - * HybridRsaCipher(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridRsaCipherSpec: public virtual HybridObject { - public: - // Constructor - explicit HybridRsaCipherSpec(): HybridObject(TAG) { } - - // Destructor - ~HybridRsaCipherSpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual std::shared_ptr encrypt(const std::shared_ptr& keyHandle, const std::shared_ptr& data, double padding, const std::string& hashAlgorithm, const std::optional>& label) = 0; - virtual std::shared_ptr decrypt(const std::shared_ptr& keyHandle, const std::shared_ptr& data, double padding, const std::string& hashAlgorithm, const std::optional>& label) = 0; - virtual std::shared_ptr publicDecrypt(const std::shared_ptr& keyHandle, const std::shared_ptr& data, double padding) = 0; - virtual std::shared_ptr privateEncrypt(const std::shared_ptr& keyHandle, const std::shared_ptr& data, double padding) = 0; - virtual std::shared_ptr privateDecrypt(const std::shared_ptr& keyHandle, const std::shared_ptr& data, double padding, const std::string& hashAlgorithm, const std::optional>& label) = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "RsaCipher"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.cpp index ad116c894..19f26b5cf 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.cpp @@ -1,29 +1,14 @@ /// /// HybridRsaKeyPairSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridRsaKeyPairSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridRsaKeyPairSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("generateKeyPair", &HybridRsaKeyPairSpec::generateKeyPair); - prototype.registerHybridMethod("generateKeyPairSync", &HybridRsaKeyPairSpec::generateKeyPairSync); - prototype.registerHybridMethod("setModulusLength", &HybridRsaKeyPairSpec::setModulusLength); - prototype.registerHybridMethod("setPublicExponent", &HybridRsaKeyPairSpec::setPublicExponent); - prototype.registerHybridMethod("setHashAlgorithm", &HybridRsaKeyPairSpec::setHashAlgorithm); - prototype.registerHybridMethod("importKey", &HybridRsaKeyPairSpec::importKey); - prototype.registerHybridMethod("exportKey", &HybridRsaKeyPairSpec::exportKey); - prototype.registerHybridMethod("getPublicKey", &HybridRsaKeyPairSpec::getPublicKey); - prototype.registerHybridMethod("getPrivateKey", &HybridRsaKeyPairSpec::getPrivateKey); - }); - } + HybridRsaKeyPairSpec::~HybridRsaKeyPairSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.hpp deleted file mode 100644 index c8df50e01..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridRsaKeyPairSpec.hpp +++ /dev/null @@ -1,75 +0,0 @@ -/// -/// HybridRsaKeyPairSpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - -// Forward declaration of `KeyObject` to properly resolve imports. -namespace margelo::nitro::crypto { struct KeyObject; } - -#include -#include -#include -#include "KeyObject.hpp" -#include - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `RsaKeyPair` - * Inherit this class to create instances of `HybridRsaKeyPairSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridRsaKeyPair: public HybridRsaKeyPairSpec { - * public: - * HybridRsaKeyPair(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridRsaKeyPairSpec: public virtual HybridObject { - public: - // Constructor - explicit HybridRsaKeyPairSpec(): HybridObject(TAG) { } - - // Destructor - ~HybridRsaKeyPairSpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual std::shared_ptr> generateKeyPair() = 0; - virtual void generateKeyPairSync() = 0; - virtual void setModulusLength(double modulusLength) = 0; - virtual void setPublicExponent(const std::shared_ptr& publicExponent) = 0; - virtual void setHashAlgorithm(const std::string& hashAlgorithm) = 0; - virtual KeyObject importKey(const std::string& format, const std::shared_ptr& keyData, const std::string& algorithm, bool extractable, const std::vector& keyUsages) = 0; - virtual std::shared_ptr exportKey(const KeyObject& key, const std::string& format) = 0; - virtual std::shared_ptr getPublicKey() = 0; - virtual std::shared_ptr getPrivateKey() = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "RsaKeyPair"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridScryptSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridScryptSpec.cpp index 95a4e62c1..a04caa42c 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridScryptSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridScryptSpec.cpp @@ -1,22 +1,14 @@ /// /// HybridScryptSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridScryptSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridScryptSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("deriveKey", &HybridScryptSpec::deriveKey); - prototype.registerHybridMethod("deriveKeySync", &HybridScryptSpec::deriveKeySync); - }); - } + HybridScryptSpec::~HybridScryptSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridScryptSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridScryptSpec.hpp deleted file mode 100644 index 7a2e893e3..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridScryptSpec.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/// -/// HybridScryptSpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - - - -#include -#include - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `Scrypt` - * Inherit this class to create instances of `HybridScryptSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridScrypt: public HybridScryptSpec { - * public: - * HybridScrypt(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridScryptSpec: public virtual HybridObject { - public: - // Constructor - explicit HybridScryptSpec(): HybridObject(TAG) { } - - // Destructor - ~HybridScryptSpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual std::shared_ptr>> deriveKey(const std::shared_ptr& password, const std::shared_ptr& salt, double N, double r, double p, double maxmem, double keylen) = 0; - virtual std::shared_ptr deriveKeySync(const std::shared_ptr& password, const std::shared_ptr& salt, double N, double r, double p, double maxmem, double keylen) = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "Scrypt"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridSignHandleSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridSignHandleSpec.cpp index 0d57b56ae..db3161240 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridSignHandleSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridSignHandleSpec.cpp @@ -1,23 +1,14 @@ /// /// HybridSignHandleSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridSignHandleSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridSignHandleSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("init", &HybridSignHandleSpec::init); - prototype.registerHybridMethod("update", &HybridSignHandleSpec::update); - prototype.registerHybridMethod("sign", &HybridSignHandleSpec::sign); - }); - } + HybridSignHandleSpec::~HybridSignHandleSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridSignHandleSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridSignHandleSpec.hpp deleted file mode 100644 index 304f10af2..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridSignHandleSpec.hpp +++ /dev/null @@ -1,69 +0,0 @@ -/// -/// HybridSignHandleSpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - -// Forward declaration of `HybridKeyObjectHandleSpec` to properly resolve imports. -namespace margelo::nitro::crypto { class HybridKeyObjectHandleSpec; } - -#include -#include -#include -#include "HybridKeyObjectHandleSpec.hpp" -#include - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `SignHandle` - * Inherit this class to create instances of `HybridSignHandleSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridSignHandle: public HybridSignHandleSpec { - * public: - * HybridSignHandle(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridSignHandleSpec: public virtual HybridObject { - public: - // Constructor - explicit HybridSignHandleSpec(): HybridObject(TAG) { } - - // Destructor - ~HybridSignHandleSpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual void init(const std::string& algorithm) = 0; - virtual void update(const std::shared_ptr& data) = 0; - virtual std::shared_ptr sign(const std::shared_ptr& keyHandle, std::optional padding, std::optional saltLength, std::optional dsaEncoding) = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "SignHandle"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridSlhDsaKeyPairSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridSlhDsaKeyPairSpec.cpp index 79d955482..92a0e6009 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridSlhDsaKeyPairSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridSlhDsaKeyPairSpec.cpp @@ -1,29 +1,14 @@ /// /// HybridSlhDsaKeyPairSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridSlhDsaKeyPairSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridSlhDsaKeyPairSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("generateKeyPair", &HybridSlhDsaKeyPairSpec::generateKeyPair); - prototype.registerHybridMethod("generateKeyPairSync", &HybridSlhDsaKeyPairSpec::generateKeyPairSync); - prototype.registerHybridMethod("getPublicKey", &HybridSlhDsaKeyPairSpec::getPublicKey); - prototype.registerHybridMethod("getPrivateKey", &HybridSlhDsaKeyPairSpec::getPrivateKey); - prototype.registerHybridMethod("sign", &HybridSlhDsaKeyPairSpec::sign); - prototype.registerHybridMethod("signSync", &HybridSlhDsaKeyPairSpec::signSync); - prototype.registerHybridMethod("verify", &HybridSlhDsaKeyPairSpec::verify); - prototype.registerHybridMethod("verifySync", &HybridSlhDsaKeyPairSpec::verifySync); - prototype.registerHybridMethod("setVariant", &HybridSlhDsaKeyPairSpec::setVariant); - }); - } + HybridSlhDsaKeyPairSpec::~HybridSlhDsaKeyPairSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridSlhDsaKeyPairSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridSlhDsaKeyPairSpec.hpp deleted file mode 100644 index 43725476b..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridSlhDsaKeyPairSpec.hpp +++ /dev/null @@ -1,72 +0,0 @@ -/// -/// HybridSlhDsaKeyPairSpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - - - -#include -#include -#include - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `SlhDsaKeyPair` - * Inherit this class to create instances of `HybridSlhDsaKeyPairSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridSlhDsaKeyPair: public HybridSlhDsaKeyPairSpec { - * public: - * HybridSlhDsaKeyPair(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridSlhDsaKeyPairSpec: public virtual HybridObject { - public: - // Constructor - explicit HybridSlhDsaKeyPairSpec(): HybridObject(TAG) { } - - // Destructor - ~HybridSlhDsaKeyPairSpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual std::shared_ptr> generateKeyPair(double publicFormat, double publicType, double privateFormat, double privateType) = 0; - virtual void generateKeyPairSync(double publicFormat, double publicType, double privateFormat, double privateType) = 0; - virtual std::shared_ptr getPublicKey() = 0; - virtual std::shared_ptr getPrivateKey() = 0; - virtual std::shared_ptr>> sign(const std::shared_ptr& message) = 0; - virtual std::shared_ptr signSync(const std::shared_ptr& message) = 0; - virtual std::shared_ptr> verify(const std::shared_ptr& signature, const std::shared_ptr& message) = 0; - virtual bool verifySync(const std::shared_ptr& signature, const std::shared_ptr& message) = 0; - virtual void setVariant(const std::string& variant) = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "SlhDsaKeyPair"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridTurboShakeSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridTurboShakeSpec.cpp index da6b1a09e..c2dde58f3 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridTurboShakeSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridTurboShakeSpec.cpp @@ -1,22 +1,14 @@ /// /// HybridTurboShakeSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridTurboShakeSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridTurboShakeSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("turboShake", &HybridTurboShakeSpec::turboShake); - prototype.registerHybridMethod("kangarooTwelve", &HybridTurboShakeSpec::kangarooTwelve); - }); - } + HybridTurboShakeSpec::~HybridTurboShakeSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridTurboShakeSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridTurboShakeSpec.hpp deleted file mode 100644 index 614216db4..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridTurboShakeSpec.hpp +++ /dev/null @@ -1,70 +0,0 @@ -/// -/// HybridTurboShakeSpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - -// Forward declaration of `TurboShakeVariant` to properly resolve imports. -namespace margelo::nitro::crypto { enum class TurboShakeVariant; } -// Forward declaration of `KangarooTwelveVariant` to properly resolve imports. -namespace margelo::nitro::crypto { enum class KangarooTwelveVariant; } - -#include -#include -#include "TurboShakeVariant.hpp" -#include "KangarooTwelveVariant.hpp" -#include - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `TurboShake` - * Inherit this class to create instances of `HybridTurboShakeSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridTurboShake: public HybridTurboShakeSpec { - * public: - * HybridTurboShake(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridTurboShakeSpec: public virtual HybridObject { - public: - // Constructor - explicit HybridTurboShakeSpec(): HybridObject(TAG) { } - - // Destructor - ~HybridTurboShakeSpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual std::shared_ptr>> turboShake(TurboShakeVariant variant, double domainSeparation, double outputLength, const std::shared_ptr& data) = 0; - virtual std::shared_ptr>> kangarooTwelve(KangarooTwelveVariant variant, double outputLength, const std::shared_ptr& data, const std::optional>& customization) = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "TurboShake"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridUtilsSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridUtilsSpec.cpp index a3cae7e48..928a0e047 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridUtilsSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridUtilsSpec.cpp @@ -1,21 +1,14 @@ /// /// HybridUtilsSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridUtilsSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridUtilsSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("timingSafeEqual", &HybridUtilsSpec::timingSafeEqual); - }); - } + HybridUtilsSpec::~HybridUtilsSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridUtilsSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridUtilsSpec.hpp deleted file mode 100644 index 904ae0c07..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridUtilsSpec.hpp +++ /dev/null @@ -1,62 +0,0 @@ -/// -/// HybridUtilsSpec.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - - - -#include - -namespace margelo::nitro::crypto { - - using namespace margelo::nitro; - - /** - * An abstract base class for `Utils` - * Inherit this class to create instances of `HybridUtilsSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. - * @example - * ```cpp - * class HybridUtils: public HybridUtilsSpec { - * public: - * HybridUtils(...): HybridObject(TAG) { ... } - * // ... - * }; - * ``` - */ - class HybridUtilsSpec: public virtual HybridObject { - public: - // Constructor - explicit HybridUtilsSpec(): HybridObject(TAG) { } - - // Destructor - ~HybridUtilsSpec() override = default; - - public: - // Properties - - - public: - // Methods - virtual bool timingSafeEqual(const std::shared_ptr& a, const std::shared_ptr& b) = 0; - - protected: - // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "Utils"; - }; - -} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridVerifyHandleSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridVerifyHandleSpec.cpp index f2fa1a8f4..4622ebf36 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridVerifyHandleSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridVerifyHandleSpec.cpp @@ -1,23 +1,14 @@ /// /// HybridVerifyHandleSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridVerifyHandleSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridVerifyHandleSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("init", &HybridVerifyHandleSpec::init); - prototype.registerHybridMethod("update", &HybridVerifyHandleSpec::update); - prototype.registerHybridMethod("verify", &HybridVerifyHandleSpec::verify); - }); - } + HybridVerifyHandleSpec::~HybridVerifyHandleSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridX509CertificateHandleSpec.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridX509CertificateHandleSpec.cpp index 853e5d6e2..fe10e60d5 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridX509CertificateHandleSpec.cpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridX509CertificateHandleSpec.cpp @@ -1,46 +1,14 @@ /// /// HybridX509CertificateHandleSpec.cpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// -#include "HybridX509CertificateHandleSpec.hpp" +#include namespace margelo::nitro::crypto { - void HybridX509CertificateHandleSpec::loadHybridMethods() { - // load base methods/properties - HybridObject::loadHybridMethods(); - // load custom methods/properties - registerHybrids(this, [](Prototype& prototype) { - prototype.registerHybridMethod("init", &HybridX509CertificateHandleSpec::init); - prototype.registerHybridMethod("subject", &HybridX509CertificateHandleSpec::subject); - prototype.registerHybridMethod("subjectAltName", &HybridX509CertificateHandleSpec::subjectAltName); - prototype.registerHybridMethod("issuer", &HybridX509CertificateHandleSpec::issuer); - prototype.registerHybridMethod("infoAccess", &HybridX509CertificateHandleSpec::infoAccess); - prototype.registerHybridMethod("validFrom", &HybridX509CertificateHandleSpec::validFrom); - prototype.registerHybridMethod("validTo", &HybridX509CertificateHandleSpec::validTo); - prototype.registerHybridMethod("validFromDate", &HybridX509CertificateHandleSpec::validFromDate); - prototype.registerHybridMethod("validToDate", &HybridX509CertificateHandleSpec::validToDate); - prototype.registerHybridMethod("signatureAlgorithm", &HybridX509CertificateHandleSpec::signatureAlgorithm); - prototype.registerHybridMethod("signatureAlgorithmOid", &HybridX509CertificateHandleSpec::signatureAlgorithmOid); - prototype.registerHybridMethod("serialNumber", &HybridX509CertificateHandleSpec::serialNumber); - prototype.registerHybridMethod("fingerprint", &HybridX509CertificateHandleSpec::fingerprint); - prototype.registerHybridMethod("fingerprint256", &HybridX509CertificateHandleSpec::fingerprint256); - prototype.registerHybridMethod("fingerprint512", &HybridX509CertificateHandleSpec::fingerprint512); - prototype.registerHybridMethod("raw", &HybridX509CertificateHandleSpec::raw); - prototype.registerHybridMethod("pem", &HybridX509CertificateHandleSpec::pem); - prototype.registerHybridMethod("publicKey", &HybridX509CertificateHandleSpec::publicKey); - prototype.registerHybridMethod("keyUsage", &HybridX509CertificateHandleSpec::keyUsage); - prototype.registerHybridMethod("ca", &HybridX509CertificateHandleSpec::ca); - prototype.registerHybridMethod("checkIssued", &HybridX509CertificateHandleSpec::checkIssued); - prototype.registerHybridMethod("checkPrivateKey", &HybridX509CertificateHandleSpec::checkPrivateKey); - prototype.registerHybridMethod("verify", &HybridX509CertificateHandleSpec::verify); - prototype.registerHybridMethod("checkHost", &HybridX509CertificateHandleSpec::checkHost); - prototype.registerHybridMethod("checkEmail", &HybridX509CertificateHandleSpec::checkEmail); - prototype.registerHybridMethod("checkIP", &HybridX509CertificateHandleSpec::checkIP); - }); - } + HybridX509CertificateHandleSpec::~HybridX509CertificateHandleSpec() = default; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/JWK.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/JWK.cpp new file mode 100644 index 000000000..a2bb23c24 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/JWK.cpp @@ -0,0 +1,114 @@ +/// +/// JWK.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace margelo::nitro { + + margelo::nitro::crypto::JWK JSIConverter::fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { + jsi::Object obj = arg.asObject(runtime); + return margelo::nitro::crypto::JWK( + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "kty"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "use"))), + JSIConverter>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "key_ops"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "alg"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "crv"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "kid"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x5u"))), + JSIConverter>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x5c"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x5t"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x5t#256"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "n"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "e"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "d"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "p"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "q"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "y"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "k"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "dp"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "dq"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "qi"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "pub"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "priv"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ext"))) + ); + } + + jsi::Value JSIConverter::toJSI(jsi::Runtime& runtime, const margelo::nitro::crypto::JWK& arg) { + jsi::Object obj(runtime); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "kty"), JSIConverter>::toJSI(runtime, arg.kty)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "use"), JSIConverter>::toJSI(runtime, arg.use)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "key_ops"), JSIConverter>>::toJSI(runtime, arg.key_ops)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "alg"), JSIConverter>::toJSI(runtime, arg.alg)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "crv"), JSIConverter>::toJSI(runtime, arg.crv)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "kid"), JSIConverter>::toJSI(runtime, arg.kid)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "x5u"), JSIConverter>::toJSI(runtime, arg.x5u)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "x5c"), JSIConverter>>::toJSI(runtime, arg.x5c)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "x5t"), JSIConverter>::toJSI(runtime, arg.x5t)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "x5t#256"), JSIConverter>::toJSI(runtime, arg.x5t_256)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "n"), JSIConverter>::toJSI(runtime, arg.n)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "e"), JSIConverter>::toJSI(runtime, arg.e)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "d"), JSIConverter>::toJSI(runtime, arg.d)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "p"), JSIConverter>::toJSI(runtime, arg.p)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "q"), JSIConverter>::toJSI(runtime, arg.q)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "x"), JSIConverter>::toJSI(runtime, arg.x)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "y"), JSIConverter>::toJSI(runtime, arg.y)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "k"), JSIConverter>::toJSI(runtime, arg.k)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "dp"), JSIConverter>::toJSI(runtime, arg.dp)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "dq"), JSIConverter>::toJSI(runtime, arg.dq)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "qi"), JSIConverter>::toJSI(runtime, arg.qi)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "pub"), JSIConverter>::toJSI(runtime, arg.pub)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "priv"), JSIConverter>::toJSI(runtime, arg.priv)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "ext"), JSIConverter>::toJSI(runtime, arg.ext)); + return obj; + } + + bool JSIConverter::canConvert(jsi::Runtime& runtime, const jsi::Value& value) { + if (!value.isObject()) { + return false; + } + jsi::Object obj = value.getObject(runtime); + if (!nitro::isPlainObject(runtime, obj)) { + return false; + } + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "kty")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "use")))) return false; + if (!JSIConverter>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "key_ops")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "alg")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "crv")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "kid")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x5u")))) return false; + if (!JSIConverter>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x5c")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x5t")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x5t#256")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "n")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "e")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "d")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "p")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "q")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "y")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "k")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "dp")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "dq")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "qi")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "pub")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "priv")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ext")))) return false; + return true; + } + +} // namespace margelo::nitro diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/JWK.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/JWK.hpp deleted file mode 100644 index 100ce480f..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/JWK.hpp +++ /dev/null @@ -1,185 +0,0 @@ -/// -/// JWK.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - -// Forward declaration of `JWKkty` to properly resolve imports. -namespace margelo::nitro::crypto { enum class JWKkty; } -// Forward declaration of `JWKuse` to properly resolve imports. -namespace margelo::nitro::crypto { enum class JWKuse; } -// Forward declaration of `KeyUsage` to properly resolve imports. -namespace margelo::nitro::crypto { enum class KeyUsage; } - -#include "JWKkty.hpp" -#include -#include "JWKuse.hpp" -#include "KeyUsage.hpp" -#include -#include - -namespace margelo::nitro::crypto { - - /** - * A struct which can be represented as a JavaScript object (JWK). - */ - struct JWK final { - public: - std::optional kty SWIFT_PRIVATE; - std::optional use SWIFT_PRIVATE; - std::optional> key_ops SWIFT_PRIVATE; - std::optional alg SWIFT_PRIVATE; - std::optional crv SWIFT_PRIVATE; - std::optional kid SWIFT_PRIVATE; - std::optional x5u SWIFT_PRIVATE; - std::optional> x5c SWIFT_PRIVATE; - std::optional x5t SWIFT_PRIVATE; - std::optional x5t_256 SWIFT_PRIVATE; - std::optional n SWIFT_PRIVATE; - std::optional e SWIFT_PRIVATE; - std::optional d SWIFT_PRIVATE; - std::optional p SWIFT_PRIVATE; - std::optional q SWIFT_PRIVATE; - std::optional x SWIFT_PRIVATE; - std::optional y SWIFT_PRIVATE; - std::optional k SWIFT_PRIVATE; - std::optional dp SWIFT_PRIVATE; - std::optional dq SWIFT_PRIVATE; - std::optional qi SWIFT_PRIVATE; - std::optional pub SWIFT_PRIVATE; - std::optional priv SWIFT_PRIVATE; - std::optional ext SWIFT_PRIVATE; - - public: - JWK() = default; - explicit JWK(std::optional kty, std::optional use, std::optional> key_ops, std::optional alg, std::optional crv, std::optional kid, std::optional x5u, std::optional> x5c, std::optional x5t, std::optional x5t_256, std::optional n, std::optional e, std::optional d, std::optional p, std::optional q, std::optional x, std::optional y, std::optional k, std::optional dp, std::optional dq, std::optional qi, std::optional pub, std::optional priv, std::optional 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), pub(pub), priv(priv), ext(ext) {} - - public: - friend bool operator==(const JWK& lhs, const JWK& rhs) = default; - }; - -} // namespace margelo::nitro::crypto - -namespace margelo::nitro { - - // C++ JWK <> JS JWK (object) - template <> - struct JSIConverter final { - static inline margelo::nitro::crypto::JWK fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { - jsi::Object obj = arg.asObject(runtime); - return margelo::nitro::crypto::JWK( - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "kty"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "use"))), - JSIConverter>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "key_ops"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "alg"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "crv"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "kid"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x5u"))), - JSIConverter>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x5c"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x5t"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x5t#256"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "n"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "e"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "d"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "p"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "q"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "y"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "k"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "dp"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "dq"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "qi"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "pub"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "priv"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ext"))) - ); - } - static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::crypto::JWK& arg) { - jsi::Object obj(runtime); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "kty"), JSIConverter>::toJSI(runtime, arg.kty)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "use"), JSIConverter>::toJSI(runtime, arg.use)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "key_ops"), JSIConverter>>::toJSI(runtime, arg.key_ops)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "alg"), JSIConverter>::toJSI(runtime, arg.alg)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "crv"), JSIConverter>::toJSI(runtime, arg.crv)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "kid"), JSIConverter>::toJSI(runtime, arg.kid)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "x5u"), JSIConverter>::toJSI(runtime, arg.x5u)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "x5c"), JSIConverter>>::toJSI(runtime, arg.x5c)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "x5t"), JSIConverter>::toJSI(runtime, arg.x5t)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "x5t#256"), JSIConverter>::toJSI(runtime, arg.x5t_256)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "n"), JSIConverter>::toJSI(runtime, arg.n)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "e"), JSIConverter>::toJSI(runtime, arg.e)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "d"), JSIConverter>::toJSI(runtime, arg.d)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "p"), JSIConverter>::toJSI(runtime, arg.p)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "q"), JSIConverter>::toJSI(runtime, arg.q)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "x"), JSIConverter>::toJSI(runtime, arg.x)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "y"), JSIConverter>::toJSI(runtime, arg.y)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "k"), JSIConverter>::toJSI(runtime, arg.k)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "dp"), JSIConverter>::toJSI(runtime, arg.dp)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "dq"), JSIConverter>::toJSI(runtime, arg.dq)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "qi"), JSIConverter>::toJSI(runtime, arg.qi)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "pub"), JSIConverter>::toJSI(runtime, arg.pub)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "priv"), JSIConverter>::toJSI(runtime, arg.priv)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "ext"), JSIConverter>::toJSI(runtime, arg.ext)); - return obj; - } - static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) { - if (!value.isObject()) { - return false; - } - jsi::Object obj = value.getObject(runtime); - if (!nitro::isPlainObject(runtime, obj)) { - return false; - } - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "kty")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "use")))) return false; - if (!JSIConverter>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "key_ops")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "alg")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "crv")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "kid")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x5u")))) return false; - if (!JSIConverter>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x5c")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x5t")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x5t#256")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "n")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "e")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "d")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "p")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "q")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "y")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "k")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "dp")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "dq")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "qi")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "pub")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "priv")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "ext")))) return false; - return true; - } - }; - -} // namespace margelo::nitro diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KeyDetail.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KeyDetail.cpp new file mode 100644 index 000000000..939982b72 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KeyDetail.cpp @@ -0,0 +1,59 @@ +/// +/// KeyDetail.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include +#include +#include + +namespace margelo::nitro { + + margelo::nitro::crypto::KeyDetail JSIConverter::fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { + jsi::Object obj = arg.asObject(runtime); + return margelo::nitro::crypto::KeyDetail( + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "length"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "publicExponent"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "modulusLength"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "hashAlgorithm"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mgf1HashAlgorithm"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "saltLength"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "namedCurve"))) + ); + } + + jsi::Value JSIConverter::toJSI(jsi::Runtime& runtime, const margelo::nitro::crypto::KeyDetail& arg) { + jsi::Object obj(runtime); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "length"), JSIConverter>::toJSI(runtime, arg.length)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "publicExponent"), JSIConverter>::toJSI(runtime, arg.publicExponent)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "modulusLength"), JSIConverter>::toJSI(runtime, arg.modulusLength)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "hashAlgorithm"), JSIConverter>::toJSI(runtime, arg.hashAlgorithm)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "mgf1HashAlgorithm"), JSIConverter>::toJSI(runtime, arg.mgf1HashAlgorithm)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "saltLength"), JSIConverter>::toJSI(runtime, arg.saltLength)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "namedCurve"), JSIConverter>::toJSI(runtime, arg.namedCurve)); + return obj; + } + + bool JSIConverter::canConvert(jsi::Runtime& runtime, const jsi::Value& value) { + if (!value.isObject()) { + return false; + } + jsi::Object obj = value.getObject(runtime); + if (!nitro::isPlainObject(runtime, obj)) { + return false; + } + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "length")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "publicExponent")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "modulusLength")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "hashAlgorithm")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mgf1HashAlgorithm")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "saltLength")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "namedCurve")))) return false; + return true; + } + +} // namespace margelo::nitro diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KeyDetail.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KeyDetail.hpp deleted file mode 100644 index 4ec385c79..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KeyDetail.hpp +++ /dev/null @@ -1,108 +0,0 @@ -/// -/// KeyDetail.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - - - -#include -#include - -namespace margelo::nitro::crypto { - - /** - * A struct which can be represented as a JavaScript object (KeyDetail). - */ - struct KeyDetail final { - public: - std::optional length SWIFT_PRIVATE; - std::optional publicExponent SWIFT_PRIVATE; - std::optional modulusLength SWIFT_PRIVATE; - std::optional hashAlgorithm SWIFT_PRIVATE; - std::optional mgf1HashAlgorithm SWIFT_PRIVATE; - std::optional saltLength SWIFT_PRIVATE; - std::optional namedCurve SWIFT_PRIVATE; - - public: - KeyDetail() = default; - explicit KeyDetail(std::optional length, std::optional publicExponent, std::optional modulusLength, std::optional hashAlgorithm, std::optional mgf1HashAlgorithm, std::optional saltLength, std::optional namedCurve): length(length), publicExponent(publicExponent), modulusLength(modulusLength), hashAlgorithm(hashAlgorithm), mgf1HashAlgorithm(mgf1HashAlgorithm), saltLength(saltLength), namedCurve(namedCurve) {} - - public: - friend bool operator==(const KeyDetail& lhs, const KeyDetail& rhs) = default; - }; - -} // namespace margelo::nitro::crypto - -namespace margelo::nitro { - - // C++ KeyDetail <> JS KeyDetail (object) - template <> - struct JSIConverter final { - static inline margelo::nitro::crypto::KeyDetail fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { - jsi::Object obj = arg.asObject(runtime); - return margelo::nitro::crypto::KeyDetail( - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "length"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "publicExponent"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "modulusLength"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "hashAlgorithm"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mgf1HashAlgorithm"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "saltLength"))), - JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "namedCurve"))) - ); - } - static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::crypto::KeyDetail& arg) { - jsi::Object obj(runtime); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "length"), JSIConverter>::toJSI(runtime, arg.length)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "publicExponent"), JSIConverter>::toJSI(runtime, arg.publicExponent)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "modulusLength"), JSIConverter>::toJSI(runtime, arg.modulusLength)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "hashAlgorithm"), JSIConverter>::toJSI(runtime, arg.hashAlgorithm)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "mgf1HashAlgorithm"), JSIConverter>::toJSI(runtime, arg.mgf1HashAlgorithm)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "saltLength"), JSIConverter>::toJSI(runtime, arg.saltLength)); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "namedCurve"), JSIConverter>::toJSI(runtime, arg.namedCurve)); - return obj; - } - static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) { - if (!value.isObject()) { - return false; - } - jsi::Object obj = value.getObject(runtime); - if (!nitro::isPlainObject(runtime, obj)) { - return false; - } - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "length")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "publicExponent")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "modulusLength")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "hashAlgorithm")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mgf1HashAlgorithm")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "saltLength")))) return false; - if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "namedCurve")))) return false; - return true; - } - }; - -} // namespace margelo::nitro diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KeyObject.cpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KeyObject.cpp new file mode 100644 index 000000000..a62abb40a --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KeyObject.cpp @@ -0,0 +1,39 @@ +/// +/// KeyObject.cpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#include +#include +#include + +namespace margelo::nitro { + + margelo::nitro::crypto::KeyObject JSIConverter::fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { + jsi::Object obj = arg.asObject(runtime); + return margelo::nitro::crypto::KeyObject( + JSIConverter::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "extractable"))) + ); + } + + jsi::Value JSIConverter::toJSI(jsi::Runtime& runtime, const margelo::nitro::crypto::KeyObject& arg) { + jsi::Object obj(runtime); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "extractable"), JSIConverter::toJSI(runtime, arg.extractable)); + return obj; + } + + bool JSIConverter::canConvert(jsi::Runtime& runtime, const jsi::Value& value) { + if (!value.isObject()) { + return false; + } + jsi::Object obj = value.getObject(runtime); + if (!nitro::isPlainObject(runtime, obj)) { + return false; + } + if (!JSIConverter::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "extractable")))) return false; + return true; + } + +} // namespace margelo::nitro diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KeyObject.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KeyObject.hpp deleted file mode 100644 index 92925f888..000000000 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KeyObject.hpp +++ /dev/null @@ -1,83 +0,0 @@ -/// -/// KeyObject.hpp -/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro -/// Copyright © Marc Rousavy @ Margelo -/// - -#pragma once - -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() -#include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - - - - - -namespace margelo::nitro::crypto { - - /** - * A struct which can be represented as a JavaScript object (KeyObject). - */ - struct KeyObject final { - public: - bool extractable SWIFT_PRIVATE; - - public: - KeyObject() = default; - explicit KeyObject(bool extractable): extractable(extractable) {} - - public: - friend bool operator==(const KeyObject& lhs, const KeyObject& rhs) = default; - }; - -} // namespace margelo::nitro::crypto - -namespace margelo::nitro { - - // C++ KeyObject <> JS KeyObject (object) - template <> - struct JSIConverter final { - static inline margelo::nitro::crypto::KeyObject fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { - jsi::Object obj = arg.asObject(runtime); - return margelo::nitro::crypto::KeyObject( - JSIConverter::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "extractable"))) - ); - } - static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::crypto::KeyObject& arg) { - jsi::Object obj(runtime); - obj.setProperty(runtime, PropNameIDCache::get(runtime, "extractable"), JSIConverter::toJSI(runtime, arg.extractable)); - return obj; - } - static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) { - if (!value.isObject()) { - return false; - } - jsi::Object obj = value.getObject(runtime); - if (!nitro::isPlainObject(runtime, obj)) { - return false; - } - if (!JSIConverter::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "extractable")))) return false; - return true; - } - }; - -} // namespace margelo::nitro diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/AsymmetricKeyType.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/AsymmetricKeyType.hpp similarity index 95% rename from packages/react-native-quick-crypto/nitrogen/generated/shared/c++/AsymmetricKeyType.hpp rename to packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/AsymmetricKeyType.hpp index e2349aa92..25dc54179 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/AsymmetricKeyType.hpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/AsymmetricKeyType.hpp @@ -1,27 +1,15 @@ /// /// AsymmetricKeyType.hpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// #pragma once -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif namespace margelo::nitro::crypto { diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/CipherArgs.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/CipherArgs.hpp new file mode 100644 index 000000000..65e352415 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/CipherArgs.hpp @@ -0,0 +1,49 @@ +/// +/// CipherArgs.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace margelo::nitro::crypto { + + /** + * A struct which can be represented as a JavaScript object (CipherArgs). + */ + struct CipherArgs final { + public: + bool isCipher SWIFT_PRIVATE; + std::string cipherType SWIFT_PRIVATE; + ArrayBuffer cipherKey SWIFT_PRIVATE; + ArrayBuffer iv SWIFT_PRIVATE; + std::optional authTagLen SWIFT_PRIVATE; + + public: + explicit CipherArgs(bool isCipher, std::string cipherType, ArrayBuffer cipherKey, ArrayBuffer iv, std::optional authTagLen): isCipher(isCipher), cipherType(std::move(cipherType)), cipherKey(std::move(cipherKey)), iv(std::move(iv)), authTagLen(std::move(authTagLen)) {} + + public: + friend bool operator==(const CipherArgs& lhs, const CipherArgs& rhs) = default; + }; + +} // namespace margelo::nitro::crypto + +namespace margelo::nitro { + + // C++ CipherArgs <> JS CipherArgs (object) + template <> + struct JSIConverter final { + static margelo::nitro::crypto::CipherArgs fromJSI(jsi::Runtime& runtime, const jsi::Value& arg); + static jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::crypto::CipherArgs& arg); + static bool canConvert(jsi::Runtime& runtime, const jsi::Value& value); + }; + +} // namespace margelo::nitro diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/CipherInfo.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/CipherInfo.hpp new file mode 100644 index 000000000..15e35400d --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/CipherInfo.hpp @@ -0,0 +1,49 @@ +/// +/// CipherInfo.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include +#include + +namespace margelo::nitro::crypto { + + /** + * A struct which can be represented as a JavaScript object (CipherInfo). + */ + struct CipherInfo final { + public: + std::string name SWIFT_PRIVATE; + double nid SWIFT_PRIVATE; + std::string mode SWIFT_PRIVATE; + double keyLength SWIFT_PRIVATE; + std::optional blockSize SWIFT_PRIVATE; + std::optional ivLength SWIFT_PRIVATE; + + public: + explicit CipherInfo(std::string name, double nid, std::string mode, double keyLength, std::optional blockSize, std::optional ivLength): name(std::move(name)), nid(nid), mode(std::move(mode)), keyLength(keyLength), blockSize(std::move(blockSize)), ivLength(std::move(ivLength)) {} + + public: + friend bool operator==(const CipherInfo& lhs, const CipherInfo& rhs) = default; + }; + +} // namespace margelo::nitro::crypto + +namespace margelo::nitro { + + // C++ CipherInfo <> JS CipherInfo (object) + template <> + struct JSIConverter final { + static margelo::nitro::crypto::CipherInfo fromJSI(jsi::Runtime& runtime, const jsi::Value& arg); + static jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::crypto::CipherInfo& arg); + static bool canConvert(jsi::Runtime& runtime, const jsi::Value& value); + }; + +} // namespace margelo::nitro diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HkdfMode.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HkdfMode.hpp similarity index 84% rename from packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HkdfMode.hpp rename to packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HkdfMode.hpp index e159ca26a..befdbc5cc 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HkdfMode.hpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HkdfMode.hpp @@ -1,27 +1,15 @@ /// /// HkdfMode.hpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// #pragma once -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif namespace margelo::nitro::crypto { diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridArgon2Spec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridArgon2Spec.hpp new file mode 100644 index 000000000..a6050fed5 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridArgon2Spec.hpp @@ -0,0 +1,63 @@ +/// +/// HybridArgon2Spec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `Argon2` + * Inherit this class to create instances of `HybridArgon2Spec` in C++. + * @example + * ```cpp + * class HybridArgon2 : public HybridArgon2Spec { + * public: + * HybridArgon2(...) { ... } + * // ... + * }; + * ``` + */ + class HybridArgon2Spec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "Argon2"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridArgon2Spec() = default; + + // Destructor + ~HybridArgon2Spec() override; + + public: + // Properties + + + public: + // Methods + + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridBlake3Spec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridBlake3Spec.hpp similarity index 52% rename from packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridBlake3Spec.hpp rename to packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridBlake3Spec.hpp index 59d18af42..cd4895f72 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridBlake3Spec.hpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridBlake3Spec.hpp @@ -1,26 +1,20 @@ /// /// HybridBlake3Spec.hpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// #pragma once -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - -// Forward declaration of `HybridBlake3Spec` to properly resolve imports. -namespace margelo::nitro::crypto { class HybridBlake3Spec; } - +#include #include #include #include #include -#include "HybridBlake3Spec.hpp" +// Forward declaration of `HybridBlake3Spec` to properly resolve imports. +namespace margelo::nitro::crypto { class HybridBlake3Spec; } namespace margelo::nitro::crypto { @@ -29,46 +23,49 @@ namespace margelo::nitro::crypto { /** * An abstract base class for `Blake3` * Inherit this class to create instances of `HybridBlake3Spec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. * @example * ```cpp - * class HybridBlake3: public HybridBlake3Spec { + * class HybridBlake3 : public HybridBlake3Spec { * public: - * HybridBlake3(...): HybridObject(TAG) { ... } + * HybridBlake3(...) { ... } * // ... * }; * ``` */ - class HybridBlake3Spec: public virtual HybridObject { + class HybridBlake3Spec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "Blake3"; + static const std::shared_ptr& get(); + }; + public: // Constructor - explicit HybridBlake3Spec(): HybridObject(TAG) { } + HybridBlake3Spec() = default; // Destructor - ~HybridBlake3Spec() override = default; + ~HybridBlake3Spec() override; public: // Properties - + public: // Methods virtual void initHash() = 0; - virtual void initKeyed(const std::shared_ptr& key) = 0; + virtual void initKeyed(const ArrayBuffer& key) = 0; virtual void initDeriveKey(const std::string& context) = 0; - virtual void update(const std::shared_ptr& data) = 0; - virtual std::shared_ptr digest(std::optional length) = 0; + virtual void update(const ArrayBuffer& data) = 0; + virtual ArrayBuffer digest(const std::optional& length) = 0; virtual void reset() = 0; virtual std::shared_ptr copy() = 0; - virtual std::string getVersion() = 0; protected: // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "Blake3"; + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } }; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridCertificateSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridCertificateSpec.hpp new file mode 100644 index 000000000..6a2e753f3 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridCertificateSpec.hpp @@ -0,0 +1,60 @@ +/// +/// HybridCertificateSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `Certificate` + * Inherit this class to create instances of `HybridCertificateSpec` in C++. + * @example + * ```cpp + * class HybridCertificate : public HybridCertificateSpec { + * public: + * HybridCertificate(...) { ... } + * // ... + * }; + * ``` + */ + class HybridCertificateSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "Certificate"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridCertificateSpec() = default; + + // Destructor + ~HybridCertificateSpec() override; + + public: + // Properties + + + public: + // Methods + + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridCipherFactorySpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridCipherFactorySpec.hpp new file mode 100644 index 000000000..a002739a7 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridCipherFactorySpec.hpp @@ -0,0 +1,63 @@ +/// +/// HybridCipherFactorySpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +// Forward declaration of `HybridCipherSpec` to properly resolve imports. +namespace margelo::nitro::crypto { class HybridCipherSpec; } +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `CipherFactory` + * Inherit this class to create instances of `HybridCipherFactorySpec` in C++. + * @example + * ```cpp + * class HybridCipherFactory : public HybridCipherFactorySpec { + * public: + * HybridCipherFactory(...) { ... } + * // ... + * }; + * ``` + */ + class HybridCipherFactorySpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "CipherFactory"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridCipherFactorySpec() = default; + + // Destructor + ~HybridCipherFactorySpec() override; + + public: + // Properties + + + public: + // Methods + + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridCipherSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridCipherSpec.hpp new file mode 100644 index 000000000..7da5b7ca2 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridCipherSpec.hpp @@ -0,0 +1,71 @@ +/// +/// HybridCipherSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `Cipher` + * Inherit this class to create instances of `HybridCipherSpec` in C++. + * @example + * ```cpp + * class HybridCipher : public HybridCipherSpec { + * public: + * HybridCipher(...) { ... } + * // ... + * }; + * ``` + */ + class HybridCipherSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "Cipher"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridCipherSpec() = default; + + // Destructor + ~HybridCipherSpec() override; + + public: + // Properties + + + public: + // Methods + virtual ArrayBuffer update(const ArrayBuffer& data) = 0; + virtual ArrayBuffer final() = 0; + virtual void setArgs(const CipherArgs& args) = 0; + virtual bool setAAD(const ArrayBuffer& data, const std::optional& plaintextLength) = 0; + virtual bool setAutoPadding(bool autoPad) = 0; + virtual bool setAuthTag(const ArrayBuffer& tag) = 0; + virtual ArrayBuffer getAuthTag() = 0; + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridDhKeyPairSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridDhKeyPairSpec.hpp new file mode 100644 index 000000000..a622da06a --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridDhKeyPairSpec.hpp @@ -0,0 +1,67 @@ +/// +/// HybridDhKeyPairSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `DhKeyPair` + * Inherit this class to create instances of `HybridDhKeyPairSpec` in C++. + * @example + * ```cpp + * class HybridDhKeyPair : public HybridDhKeyPairSpec { + * public: + * HybridDhKeyPair(...) { ... } + * // ... + * }; + * ``` + */ + class HybridDhKeyPairSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "DhKeyPair"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridDhKeyPairSpec() = default; + + // Destructor + ~HybridDhKeyPairSpec() override; + + public: + // Properties + + + public: + // Methods + virtual Promise generateKeyPair() = 0; + virtual void generateKeyPairSync() = 0; + virtual void setPrimeLength(double primeLength) = 0; + virtual void setPrime(const ArrayBuffer& prime) = 0; + virtual void setGenerator(double generator) = 0; + virtual ArrayBuffer getPublicKey() = 0; + virtual ArrayBuffer getPrivateKey() = 0; + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridDiffieHellmanSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridDiffieHellmanSpec.hpp new file mode 100644 index 000000000..8c1b31d53 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridDiffieHellmanSpec.hpp @@ -0,0 +1,70 @@ +/// +/// HybridDiffieHellmanSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `DiffieHellman` + * Inherit this class to create instances of `HybridDiffieHellmanSpec` in C++. + * @example + * ```cpp + * class HybridDiffieHellman : public HybridDiffieHellmanSpec { + * public: + * HybridDiffieHellman(...) { ... } + * // ... + * }; + * ``` + */ + class HybridDiffieHellmanSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "DiffieHellman"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridDiffieHellmanSpec() = default; + + // Destructor + ~HybridDiffieHellmanSpec() override; + + public: + // Properties + + + public: + // Methods + virtual void init(const ArrayBuffer& prime, const ArrayBuffer& generator) = 0; + virtual void initWithSize(double primeLength, double generator) = 0; + virtual ArrayBuffer generateKeys() = 0; + virtual ArrayBuffer computeSecret(const ArrayBuffer& otherPublicKey) = 0; + virtual ArrayBuffer getPrime() = 0; + virtual ArrayBuffer getGenerator() = 0; + virtual ArrayBuffer getPublicKey() = 0; + virtual ArrayBuffer getPrivateKey() = 0; + virtual void setPublicKey(const ArrayBuffer& publicKey) = 0; + virtual void setPrivateKey(const ArrayBuffer& privateKey) = 0; + virtual double getVerifyError() = 0; + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridDsaKeyPairSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridDsaKeyPairSpec.hpp similarity index 50% rename from packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridDsaKeyPairSpec.hpp rename to packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridDsaKeyPairSpec.hpp index 285a91d51..36f7d3ce0 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridDsaKeyPairSpec.hpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridDsaKeyPairSpec.hpp @@ -1,20 +1,14 @@ /// /// HybridDsaKeyPairSpec.hpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// #pragma once -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - - - +#include #include #include @@ -25,44 +19,48 @@ namespace margelo::nitro::crypto { /** * An abstract base class for `DsaKeyPair` * Inherit this class to create instances of `HybridDsaKeyPairSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. * @example * ```cpp - * class HybridDsaKeyPair: public HybridDsaKeyPairSpec { + * class HybridDsaKeyPair : public HybridDsaKeyPairSpec { * public: - * HybridDsaKeyPair(...): HybridObject(TAG) { ... } + * HybridDsaKeyPair(...) { ... } * // ... * }; * ``` */ - class HybridDsaKeyPairSpec: public virtual HybridObject { + class HybridDsaKeyPairSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "DsaKeyPair"; + static const std::shared_ptr& get(); + }; + public: // Constructor - explicit HybridDsaKeyPairSpec(): HybridObject(TAG) { } + HybridDsaKeyPairSpec() = default; // Destructor - ~HybridDsaKeyPairSpec() override = default; + ~HybridDsaKeyPairSpec() override; public: // Properties - + public: // Methods - virtual std::shared_ptr> generateKeyPair() = 0; + virtual Promise generateKeyPair() = 0; virtual void generateKeyPairSync() = 0; virtual void setModulusLength(double modulusLength) = 0; virtual void setDivisorLength(double divisorLength) = 0; - virtual std::shared_ptr getPublicKey() = 0; - virtual std::shared_ptr getPrivateKey() = 0; + virtual ArrayBuffer getPublicKey() = 0; + virtual ArrayBuffer getPrivateKey() = 0; protected: // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "DsaKeyPair"; + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } }; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridECDHSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridECDHSpec.hpp new file mode 100644 index 000000000..fa24d4715 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridECDHSpec.hpp @@ -0,0 +1,67 @@ +/// +/// HybridECDHSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `ECDH` + * Inherit this class to create instances of `HybridECDHSpec` in C++. + * @example + * ```cpp + * class HybridECDH : public HybridECDHSpec { + * public: + * HybridECDH(...) { ... } + * // ... + * }; + * ``` + */ + class HybridECDHSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "ECDH"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridECDHSpec() = default; + + // Destructor + ~HybridECDHSpec() override; + + public: + // Properties + + + public: + // Methods + virtual void init(const std::string& curveName) = 0; + virtual ArrayBuffer generateKeys() = 0; + virtual ArrayBuffer computeSecret(const ArrayBuffer& otherPublicKey) = 0; + virtual ArrayBuffer getPrivateKey() = 0; + virtual void setPrivateKey(const ArrayBuffer& privateKey) = 0; + virtual ArrayBuffer getPublicKey() = 0; + virtual void setPublicKey(const ArrayBuffer& publicKey) = 0; + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridEcKeyPairSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridEcKeyPairSpec.hpp new file mode 100644 index 000000000..7644fa293 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridEcKeyPairSpec.hpp @@ -0,0 +1,72 @@ +/// +/// HybridEcKeyPairSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `EcKeyPair` + * Inherit this class to create instances of `HybridEcKeyPairSpec` in C++. + * @example + * ```cpp + * class HybridEcKeyPair : public HybridEcKeyPairSpec { + * public: + * HybridEcKeyPair(...) { ... } + * // ... + * }; + * ``` + */ + class HybridEcKeyPairSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "EcKeyPair"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridEcKeyPairSpec() = default; + + // Destructor + ~HybridEcKeyPairSpec() override; + + public: + // Properties + + + public: + // Methods + virtual Promise generateKeyPair() = 0; + virtual void generateKeyPairSync() = 0; + virtual KeyObject importKey(const std::string& format, const ArrayBuffer& keyData, const std::string& algorithm, bool extractable, const std::vector& keyUsages) = 0; + virtual ArrayBuffer exportKey(const KeyObject& key, const std::string& format) = 0; + virtual ArrayBuffer getPublicKey() = 0; + virtual ArrayBuffer getPrivateKey() = 0; + virtual void setCurve(const std::string& curve) = 0; + virtual ArrayBuffer sign(const ArrayBuffer& data, const std::string& hashAlgorithm) = 0; + virtual bool verify(const ArrayBuffer& data, const ArrayBuffer& signature, const std::string& hashAlgorithm) = 0; + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridEdKeyPairSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridEdKeyPairSpec.hpp new file mode 100644 index 000000000..17fb58bcb --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridEdKeyPairSpec.hpp @@ -0,0 +1,72 @@ +/// +/// HybridEdKeyPairSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `EdKeyPair` + * Inherit this class to create instances of `HybridEdKeyPairSpec` in C++. + * @example + * ```cpp + * class HybridEdKeyPair : public HybridEdKeyPairSpec { + * public: + * HybridEdKeyPair(...) { ... } + * // ... + * }; + * ``` + */ + class HybridEdKeyPairSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "EdKeyPair"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridEdKeyPairSpec() = default; + + // Destructor + ~HybridEdKeyPairSpec() override; + + public: + // Properties + + + public: + // Methods + virtual ArrayBuffer diffieHellman(const ArrayBuffer& privateKey, const ArrayBuffer& publicKey) = 0; + virtual Promise generateKeyPair(double publicFormat, double publicType, double privateFormat, double privateType, const std::optional& cipher, const std::optional& passphrase) = 0; + virtual void generateKeyPairSync(double publicFormat, double publicType, double privateFormat, double privateType, const std::optional& cipher, const std::optional& passphrase) = 0; + virtual ArrayBuffer getPublicKey() = 0; + virtual ArrayBuffer getPrivateKey() = 0; + virtual Promise sign(const ArrayBuffer& message, const std::optional& key) = 0; + virtual ArrayBuffer signSync(const ArrayBuffer& message, const std::optional& key) = 0; + virtual Promise verify(const ArrayBuffer& signature, const ArrayBuffer& message, const std::optional& key) = 0; + virtual bool verifySync(const ArrayBuffer& signature, const ArrayBuffer& message, const std::optional& key) = 0; + virtual void setCurve(const std::string& curve) = 0; + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridHashSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridHashSpec.hpp new file mode 100644 index 000000000..e65480f35 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridHashSpec.hpp @@ -0,0 +1,70 @@ +/// +/// HybridHashSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +// Forward declaration of `HybridHashSpec` to properly resolve imports. +namespace margelo::nitro::crypto { class HybridHashSpec; } +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `Hash` + * Inherit this class to create instances of `HybridHashSpec` in C++. + * @example + * ```cpp + * class HybridHash : public HybridHashSpec { + * public: + * HybridHash(...) { ... } + * // ... + * }; + * ``` + */ + class HybridHashSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "Hash"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridHashSpec() = default; + + // Destructor + ~HybridHashSpec() override; + + public: + // Properties + + + public: + // Methods + virtual void createHash(const std::string& algorithm, const std::optional& outputLength) = 0; + virtual void update(const std::variant& data) = 0; + virtual ArrayBuffer digest(const std::optional& encoding) = 0; + virtual std::shared_ptr copy(const std::optional& outputLength) = 0; + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridHkdfSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridHkdfSpec.hpp new file mode 100644 index 000000000..6e9b1fe66 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridHkdfSpec.hpp @@ -0,0 +1,63 @@ +/// +/// HybridHkdfSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `Hkdf` + * Inherit this class to create instances of `HybridHkdfSpec` in C++. + * @example + * ```cpp + * class HybridHkdf : public HybridHkdfSpec { + * public: + * HybridHkdf(...) { ... } + * // ... + * }; + * ``` + */ + class HybridHkdfSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "Hkdf"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridHkdfSpec() = default; + + // Destructor + ~HybridHkdfSpec() override; + + public: + // Properties + + + public: + // Methods + + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridHmacSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridHmacSpec.hpp new file mode 100644 index 000000000..501dd7397 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridHmacSpec.hpp @@ -0,0 +1,64 @@ +/// +/// HybridHmacSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `Hmac` + * Inherit this class to create instances of `HybridHmacSpec` in C++. + * @example + * ```cpp + * class HybridHmac : public HybridHmacSpec { + * public: + * HybridHmac(...) { ... } + * // ... + * }; + * ``` + */ + class HybridHmacSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "Hmac"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridHmacSpec() = default; + + // Destructor + ~HybridHmacSpec() override; + + public: + // Properties + + + public: + // Methods + virtual void createHmac(const std::string& algorithm, const ArrayBuffer& key) = 0; + virtual void update(const std::variant& data) = 0; + virtual ArrayBuffer digest() = 0; + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridKeyObjectHandleSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridKeyObjectHandleSpec.hpp new file mode 100644 index 000000000..a9afd18f7 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridKeyObjectHandleSpec.hpp @@ -0,0 +1,91 @@ +/// +/// HybridKeyObjectHandleSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +// Forward declaration of `HybridKeyObjectHandleSpec` to properly resolve imports. +namespace margelo::nitro::crypto { class HybridKeyObjectHandleSpec; } + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `KeyObjectHandle` + * Inherit this class to create instances of `HybridKeyObjectHandleSpec` in C++. + * @example + * ```cpp + * class HybridKeyObjectHandle : public HybridKeyObjectHandleSpec { + * public: + * HybridKeyObjectHandle(...) { ... } + * // ... + * }; + * ``` + */ + class HybridKeyObjectHandleSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "KeyObjectHandle"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridKeyObjectHandleSpec() = default; + + // Destructor + ~HybridKeyObjectHandleSpec() override; + + public: + // Properties + + + public: + // Methods + virtual ArrayBuffer exportKey(const std::optional& format, const std::optional& type, const std::optional& cipher, const std::optional& passphrase) = 0; + virtual JWK exportJwk(const JWK& key, bool handleRsaPss) = 0; + virtual ArrayBuffer exportRawPublic() = 0; + virtual ArrayBuffer exportRawPrivate() = 0; + virtual ArrayBuffer exportRawSeed() = 0; + virtual ArrayBuffer exportECPublicRaw(bool compressed) = 0; + virtual ArrayBuffer exportECPrivateRaw() = 0; + virtual AsymmetricKeyType getAsymmetricKeyType() = 0; + virtual bool init(KeyType keyType, const std::variant& key, const std::optional& format, const std::optional& type, const std::optional& passphrase) = 0; + virtual bool initECRaw(const std::string& namedCurve, const ArrayBuffer& keyData) = 0; + virtual bool initPqcRaw(const std::string& algorithmName, const ArrayBuffer& keyData, bool isPublic) = 0; + virtual bool initRawPublic(const std::string& asymmetricKeyType, const ArrayBuffer& keyData, const std::optional& namedCurve) = 0; + virtual bool initRawPrivate(const std::string& asymmetricKeyType, const ArrayBuffer& keyData, const std::optional& namedCurve) = 0; + virtual bool initRawSeed(const std::string& asymmetricKeyType, const ArrayBuffer& keyData) = 0; + virtual std::optional initJwk(const JWK& keyData, const std::optional& namedCurve) = 0; + virtual KeyDetail keyDetail() = 0; + virtual bool keyEquals(const std::shared_ptr& other) = 0; + virtual double getSymmetricKeySize() = 0; + virtual bool checkEcKeyData() = 0; + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridKmacSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridKmacSpec.hpp new file mode 100644 index 000000000..f6570603e --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridKmacSpec.hpp @@ -0,0 +1,64 @@ +/// +/// HybridKmacSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `Kmac` + * Inherit this class to create instances of `HybridKmacSpec` in C++. + * @example + * ```cpp + * class HybridKmac : public HybridKmacSpec { + * public: + * HybridKmac(...) { ... } + * // ... + * }; + * ``` + */ + class HybridKmacSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "Kmac"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridKmacSpec() = default; + + // Destructor + ~HybridKmacSpec() override; + + public: + // Properties + + + public: + // Methods + virtual void createKmac(const std::string& algorithm, const ArrayBuffer& key, double outputLength, const std::optional& customization) = 0; + virtual void update(const ArrayBuffer& data) = 0; + virtual ArrayBuffer digest() = 0; + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridMlDsaKeyPairSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridMlDsaKeyPairSpec.hpp new file mode 100644 index 000000000..21fe09eab --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridMlDsaKeyPairSpec.hpp @@ -0,0 +1,70 @@ +/// +/// HybridMlDsaKeyPairSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `MlDsaKeyPair` + * Inherit this class to create instances of `HybridMlDsaKeyPairSpec` in C++. + * @example + * ```cpp + * class HybridMlDsaKeyPair : public HybridMlDsaKeyPairSpec { + * public: + * HybridMlDsaKeyPair(...) { ... } + * // ... + * }; + * ``` + */ + class HybridMlDsaKeyPairSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "MlDsaKeyPair"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridMlDsaKeyPairSpec() = default; + + // Destructor + ~HybridMlDsaKeyPairSpec() override; + + public: + // Properties + + + public: + // Methods + virtual Promise generateKeyPair(double publicFormat, double publicType, double privateFormat, double privateType) = 0; + virtual void generateKeyPairSync(double publicFormat, double publicType, double privateFormat, double privateType) = 0; + virtual ArrayBuffer getPublicKey() = 0; + virtual ArrayBuffer getPrivateKey() = 0; + virtual Promise sign(const ArrayBuffer& message) = 0; + virtual ArrayBuffer signSync(const ArrayBuffer& message) = 0; + virtual Promise verify(const ArrayBuffer& signature, const ArrayBuffer& message) = 0; + virtual bool verifySync(const ArrayBuffer& signature, const ArrayBuffer& message) = 0; + virtual void setVariant(const std::string& variant) = 0; + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridMlKemKeyPairSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridMlKemKeyPairSpec.hpp new file mode 100644 index 000000000..a05148192 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridMlKemKeyPairSpec.hpp @@ -0,0 +1,72 @@ +/// +/// HybridMlKemKeyPairSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `MlKemKeyPair` + * Inherit this class to create instances of `HybridMlKemKeyPairSpec` in C++. + * @example + * ```cpp + * class HybridMlKemKeyPair : public HybridMlKemKeyPairSpec { + * public: + * HybridMlKemKeyPair(...) { ... } + * // ... + * }; + * ``` + */ + class HybridMlKemKeyPairSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "MlKemKeyPair"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridMlKemKeyPairSpec() = default; + + // Destructor + ~HybridMlKemKeyPairSpec() override; + + public: + // Properties + + + public: + // Methods + virtual void setVariant(const std::string& variant) = 0; + virtual Promise generateKeyPair(double publicFormat, double publicType, double privateFormat, double privateType) = 0; + virtual void generateKeyPairSync(double publicFormat, double publicType, double privateFormat, double privateType) = 0; + virtual ArrayBuffer getPublicKey() = 0; + virtual ArrayBuffer getPrivateKey() = 0; + virtual void setPublicKey(const ArrayBuffer& keyData, double format, double type) = 0; + virtual void setPrivateKey(const ArrayBuffer& keyData, double format, double type) = 0; + virtual Promise encapsulate() = 0; + virtual ArrayBuffer encapsulateSync() = 0; + virtual Promise decapsulate(const ArrayBuffer& ciphertext) = 0; + virtual ArrayBuffer decapsulateSync(const ArrayBuffer& ciphertext) = 0; + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridPbkdf2Spec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridPbkdf2Spec.hpp new file mode 100644 index 000000000..564885f66 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridPbkdf2Spec.hpp @@ -0,0 +1,62 @@ +/// +/// HybridPbkdf2Spec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `Pbkdf2` + * Inherit this class to create instances of `HybridPbkdf2Spec` in C++. + * @example + * ```cpp + * class HybridPbkdf2 : public HybridPbkdf2Spec { + * public: + * HybridPbkdf2(...) { ... } + * // ... + * }; + * ``` + */ + class HybridPbkdf2Spec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "Pbkdf2"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridPbkdf2Spec() = default; + + // Destructor + ~HybridPbkdf2Spec() override; + + public: + // Properties + + + public: + // Methods + + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridPrimeSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridPrimeSpec.hpp new file mode 100644 index 000000000..fe730261c --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridPrimeSpec.hpp @@ -0,0 +1,62 @@ +/// +/// HybridPrimeSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `Prime` + * Inherit this class to create instances of `HybridPrimeSpec` in C++. + * @example + * ```cpp + * class HybridPrime : public HybridPrimeSpec { + * public: + * HybridPrime(...) { ... } + * // ... + * }; + * ``` + */ + class HybridPrimeSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "Prime"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridPrimeSpec() = default; + + // Destructor + ~HybridPrimeSpec() override; + + public: + // Properties + + + public: + // Methods + + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridRandomSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridRandomSpec.hpp new file mode 100644 index 000000000..1568c80ba --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridRandomSpec.hpp @@ -0,0 +1,61 @@ +/// +/// HybridRandomSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `Random` + * Inherit this class to create instances of `HybridRandomSpec` in C++. + * @example + * ```cpp + * class HybridRandom : public HybridRandomSpec { + * public: + * HybridRandom(...) { ... } + * // ... + * }; + * ``` + */ + class HybridRandomSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "Random"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridRandomSpec() = default; + + // Destructor + ~HybridRandomSpec() override; + + public: + // Properties + + + public: + // Methods + + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridRsaCipherSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridRsaCipherSpec.hpp new file mode 100644 index 000000000..7b547a4ad --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridRsaCipherSpec.hpp @@ -0,0 +1,65 @@ +/// +/// HybridRsaCipherSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include +// Forward declaration of `HybridKeyObjectHandleSpec` to properly resolve imports. +namespace margelo::nitro::crypto { class HybridKeyObjectHandleSpec; } +#include +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `RsaCipher` + * Inherit this class to create instances of `HybridRsaCipherSpec` in C++. + * @example + * ```cpp + * class HybridRsaCipher : public HybridRsaCipherSpec { + * public: + * HybridRsaCipher(...) { ... } + * // ... + * }; + * ``` + */ + class HybridRsaCipherSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "RsaCipher"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridRsaCipherSpec() = default; + + // Destructor + ~HybridRsaCipherSpec() override; + + public: + // Properties + + + public: + // Methods + + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridRsaKeyPairSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridRsaKeyPairSpec.hpp new file mode 100644 index 000000000..171812b59 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridRsaKeyPairSpec.hpp @@ -0,0 +1,72 @@ +/// +/// HybridRsaKeyPairSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `RsaKeyPair` + * Inherit this class to create instances of `HybridRsaKeyPairSpec` in C++. + * @example + * ```cpp + * class HybridRsaKeyPair : public HybridRsaKeyPairSpec { + * public: + * HybridRsaKeyPair(...) { ... } + * // ... + * }; + * ``` + */ + class HybridRsaKeyPairSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "RsaKeyPair"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridRsaKeyPairSpec() = default; + + // Destructor + ~HybridRsaKeyPairSpec() override; + + public: + // Properties + + + public: + // Methods + virtual Promise generateKeyPair() = 0; + virtual void generateKeyPairSync() = 0; + virtual void setModulusLength(double modulusLength) = 0; + virtual void setPublicExponent(const ArrayBuffer& publicExponent) = 0; + virtual void setHashAlgorithm(const std::string& hashAlgorithm) = 0; + virtual KeyObject importKey(const std::string& format, const ArrayBuffer& keyData, const std::string& algorithm, bool extractable, const std::vector& keyUsages) = 0; + virtual ArrayBuffer exportKey(const KeyObject& key, const std::string& format) = 0; + virtual ArrayBuffer getPublicKey() = 0; + virtual ArrayBuffer getPrivateKey() = 0; + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridScryptSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridScryptSpec.hpp new file mode 100644 index 000000000..4059ebd03 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridScryptSpec.hpp @@ -0,0 +1,61 @@ +/// +/// HybridScryptSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `Scrypt` + * Inherit this class to create instances of `HybridScryptSpec` in C++. + * @example + * ```cpp + * class HybridScrypt : public HybridScryptSpec { + * public: + * HybridScrypt(...) { ... } + * // ... + * }; + * ``` + */ + class HybridScryptSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "Scrypt"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridScryptSpec() = default; + + // Destructor + ~HybridScryptSpec() override; + + public: + // Properties + + + public: + // Methods + + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridSignHandleSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridSignHandleSpec.hpp new file mode 100644 index 000000000..8c92529a1 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridSignHandleSpec.hpp @@ -0,0 +1,67 @@ +/// +/// HybridSignHandleSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include +#include +// Forward declaration of `HybridKeyObjectHandleSpec` to properly resolve imports. +namespace margelo::nitro::crypto { class HybridKeyObjectHandleSpec; } +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `SignHandle` + * Inherit this class to create instances of `HybridSignHandleSpec` in C++. + * @example + * ```cpp + * class HybridSignHandle : public HybridSignHandleSpec { + * public: + * HybridSignHandle(...) { ... } + * // ... + * }; + * ``` + */ + class HybridSignHandleSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "SignHandle"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridSignHandleSpec() = default; + + // Destructor + ~HybridSignHandleSpec() override; + + public: + // Properties + + + public: + // Methods + virtual void init(const std::string& algorithm) = 0; + virtual void update(const ArrayBuffer& data) = 0; + virtual ArrayBuffer sign(const std::shared_ptr& keyHandle, const std::optional& padding, const std::optional& saltLength, const std::optional& dsaEncoding) = 0; + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridSlhDsaKeyPairSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridSlhDsaKeyPairSpec.hpp new file mode 100644 index 000000000..d90da6910 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridSlhDsaKeyPairSpec.hpp @@ -0,0 +1,70 @@ +/// +/// HybridSlhDsaKeyPairSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `SlhDsaKeyPair` + * Inherit this class to create instances of `HybridSlhDsaKeyPairSpec` in C++. + * @example + * ```cpp + * class HybridSlhDsaKeyPair : public HybridSlhDsaKeyPairSpec { + * public: + * HybridSlhDsaKeyPair(...) { ... } + * // ... + * }; + * ``` + */ + class HybridSlhDsaKeyPairSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "SlhDsaKeyPair"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridSlhDsaKeyPairSpec() = default; + + // Destructor + ~HybridSlhDsaKeyPairSpec() override; + + public: + // Properties + + + public: + // Methods + virtual Promise generateKeyPair(double publicFormat, double publicType, double privateFormat, double privateType) = 0; + virtual void generateKeyPairSync(double publicFormat, double publicType, double privateFormat, double privateType) = 0; + virtual ArrayBuffer getPublicKey() = 0; + virtual ArrayBuffer getPrivateKey() = 0; + virtual Promise sign(const ArrayBuffer& message) = 0; + virtual ArrayBuffer signSync(const ArrayBuffer& message) = 0; + virtual Promise verify(const ArrayBuffer& signature, const ArrayBuffer& message) = 0; + virtual bool verifySync(const ArrayBuffer& signature, const ArrayBuffer& message) = 0; + virtual void setVariant(const std::string& variant) = 0; + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridTurboShakeSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridTurboShakeSpec.hpp new file mode 100644 index 000000000..cba97fb74 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridTurboShakeSpec.hpp @@ -0,0 +1,64 @@ +/// +/// HybridTurboShakeSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `TurboShake` + * Inherit this class to create instances of `HybridTurboShakeSpec` in C++. + * @example + * ```cpp + * class HybridTurboShake : public HybridTurboShakeSpec { + * public: + * HybridTurboShake(...) { ... } + * // ... + * }; + * ``` + */ + class HybridTurboShakeSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "TurboShake"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridTurboShakeSpec() = default; + + // Destructor + ~HybridTurboShakeSpec() override; + + public: + // Properties + + + public: + // Methods + + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridUtilsSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridUtilsSpec.hpp new file mode 100644 index 000000000..e9854ab57 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridUtilsSpec.hpp @@ -0,0 +1,60 @@ +/// +/// HybridUtilsSpec.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include + +namespace margelo::nitro::crypto { + + using namespace margelo::nitro; + + /** + * An abstract base class for `Utils` + * Inherit this class to create instances of `HybridUtilsSpec` in C++. + * @example + * ```cpp + * class HybridUtils : public HybridUtilsSpec { + * public: + * HybridUtils(...) { ... } + * // ... + * }; + * ``` + */ + class HybridUtilsSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "Utils"; + static const std::shared_ptr& get(); + }; + + public: + // Constructor + HybridUtilsSpec() = default; + + // Destructor + ~HybridUtilsSpec() override; + + public: + // Properties + + + public: + // Methods + + + protected: + // Hybrid Setup + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } + }; + +} // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridVerifyHandleSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridVerifyHandleSpec.hpp similarity index 51% rename from packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridVerifyHandleSpec.hpp rename to packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridVerifyHandleSpec.hpp index ba5596f9f..f6331ad31 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridVerifyHandleSpec.hpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridVerifyHandleSpec.hpp @@ -1,25 +1,19 @@ /// /// HybridVerifyHandleSpec.hpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// #pragma once -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - -// Forward declaration of `HybridKeyObjectHandleSpec` to properly resolve imports. -namespace margelo::nitro::crypto { class HybridKeyObjectHandleSpec; } - +#include #include #include #include -#include "HybridKeyObjectHandleSpec.hpp" +// Forward declaration of `HybridKeyObjectHandleSpec` to properly resolve imports. +namespace margelo::nitro::crypto { class HybridKeyObjectHandleSpec; } #include namespace margelo::nitro::crypto { @@ -29,41 +23,45 @@ namespace margelo::nitro::crypto { /** * An abstract base class for `VerifyHandle` * Inherit this class to create instances of `HybridVerifyHandleSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. * @example * ```cpp - * class HybridVerifyHandle: public HybridVerifyHandleSpec { + * class HybridVerifyHandle : public HybridVerifyHandleSpec { * public: - * HybridVerifyHandle(...): HybridObject(TAG) { ... } + * HybridVerifyHandle(...) { ... } * // ... * }; * ``` */ - class HybridVerifyHandleSpec: public virtual HybridObject { + class HybridVerifyHandleSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "VerifyHandle"; + static const std::shared_ptr& get(); + }; + public: // Constructor - explicit HybridVerifyHandleSpec(): HybridObject(TAG) { } + HybridVerifyHandleSpec() = default; // Destructor - ~HybridVerifyHandleSpec() override = default; + ~HybridVerifyHandleSpec() override; public: // Properties - + public: // Methods virtual void init(const std::string& algorithm) = 0; - virtual void update(const std::shared_ptr& data) = 0; - virtual bool verify(const std::shared_ptr& keyHandle, const std::shared_ptr& signature, std::optional padding, std::optional saltLength, std::optional dsaEncoding) = 0; + virtual void update(const ArrayBuffer& data) = 0; + virtual bool verify(const std::shared_ptr& keyHandle, const ArrayBuffer& signature, const std::optional& padding, const std::optional& saltLength, const std::optional& dsaEncoding) = 0; protected: // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "VerifyHandle"; + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } }; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridX509CertificateHandleSpec.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridX509CertificateHandleSpec.hpp similarity index 71% rename from packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridX509CertificateHandleSpec.hpp rename to packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridX509CertificateHandleSpec.hpp index 73544ab42..5d4d71738 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/HybridX509CertificateHandleSpec.hpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/HybridX509CertificateHandleSpec.hpp @@ -1,29 +1,22 @@ /// /// HybridX509CertificateHandleSpec.hpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// #pragma once -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif - -// Forward declaration of `HybridKeyObjectHandleSpec` to properly resolve imports. -namespace margelo::nitro::crypto { class HybridKeyObjectHandleSpec; } -// Forward declaration of `HybridX509CertificateHandleSpec` to properly resolve imports. -namespace margelo::nitro::crypto { class HybridX509CertificateHandleSpec; } - +#include #include #include #include -#include "HybridKeyObjectHandleSpec.hpp" +// Forward declaration of `HybridKeyObjectHandleSpec` to properly resolve imports. +namespace margelo::nitro::crypto { class HybridKeyObjectHandleSpec; } #include -#include "HybridX509CertificateHandleSpec.hpp" +// Forward declaration of `HybridX509CertificateHandleSpec` to properly resolve imports. +namespace margelo::nitro::crypto { class HybridX509CertificateHandleSpec; } #include namespace margelo::nitro::crypto { @@ -33,31 +26,37 @@ namespace margelo::nitro::crypto { /** * An abstract base class for `X509CertificateHandle` * Inherit this class to create instances of `HybridX509CertificateHandleSpec` in C++. - * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual. * @example * ```cpp - * class HybridX509CertificateHandle: public HybridX509CertificateHandleSpec { + * class HybridX509CertificateHandle : public HybridX509CertificateHandleSpec { * public: - * HybridX509CertificateHandle(...): HybridObject(TAG) { ... } + * HybridX509CertificateHandle(...) { ... } * // ... * }; * ``` */ - class HybridX509CertificateHandleSpec: public virtual HybridObject { + class HybridX509CertificateHandleSpec : public virtual HybridObject { + public: + struct Class { + using Base = HybridObject::Class; + static constexpr const char* name = "X509CertificateHandle"; + static const std::shared_ptr& get(); + }; + public: // Constructor - explicit HybridX509CertificateHandleSpec(): HybridObject(TAG) { } + HybridX509CertificateHandleSpec() = default; // Destructor - ~HybridX509CertificateHandleSpec() override = default; + ~HybridX509CertificateHandleSpec() override; public: // Properties - + public: // Methods - virtual void init(const std::shared_ptr& buffer) = 0; + virtual void init(const ArrayBuffer& buffer) = 0; virtual std::string subject() = 0; virtual std::string subjectAltName() = 0; virtual std::string issuer() = 0; @@ -72,7 +71,7 @@ namespace margelo::nitro::crypto { virtual std::string fingerprint() = 0; virtual std::string fingerprint256() = 0; virtual std::string fingerprint512() = 0; - virtual std::shared_ptr raw() = 0; + virtual ArrayBuffer raw() = 0; virtual std::string pem() = 0; virtual std::shared_ptr publicKey() = 0; virtual std::vector keyUsage() = 0; @@ -86,11 +85,9 @@ namespace margelo::nitro::crypto { protected: // Hybrid Setup - void loadHybridMethods() override; - - protected: - // Tag for logging - static constexpr auto TAG = "X509CertificateHandle"; + const std::shared_ptr& getHybridClass() override { + return Class::get(); + } }; } // namespace margelo::nitro::crypto diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/JWK.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/JWK.hpp new file mode 100644 index 000000000..b76f5260c --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/JWK.hpp @@ -0,0 +1,71 @@ +/// +/// JWK.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace margelo::nitro::crypto { + + /** + * A struct which can be represented as a JavaScript object (JWK). + */ + struct JWK final { + public: + std::optional kty SWIFT_PRIVATE; + std::optional use SWIFT_PRIVATE; + std::optional> key_ops SWIFT_PRIVATE; + std::optional alg SWIFT_PRIVATE; + std::optional crv SWIFT_PRIVATE; + std::optional kid SWIFT_PRIVATE; + std::optional x5u SWIFT_PRIVATE; + std::optional> x5c SWIFT_PRIVATE; + std::optional x5t SWIFT_PRIVATE; + std::optional x5t_256 SWIFT_PRIVATE; + std::optional n SWIFT_PRIVATE; + std::optional e SWIFT_PRIVATE; + std::optional d SWIFT_PRIVATE; + std::optional p SWIFT_PRIVATE; + std::optional q SWIFT_PRIVATE; + std::optional x SWIFT_PRIVATE; + std::optional y SWIFT_PRIVATE; + std::optional k SWIFT_PRIVATE; + std::optional dp SWIFT_PRIVATE; + std::optional dq SWIFT_PRIVATE; + std::optional qi SWIFT_PRIVATE; + std::optional pub SWIFT_PRIVATE; + std::optional priv SWIFT_PRIVATE; + std::optional ext SWIFT_PRIVATE; + + public: + explicit JWK(std::optional kty, std::optional use, std::optional> key_ops, std::optional alg, std::optional crv, std::optional kid, std::optional x5u, std::optional> x5c, std::optional x5t, std::optional x5t_256, std::optional n, std::optional e, std::optional d, std::optional p, std::optional q, std::optional x, std::optional y, std::optional k, std::optional dp, std::optional dq, std::optional qi, std::optional pub, std::optional priv, std::optional ext): kty(std::move(kty)), use(std::move(use)), key_ops(std::move(key_ops)), alg(std::move(alg)), crv(std::move(crv)), kid(std::move(kid)), x5u(std::move(x5u)), x5c(std::move(x5c)), x5t(std::move(x5t)), x5t_256(std::move(x5t_256)), n(std::move(n)), e(std::move(e)), d(std::move(d)), p(std::move(p)), q(std::move(q)), x(std::move(x)), y(std::move(y)), k(std::move(k)), dp(std::move(dp)), dq(std::move(dq)), qi(std::move(qi)), pub(std::move(pub)), priv(std::move(priv)), ext(std::move(ext)) {} + + public: + friend bool operator==(const JWK& lhs, const JWK& rhs) = default; + }; + +} // namespace margelo::nitro::crypto + +namespace margelo::nitro { + + // C++ JWK <> JS JWK (object) + template <> + struct JSIConverter final { + static margelo::nitro::crypto::JWK fromJSI(jsi::Runtime& runtime, const jsi::Value& arg); + static jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::crypto::JWK& arg); + static bool canConvert(jsi::Runtime& runtime, const jsi::Value& value); + }; + +} // namespace margelo::nitro diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/JWKkty.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/JWKkty.hpp similarity index 86% rename from packages/react-native-quick-crypto/nitrogen/generated/shared/c++/JWKkty.hpp rename to packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/JWKkty.hpp index 359cdcde2..2fb4fb418 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/JWKkty.hpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/JWKkty.hpp @@ -1,27 +1,15 @@ /// /// JWKkty.hpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// #pragma once -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif namespace margelo::nitro::crypto { diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/JWKuse.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/JWKuse.hpp similarity index 82% rename from packages/react-native-quick-crypto/nitrogen/generated/shared/c++/JWKuse.hpp rename to packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/JWKuse.hpp index eb4c63f5d..60a8e73cd 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/JWKuse.hpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/JWKuse.hpp @@ -1,27 +1,15 @@ /// /// JWKuse.hpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// #pragma once -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif namespace margelo::nitro::crypto { diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KFormatType.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/KFormatType.hpp similarity index 58% rename from packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KFormatType.hpp rename to packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/KFormatType.hpp index 0180104c1..233f2d644 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KFormatType.hpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/KFormatType.hpp @@ -1,22 +1,15 @@ /// /// KFormatType.hpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// #pragma once -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif +#include namespace margelo::nitro::crypto { @@ -37,8 +30,14 @@ namespace margelo::nitro { template <> struct JSIConverter final { static inline margelo::nitro::crypto::KFormatType fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { - int enumValue = JSIConverter::fromJSI(runtime, arg); - return static_cast(enumValue); + int integer = doubleToInt(arg.asNumber()); + switch (integer) { + case 0: return margelo::nitro::crypto::KFormatType::DER; + case 1: return margelo::nitro::crypto::KFormatType::PEM; + case 2: return margelo::nitro::crypto::KFormatType::JWK; + default: [[unlikely]] + throw std::invalid_argument("Cannot convert " + arg.toString(runtime).utf8(runtime) + " to enum KFormatType - invalid value!"); + } } static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::crypto::KFormatType arg) { int enumValue = static_cast(arg); @@ -48,15 +47,16 @@ namespace margelo::nitro { if (!value.isNumber()) { return false; } - double number = value.getNumber(); - int integer = static_cast(number); - if (number != integer) { - // The integer is not the same value as the double - we truncated floating points. - // Enums are all integers, so the input floating point number is obviously invalid. + auto integer = tryDoubleToInt(value.getNumber()); + if (!integer.has_value()) { return false; } - // Check if we are within the bounds of the enum. - return integer >= 0 && integer <= 2; + switch (*integer) { + case 0: return true; + case 1: return true; + case 2: return true; + default: return false; + } } }; diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KangarooTwelveVariant.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/KangarooTwelveVariant.hpp similarity index 83% rename from packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KangarooTwelveVariant.hpp rename to packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/KangarooTwelveVariant.hpp index 7757e2201..11119a9bf 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KangarooTwelveVariant.hpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/KangarooTwelveVariant.hpp @@ -1,27 +1,15 @@ /// /// KangarooTwelveVariant.hpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// #pragma once -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif namespace margelo::nitro::crypto { diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/KeyDetail.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/KeyDetail.hpp new file mode 100644 index 000000000..be5adea1f --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/KeyDetail.hpp @@ -0,0 +1,50 @@ +/// +/// KeyDetail.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include +#include +#include +#include + +namespace margelo::nitro::crypto { + + /** + * A struct which can be represented as a JavaScript object (KeyDetail). + */ + struct KeyDetail final { + public: + std::optional length SWIFT_PRIVATE; + std::optional publicExponent SWIFT_PRIVATE; + std::optional modulusLength SWIFT_PRIVATE; + std::optional hashAlgorithm SWIFT_PRIVATE; + std::optional mgf1HashAlgorithm SWIFT_PRIVATE; + std::optional saltLength SWIFT_PRIVATE; + std::optional namedCurve SWIFT_PRIVATE; + + public: + explicit KeyDetail(std::optional length, std::optional publicExponent, std::optional modulusLength, std::optional hashAlgorithm, std::optional mgf1HashAlgorithm, std::optional saltLength, std::optional namedCurve): length(std::move(length)), publicExponent(std::move(publicExponent)), modulusLength(std::move(modulusLength)), hashAlgorithm(std::move(hashAlgorithm)), mgf1HashAlgorithm(std::move(mgf1HashAlgorithm)), saltLength(std::move(saltLength)), namedCurve(std::move(namedCurve)) {} + + public: + friend bool operator==(const KeyDetail& lhs, const KeyDetail& rhs) = default; + }; + +} // namespace margelo::nitro::crypto + +namespace margelo::nitro { + + // C++ KeyDetail <> JS KeyDetail (object) + template <> + struct JSIConverter final { + static margelo::nitro::crypto::KeyDetail fromJSI(jsi::Runtime& runtime, const jsi::Value& arg); + static jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::crypto::KeyDetail& arg); + static bool canConvert(jsi::Runtime& runtime, const jsi::Value& value); + }; + +} // namespace margelo::nitro diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KeyEncoding.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/KeyEncoding.hpp similarity index 59% rename from packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KeyEncoding.hpp rename to packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/KeyEncoding.hpp index 430aa395a..a4c8253a7 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KeyEncoding.hpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/KeyEncoding.hpp @@ -1,22 +1,15 @@ /// /// KeyEncoding.hpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// #pragma once -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif +#include namespace margelo::nitro::crypto { @@ -38,8 +31,15 @@ namespace margelo::nitro { template <> struct JSIConverter final { static inline margelo::nitro::crypto::KeyEncoding fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { - int enumValue = JSIConverter::fromJSI(runtime, arg); - return static_cast(enumValue); + int integer = doubleToInt(arg.asNumber()); + switch (integer) { + case 0: return margelo::nitro::crypto::KeyEncoding::PKCS1; + case 1: return margelo::nitro::crypto::KeyEncoding::PKCS8; + case 2: return margelo::nitro::crypto::KeyEncoding::SPKI; + case 3: return margelo::nitro::crypto::KeyEncoding::SEC1; + default: [[unlikely]] + throw std::invalid_argument("Cannot convert " + arg.toString(runtime).utf8(runtime) + " to enum KeyEncoding - invalid value!"); + } } static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::crypto::KeyEncoding arg) { int enumValue = static_cast(arg); @@ -49,15 +49,17 @@ namespace margelo::nitro { if (!value.isNumber()) { return false; } - double number = value.getNumber(); - int integer = static_cast(number); - if (number != integer) { - // The integer is not the same value as the double - we truncated floating points. - // Enums are all integers, so the input floating point number is obviously invalid. + auto integer = tryDoubleToInt(value.getNumber()); + if (!integer.has_value()) { return false; } - // Check if we are within the bounds of the enum. - return integer >= 0 && integer <= 3; + switch (*integer) { + case 0: return true; + case 1: return true; + case 2: return true; + case 3: return true; + default: return false; + } } }; diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/KeyObject.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/KeyObject.hpp new file mode 100644 index 000000000..45436c3a0 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/KeyObject.hpp @@ -0,0 +1,41 @@ +/// +/// KeyObject.hpp +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +#pragma once + +#include +#include + +namespace margelo::nitro::crypto { + + /** + * A struct which can be represented as a JavaScript object (KeyObject). + */ + struct KeyObject final { + public: + bool extractable SWIFT_PRIVATE; + + public: + explicit KeyObject(bool extractable): extractable(extractable) {} + + public: + friend bool operator==(const KeyObject& lhs, const KeyObject& rhs) = default; + }; + +} // namespace margelo::nitro::crypto + +namespace margelo::nitro { + + // C++ KeyObject <> JS KeyObject (object) + template <> + struct JSIConverter final { + static margelo::nitro::crypto::KeyObject fromJSI(jsi::Runtime& runtime, const jsi::Value& arg); + static jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::crypto::KeyObject& arg); + static bool canConvert(jsi::Runtime& runtime, const jsi::Value& value); + }; + +} // namespace margelo::nitro diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KeyType.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/KeyType.hpp similarity index 58% rename from packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KeyType.hpp rename to packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/KeyType.hpp index 05652c106..36a579e28 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KeyType.hpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/KeyType.hpp @@ -1,22 +1,15 @@ /// /// KeyType.hpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// #pragma once -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif +#include namespace margelo::nitro::crypto { @@ -37,8 +30,14 @@ namespace margelo::nitro { template <> struct JSIConverter final { static inline margelo::nitro::crypto::KeyType fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { - int enumValue = JSIConverter::fromJSI(runtime, arg); - return static_cast(enumValue); + int integer = doubleToInt(arg.asNumber()); + switch (integer) { + case 0: return margelo::nitro::crypto::KeyType::SECRET; + case 1: return margelo::nitro::crypto::KeyType::PUBLIC; + case 2: return margelo::nitro::crypto::KeyType::PRIVATE; + default: [[unlikely]] + throw std::invalid_argument("Cannot convert " + arg.toString(runtime).utf8(runtime) + " to enum KeyType - invalid value!"); + } } static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::crypto::KeyType arg) { int enumValue = static_cast(arg); @@ -48,15 +47,16 @@ namespace margelo::nitro { if (!value.isNumber()) { return false; } - double number = value.getNumber(); - int integer = static_cast(number); - if (number != integer) { - // The integer is not the same value as the double - we truncated floating points. - // Enums are all integers, so the input floating point number is obviously invalid. + auto integer = tryDoubleToInt(value.getNumber()); + if (!integer.has_value()) { return false; } - // Check if we are within the bounds of the enum. - return integer >= 0 && integer <= 2; + switch (*integer) { + case 0: return true; + case 1: return true; + case 2: return true; + default: return false; + } } }; diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KeyUsage.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/KeyUsage.hpp similarity index 91% rename from packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KeyUsage.hpp rename to packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/KeyUsage.hpp index 119552a63..da284285e 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/KeyUsage.hpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/KeyUsage.hpp @@ -1,27 +1,15 @@ /// /// KeyUsage.hpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// #pragma once -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif namespace margelo::nitro::crypto { diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/NamedCurve.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/NamedCurve.hpp similarity index 84% rename from packages/react-native-quick-crypto/nitrogen/generated/shared/c++/NamedCurve.hpp rename to packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/NamedCurve.hpp index 03f64cc7d..dca34036d 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/NamedCurve.hpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/NamedCurve.hpp @@ -1,27 +1,15 @@ /// /// NamedCurve.hpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// #pragma once -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif namespace margelo::nitro::crypto { diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/TurboShakeVariant.hpp b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/TurboShakeVariant.hpp similarity index 83% rename from packages/react-native-quick-crypto/nitrogen/generated/shared/c++/TurboShakeVariant.hpp rename to packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/TurboShakeVariant.hpp index 09491f255..3433f43f5 100644 --- a/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/TurboShakeVariant.hpp +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/c++/include/QuickCrypto/TurboShakeVariant.hpp @@ -1,27 +1,15 @@ /// /// TurboShakeVariant.hpp /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. -/// https://github.com/mrousavy/nitro +/// https://github.com/margelo/nitro /// Copyright © Marc Rousavy @ Margelo /// #pragma once -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif -#if __has_include() #include -#else -#error NitroModules cannot be found! Are you sure you installed NitroModules properly? -#endif namespace margelo::nitro::crypto { diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Argon2.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Argon2.cjs new file mode 100644 index 000000000..e47942663 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Argon2.cjs @@ -0,0 +1,19 @@ +/// +/// Argon2.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get Argon2() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.Argon2') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Argon2.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Argon2.d.cts new file mode 100644 index 000000000..6730e2270 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Argon2.d.cts @@ -0,0 +1,9 @@ +/// +/// Argon2.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class Argon2` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Blake3.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Blake3.cjs new file mode 100644 index 000000000..5e1e53e36 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Blake3.cjs @@ -0,0 +1,19 @@ +/// +/// Blake3.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get Blake3() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.Blake3') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Blake3.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Blake3.d.cts new file mode 100644 index 000000000..5a5194d92 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Blake3.d.cts @@ -0,0 +1,9 @@ +/// +/// Blake3.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class Blake3` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Certificate.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Certificate.cjs new file mode 100644 index 000000000..85b185ae2 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Certificate.cjs @@ -0,0 +1,19 @@ +/// +/// Certificate.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get Certificate() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.Certificate') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Certificate.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Certificate.d.cts new file mode 100644 index 000000000..7b4ea46bf --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Certificate.d.cts @@ -0,0 +1,9 @@ +/// +/// Certificate.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class Certificate` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Cipher.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Cipher.cjs new file mode 100644 index 000000000..44d352adb --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Cipher.cjs @@ -0,0 +1,19 @@ +/// +/// Cipher.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get Cipher() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.Cipher') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Cipher.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Cipher.d.cts new file mode 100644 index 000000000..5f8fa3017 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Cipher.d.cts @@ -0,0 +1,9 @@ +/// +/// Cipher.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class Cipher` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/CipherFactory.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/CipherFactory.cjs new file mode 100644 index 000000000..85e713147 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/CipherFactory.cjs @@ -0,0 +1,19 @@ +/// +/// CipherFactory.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get CipherFactory() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.CipherFactory') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/CipherFactory.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/CipherFactory.d.cts new file mode 100644 index 000000000..4ca6c4406 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/CipherFactory.d.cts @@ -0,0 +1,9 @@ +/// +/// CipherFactory.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class CipherFactory` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/DhKeyPair.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/DhKeyPair.cjs new file mode 100644 index 000000000..4f019597a --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/DhKeyPair.cjs @@ -0,0 +1,19 @@ +/// +/// DhKeyPair.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get DhKeyPair() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.DhKeyPair') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/DhKeyPair.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/DhKeyPair.d.cts new file mode 100644 index 000000000..cec69348b --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/DhKeyPair.d.cts @@ -0,0 +1,9 @@ +/// +/// DhKeyPair.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class DhKeyPair` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/DiffieHellman.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/DiffieHellman.cjs new file mode 100644 index 000000000..10b395301 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/DiffieHellman.cjs @@ -0,0 +1,19 @@ +/// +/// DiffieHellman.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get DiffieHellman() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.DiffieHellman') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/DiffieHellman.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/DiffieHellman.d.cts new file mode 100644 index 000000000..4620ed9e0 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/DiffieHellman.d.cts @@ -0,0 +1,9 @@ +/// +/// DiffieHellman.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class DiffieHellman` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/DsaKeyPair.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/DsaKeyPair.cjs new file mode 100644 index 000000000..ee98452d9 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/DsaKeyPair.cjs @@ -0,0 +1,19 @@ +/// +/// DsaKeyPair.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get DsaKeyPair() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.DsaKeyPair') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/DsaKeyPair.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/DsaKeyPair.d.cts new file mode 100644 index 000000000..895dfd7dd --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/DsaKeyPair.d.cts @@ -0,0 +1,9 @@ +/// +/// DsaKeyPair.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class DsaKeyPair` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/ECDH.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/ECDH.cjs new file mode 100644 index 000000000..9eb141948 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/ECDH.cjs @@ -0,0 +1,19 @@ +/// +/// ECDH.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get ECDH() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.ECDH') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/ECDH.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/ECDH.d.cts new file mode 100644 index 000000000..f5e1fbead --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/ECDH.d.cts @@ -0,0 +1,9 @@ +/// +/// ECDH.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class ECDH` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/EcKeyPair.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/EcKeyPair.cjs new file mode 100644 index 000000000..a993a04e1 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/EcKeyPair.cjs @@ -0,0 +1,19 @@ +/// +/// EcKeyPair.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get EcKeyPair() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.EcKeyPair') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/EcKeyPair.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/EcKeyPair.d.cts new file mode 100644 index 000000000..736bd10c3 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/EcKeyPair.d.cts @@ -0,0 +1,9 @@ +/// +/// EcKeyPair.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class EcKeyPair` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/EdKeyPair.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/EdKeyPair.cjs new file mode 100644 index 000000000..990fd69c2 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/EdKeyPair.cjs @@ -0,0 +1,19 @@ +/// +/// EdKeyPair.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get EdKeyPair() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.EdKeyPair') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/EdKeyPair.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/EdKeyPair.d.cts new file mode 100644 index 000000000..e43c94541 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/EdKeyPair.d.cts @@ -0,0 +1,9 @@ +/// +/// EdKeyPair.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class EdKeyPair` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Hash.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Hash.cjs new file mode 100644 index 000000000..04ffc748b --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Hash.cjs @@ -0,0 +1,19 @@ +/// +/// Hash.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get Hash() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.Hash') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Hash.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Hash.d.cts new file mode 100644 index 000000000..56d8c7ce1 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Hash.d.cts @@ -0,0 +1,9 @@ +/// +/// Hash.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class Hash` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Hkdf.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Hkdf.cjs new file mode 100644 index 000000000..3ac2277f4 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Hkdf.cjs @@ -0,0 +1,19 @@ +/// +/// Hkdf.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get Hkdf() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.Hkdf') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Hkdf.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Hkdf.d.cts new file mode 100644 index 000000000..90047aacf --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Hkdf.d.cts @@ -0,0 +1,9 @@ +/// +/// Hkdf.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class Hkdf` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Hmac.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Hmac.cjs new file mode 100644 index 000000000..c3d4ba3d7 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Hmac.cjs @@ -0,0 +1,19 @@ +/// +/// Hmac.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get Hmac() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.Hmac') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Hmac.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Hmac.d.cts new file mode 100644 index 000000000..1d4dc6c23 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Hmac.d.cts @@ -0,0 +1,9 @@ +/// +/// Hmac.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class Hmac` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/KeyObjectHandle.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/KeyObjectHandle.cjs new file mode 100644 index 000000000..5ef3b4c62 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/KeyObjectHandle.cjs @@ -0,0 +1,19 @@ +/// +/// KeyObjectHandle.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get KeyObjectHandle() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.KeyObjectHandle') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/KeyObjectHandle.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/KeyObjectHandle.d.cts new file mode 100644 index 000000000..79af388d9 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/KeyObjectHandle.d.cts @@ -0,0 +1,9 @@ +/// +/// KeyObjectHandle.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class KeyObjectHandle` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Kmac.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Kmac.cjs new file mode 100644 index 000000000..7b9b10c82 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Kmac.cjs @@ -0,0 +1,19 @@ +/// +/// Kmac.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get Kmac() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.Kmac') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Kmac.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Kmac.d.cts new file mode 100644 index 000000000..c1acb6cec --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Kmac.d.cts @@ -0,0 +1,9 @@ +/// +/// Kmac.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class Kmac` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/MlDsaKeyPair.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/MlDsaKeyPair.cjs new file mode 100644 index 000000000..eb5b44627 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/MlDsaKeyPair.cjs @@ -0,0 +1,19 @@ +/// +/// MlDsaKeyPair.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get MlDsaKeyPair() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.MlDsaKeyPair') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/MlDsaKeyPair.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/MlDsaKeyPair.d.cts new file mode 100644 index 000000000..42e2afff7 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/MlDsaKeyPair.d.cts @@ -0,0 +1,9 @@ +/// +/// MlDsaKeyPair.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class MlDsaKeyPair` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/MlKemKeyPair.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/MlKemKeyPair.cjs new file mode 100644 index 000000000..fb8e1bb8a --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/MlKemKeyPair.cjs @@ -0,0 +1,19 @@ +/// +/// MlKemKeyPair.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get MlKemKeyPair() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.MlKemKeyPair') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/MlKemKeyPair.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/MlKemKeyPair.d.cts new file mode 100644 index 000000000..4dd58723f --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/MlKemKeyPair.d.cts @@ -0,0 +1,9 @@ +/// +/// MlKemKeyPair.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class MlKemKeyPair` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Pbkdf2.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Pbkdf2.cjs new file mode 100644 index 000000000..5599731fb --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Pbkdf2.cjs @@ -0,0 +1,19 @@ +/// +/// Pbkdf2.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get Pbkdf2() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.Pbkdf2') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Pbkdf2.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Pbkdf2.d.cts new file mode 100644 index 000000000..47e1fac19 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Pbkdf2.d.cts @@ -0,0 +1,9 @@ +/// +/// Pbkdf2.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class Pbkdf2` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Prime.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Prime.cjs new file mode 100644 index 000000000..a31170eaf --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Prime.cjs @@ -0,0 +1,19 @@ +/// +/// Prime.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get Prime() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.Prime') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Prime.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Prime.d.cts new file mode 100644 index 000000000..717f56e53 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Prime.d.cts @@ -0,0 +1,9 @@ +/// +/// Prime.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class Prime` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Random.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Random.cjs new file mode 100644 index 000000000..f9ba3a0a1 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Random.cjs @@ -0,0 +1,19 @@ +/// +/// Random.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get Random() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.Random') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Random.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Random.d.cts new file mode 100644 index 000000000..13af8e535 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Random.d.cts @@ -0,0 +1,9 @@ +/// +/// Random.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class Random` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/RsaCipher.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/RsaCipher.cjs new file mode 100644 index 000000000..122d03234 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/RsaCipher.cjs @@ -0,0 +1,19 @@ +/// +/// RsaCipher.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get RsaCipher() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.RsaCipher') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/RsaCipher.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/RsaCipher.d.cts new file mode 100644 index 000000000..4e15216e1 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/RsaCipher.d.cts @@ -0,0 +1,9 @@ +/// +/// RsaCipher.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class RsaCipher` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/RsaKeyPair.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/RsaKeyPair.cjs new file mode 100644 index 000000000..7910009d3 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/RsaKeyPair.cjs @@ -0,0 +1,19 @@ +/// +/// RsaKeyPair.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get RsaKeyPair() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.RsaKeyPair') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/RsaKeyPair.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/RsaKeyPair.d.cts new file mode 100644 index 000000000..cc47122b2 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/RsaKeyPair.d.cts @@ -0,0 +1,9 @@ +/// +/// RsaKeyPair.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class RsaKeyPair` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Scrypt.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Scrypt.cjs new file mode 100644 index 000000000..954427b40 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Scrypt.cjs @@ -0,0 +1,19 @@ +/// +/// Scrypt.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get Scrypt() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.Scrypt') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Scrypt.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Scrypt.d.cts new file mode 100644 index 000000000..9f7607230 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Scrypt.d.cts @@ -0,0 +1,9 @@ +/// +/// Scrypt.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class Scrypt` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/SignHandle.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/SignHandle.cjs new file mode 100644 index 000000000..ef3d4c3d7 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/SignHandle.cjs @@ -0,0 +1,19 @@ +/// +/// SignHandle.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get SignHandle() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.SignHandle') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/SignHandle.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/SignHandle.d.cts new file mode 100644 index 000000000..ac6b96056 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/SignHandle.d.cts @@ -0,0 +1,9 @@ +/// +/// SignHandle.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class SignHandle` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/SlhDsaKeyPair.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/SlhDsaKeyPair.cjs new file mode 100644 index 000000000..32ade1d40 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/SlhDsaKeyPair.cjs @@ -0,0 +1,19 @@ +/// +/// SlhDsaKeyPair.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get SlhDsaKeyPair() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.SlhDsaKeyPair') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/SlhDsaKeyPair.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/SlhDsaKeyPair.d.cts new file mode 100644 index 000000000..7684b38cb --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/SlhDsaKeyPair.d.cts @@ -0,0 +1,9 @@ +/// +/// SlhDsaKeyPair.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class SlhDsaKeyPair` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/TurboShake.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/TurboShake.cjs new file mode 100644 index 000000000..191d45d71 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/TurboShake.cjs @@ -0,0 +1,19 @@ +/// +/// TurboShake.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get TurboShake() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.TurboShake') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/TurboShake.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/TurboShake.d.cts new file mode 100644 index 000000000..5d3c00635 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/TurboShake.d.cts @@ -0,0 +1,9 @@ +/// +/// TurboShake.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class TurboShake` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Utils.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Utils.cjs new file mode 100644 index 000000000..d83a2a1ee --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Utils.cjs @@ -0,0 +1,19 @@ +/// +/// Utils.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get Utils() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.Utils') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Utils.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Utils.d.cts new file mode 100644 index 000000000..ef36b57e8 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/Utils.d.cts @@ -0,0 +1,9 @@ +/// +/// Utils.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class Utils` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/VerifyHandle.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/VerifyHandle.cjs new file mode 100644 index 000000000..7abd38bc4 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/VerifyHandle.cjs @@ -0,0 +1,19 @@ +/// +/// VerifyHandle.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get VerifyHandle() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.VerifyHandle') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/VerifyHandle.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/VerifyHandle.d.cts new file mode 100644 index 000000000..3e4172903 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/VerifyHandle.d.cts @@ -0,0 +1,9 @@ +/// +/// VerifyHandle.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class VerifyHandle` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/X509CertificateHandle.cjs b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/X509CertificateHandle.cjs new file mode 100644 index 000000000..c75c97d7f --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/X509CertificateHandle.cjs @@ -0,0 +1,19 @@ +/// +/// X509CertificateHandle.cjs +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +const { NitroModules } = require('nitro-core') + +let hybridClass + +module.exports = { + get X509CertificateHandle() { + if (hybridClass === undefined) { + hybridClass = NitroModules.getHybridClass('crypto.X509CertificateHandle') + } + return hybridClass + }, +} diff --git a/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/X509CertificateHandle.d.cts b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/X509CertificateHandle.d.cts new file mode 100644 index 000000000..14d308817 --- /dev/null +++ b/packages/react-native-quick-crypto/nitrogen/generated/shared/javascript/X509CertificateHandle.d.cts @@ -0,0 +1,9 @@ +/// +/// X509CertificateHandle.d.cts +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/margelo/nitro +/// Copyright © Marc Rousavy @ Margelo +/// + +// The spec's `export declare class X509CertificateHandle` types this runtime export. +export {} diff --git a/packages/react-native-quick-crypto/package.json b/packages/react-native-quick-crypto/package.json index 9933a23b5..2bd7a5246 100644 --- a/packages/react-native-quick-crypto/package.json +++ b/packages/react-native-quick-crypto/package.json @@ -7,6 +7,9 @@ "types": "lib/typescript/index.d.ts", "react-native": "src/index", "source": "src/index", + "imports": { + "#nitro/*": "./nitrogen/generated/shared/javascript/*.cjs" + }, "scripts": { "clean": "del-cli android/build lib", "clean:deep": "bun run clean && del-cli node_modules", @@ -29,6 +32,7 @@ "android/build.gradle", "android/gradle.properties", "android/CMakeLists.txt", + "android/cmake", "android/src", "ios", "cpp", @@ -125,20 +129,28 @@ "dpdm": "^4.0.1", "expo": "^54.0.25", "jest": "29.7.0", - "nitrogen": "0.33.2", + "nitrogen": "1.0.0-alpha.nightly.138.g43e09c161101", "react-native-builder-bob": "0.40.15", - "react-native-nitro-modules": "0.36.5" + "react-native-nitro-modules": "1.0.0-alpha.nightly.138.g43e09c161101", + "nitro-core": "1.0.0-alpha.nightly.138.g43e09c161101" }, "peerDependencies": { "react": "*", "react-native": "*", - "react-native-nitro-modules": ">=0.31.2", + "react-native-nitro-modules": "1.0.0-alpha.nightly.138.g43e09c161101", "react-native-quick-base64": ">=3.0.0", - "expo": ">=48.0.0" + "expo": ">=48.0.0", + "nitro-core": "1.0.0-alpha.nightly.138.g43e09c161101" }, "peerDependenciesMeta": { "expo": { "optional": true + }, + "react-native-nitro-modules": { + "optional": true + }, + "nitro-core": { + "optional": true } }, "release-it": { @@ -173,8 +185,18 @@ "source": "src", "output": "lib", "targets": [ - "commonjs", - "module", + [ + "commonjs", + { + "configFile": true + } + ], + [ + "module", + { + "configFile": true + } + ], [ "typescript", { diff --git a/packages/react-native-quick-crypto/src/argon2.ts b/packages/react-native-quick-crypto/src/argon2.ts index 66c64fa2e..3a2ddae9d 100644 --- a/packages/react-native-quick-crypto/src/argon2.ts +++ b/packages/react-native-quick-crypto/src/argon2.ts @@ -1,17 +1,8 @@ import { Buffer } from '@craftzdog/react-native-buffer'; -import { NitroModules } from 'react-native-nitro-modules'; -import type { Argon2 as NativeArgon2 } from './specs/argon2.nitro'; +import { Argon2 as NativeArgon2 } from './specs/argon2.nitro'; import { binaryLikeToArrayBuffer } from './utils'; import type { BinaryLike } from './utils'; -let native: NativeArgon2; -function getNative(): NativeArgon2 { - if (native == null) { - native = NitroModules.createHybridObject('Argon2'); - } - return native; -} - export interface Argon2Params { message: BinaryLike; nonce: BinaryLike; @@ -114,7 +105,7 @@ export function argon2Sync(algorithm: string, params: Argon2Params): Buffer { validateAlgorithm(algorithm); const version = params.version ?? ARGON2_VERSION; const nonceAB = validateArgon2Params(params, version); - const result = getNative().hashSync( + const result = NativeArgon2.hashSync( algorithm, toAB(params.message), nonceAB, @@ -143,19 +134,18 @@ export function argon2( callback(err as Error, Buffer.alloc(0)); return; } - getNative() - .hash( - algorithm, - toAB(params.message), - nonceAB, - params.parallelism, - params.tagLength, - params.memory, - params.passes, - version, - params.secret ? toAB(params.secret) : undefined, - params.associatedData ? toAB(params.associatedData) : undefined, - ) + NativeArgon2.hash( + algorithm, + toAB(params.message), + nonceAB, + params.parallelism, + params.tagLength, + params.memory, + params.passes, + version, + params.secret ? toAB(params.secret) : undefined, + params.associatedData ? toAB(params.associatedData) : undefined, + ) .then(ab => callback(null, Buffer.from(ab))) .catch((err: Error) => callback(err, Buffer.alloc(0))); } diff --git a/packages/react-native-quick-crypto/src/blake3.ts b/packages/react-native-quick-crypto/src/blake3.ts index 7a0298be2..9e1a98a33 100644 --- a/packages/react-native-quick-crypto/src/blake3.ts +++ b/packages/react-native-quick-crypto/src/blake3.ts @@ -1,6 +1,5 @@ -import { NitroModules } from 'react-native-nitro-modules'; import { Buffer } from '@craftzdog/react-native-buffer'; -import type { Blake3 as NativeBlake3 } from './specs/blake3.nitro'; +import { Blake3 as NativeBlake3 } from './specs/blake3.nitro'; import type { BinaryLike, Encoding } from './utils'; import { binaryLikeToArrayBuffer, ab2str } from './utils'; import { toArrayBuffer } from './utils/conversion'; @@ -21,7 +20,7 @@ export class Blake3 { private contextData?: string; constructor(opts?: Blake3Options) { - this.native = NitroModules.createHybridObject('Blake3'); + this.native = new NativeBlake3(); if (opts?.key && opts?.context) { throw new Error( @@ -97,9 +96,7 @@ export class Blake3 { } static getVersion(): string { - const native = NitroModules.createHybridObject('Blake3'); - native.initHash(); - return native.getVersion(); + return NativeBlake3.getVersion(); } } diff --git a/packages/react-native-quick-crypto/src/certificate.ts b/packages/react-native-quick-crypto/src/certificate.ts index ff17fbc38..8635844ac 100644 --- a/packages/react-native-quick-crypto/src/certificate.ts +++ b/packages/react-native-quick-crypto/src/certificate.ts @@ -1,17 +1,8 @@ -import { NitroModules } from 'react-native-nitro-modules'; import { Buffer } from '@craftzdog/react-native-buffer'; -import type { Certificate as NativeCertificate } from './specs/certificate.nitro'; +import { Certificate as NativeCertificate } from './specs/certificate.nitro'; import type { BinaryLike } from './utils'; import { binaryLikeToArrayBuffer } from './utils'; -let native: NativeCertificate; -function getNative(): NativeCertificate { - if (native == null) { - native = NitroModules.createHybridObject('Certificate'); - } - return native; -} - function toArrayBuffer( spkac: BinaryLike, encoding?: BufferEncoding, @@ -25,17 +16,17 @@ function toArrayBuffer( export class Certificate { static exportChallenge(spkac: BinaryLike, encoding?: BufferEncoding): Buffer { return Buffer.from( - getNative().exportChallenge(toArrayBuffer(spkac, encoding)), + NativeCertificate.exportChallenge(toArrayBuffer(spkac, encoding)), ); } static exportPublicKey(spkac: BinaryLike, encoding?: BufferEncoding): Buffer { return Buffer.from( - getNative().exportPublicKey(toArrayBuffer(spkac, encoding)), + NativeCertificate.exportPublicKey(toArrayBuffer(spkac, encoding)), ); } static verifySpkac(spkac: BinaryLike, encoding?: BufferEncoding): boolean { - return getNative().verifySpkac(toArrayBuffer(spkac, encoding)); + return NativeCertificate.verifySpkac(toArrayBuffer(spkac, encoding)); } } diff --git a/packages/react-native-quick-crypto/src/cipher.ts b/packages/react-native-quick-crypto/src/cipher.ts index 8d7a8469d..5b5cb672e 100644 --- a/packages/react-native-quick-crypto/src/cipher.ts +++ b/packages/react-native-quick-crypto/src/cipher.ts @@ -1,4 +1,3 @@ -import { NitroModules } from 'react-native-nitro-modules'; import Stream, { type TransformOptions } from 'readable-stream'; import { StringDecoder } from 'string_decoder'; import { Buffer } from '@craftzdog/react-native-buffer'; @@ -11,10 +10,7 @@ import type { CipherOCBOptions, CipherOCBTypes, } from 'crypto'; // @types/node -import type { - Cipher as NativeCipher, - CipherFactory, -} from './specs/cipher.nitro'; +import { Cipher as NativeCipher, CipherFactory } from './specs/cipher.nitro'; import { binaryLikeToArrayBuffer } from './utils'; import { getDefaultEncoding, @@ -39,17 +35,15 @@ export interface CipherInfoResult { } class CipherUtils { - private static native = - NitroModules.createHybridObject('Cipher'); public static getSupportedCiphers(): string[] { - return this.native.getSupportedCiphers(); + return NativeCipher.getSupportedCiphers(); } public static getCipherInfo( name: string, keyLength?: number, ivLength?: number, ): CipherInfoResult | undefined { - return this.native.getCipherInfo(name, keyLength, ivLength); + return NativeCipher.getCipherInfo(name, keyLength, ivLength); } } @@ -212,9 +206,7 @@ class CipherCommon extends Stream.Transform { const ivAB = binaryLikeToArrayBuffer(iv); validateCipherParams(cipherType, cipherKeyAB.byteLength, ivAB.byteLength); - const factory = - NitroModules.createHybridObject('CipherFactory'); - this.native = factory.createCipher({ + this.native = CipherFactory.createCipher({ isCipher, cipherType, cipherKey: cipherKeyAB, @@ -351,7 +343,7 @@ class CipherCommon extends Stream.Transform { } public getSupportedCiphers(): string[] { - return this.native.getSupportedCiphers(); + return NativeCipher.getSupportedCiphers(); } } @@ -484,9 +476,7 @@ export function xsalsa20( const ivAB = binaryLikeToArrayBuffer(nonce); validateCipherParams('xsalsa20', cipherKeyAB.byteLength, ivAB.byteLength); - const factory = - NitroModules.createHybridObject('CipherFactory'); - const native = factory.createCipher({ + const native = CipherFactory.createCipher({ isCipher: true, cipherType: 'xsalsa20', cipherKey: cipherKeyAB, diff --git a/packages/react-native-quick-crypto/src/dhKeyPair.ts b/packages/react-native-quick-crypto/src/dhKeyPair.ts index 402b98a3f..7bc9c89bf 100644 --- a/packages/react-native-quick-crypto/src/dhKeyPair.ts +++ b/packages/react-native-quick-crypto/src/dhKeyPair.ts @@ -1,7 +1,6 @@ -import { NitroModules } from 'react-native-nitro-modules'; import { Buffer } from '@craftzdog/react-native-buffer'; import { KeyObject, PublicKeyObject, PrivateKeyObject } from './keys/classes'; -import type { DhKeyPair } from './specs/dhKeyPair.nitro'; +import { DhKeyPair } from './specs/dhKeyPair.nitro'; import type { GenerateKeyPairOptions, KeyPairGenConfig } from './utils/types'; import { KFormatType, KeyEncoding } from './utils'; import { DH_GROUPS } from './dh-groups'; @@ -10,7 +9,7 @@ export class DhKeyPairGen { native: DhKeyPair; constructor(options: GenerateKeyPairOptions) { - this.native = NitroModules.createHybridObject('DhKeyPair'); + this.native = new DhKeyPair(); const { groupName, prime, primeLength, generator } = options; diff --git a/packages/react-native-quick-crypto/src/diffie-hellman.ts b/packages/react-native-quick-crypto/src/diffie-hellman.ts index 308f6071d..591387445 100644 --- a/packages/react-native-quick-crypto/src/diffie-hellman.ts +++ b/packages/react-native-quick-crypto/src/diffie-hellman.ts @@ -1,5 +1,4 @@ -import { NitroModules } from 'react-native-nitro-modules'; -import type { DiffieHellman as DiffieHellmanInterface } from './specs/diffie-hellman.nitro'; +import { DiffieHellman as DiffieHellmanInterface } from './specs/diffie-hellman.nitro'; import { Buffer } from '@craftzdog/react-native-buffer'; import { DH_GROUPS } from './dh-groups'; import { toArrayBuffer } from './utils/conversion'; @@ -12,8 +11,7 @@ export class DiffieHellman { generator?: number | Buffer | string, encoding?: BufferEncoding, ) { - this._hybrid = - NitroModules.createHybridObject('DiffieHellman'); + this._hybrid = new DiffieHellmanInterface(); if (typeof sizeOrPrime === 'number') { const gen = typeof generator === 'number' ? generator : 2; diff --git a/packages/react-native-quick-crypto/src/dsa.ts b/packages/react-native-quick-crypto/src/dsa.ts index 2cf2d2156..4f75bf653 100644 --- a/packages/react-native-quick-crypto/src/dsa.ts +++ b/packages/react-native-quick-crypto/src/dsa.ts @@ -1,7 +1,6 @@ -import { NitroModules } from 'react-native-nitro-modules'; import { Buffer } from '@craftzdog/react-native-buffer'; import { KeyObject, PublicKeyObject, PrivateKeyObject } from './keys/classes'; -import type { DsaKeyPair } from './specs/dsaKeyPair.nitro'; +import { DsaKeyPair } from './specs/dsaKeyPair.nitro'; import type { GenerateKeyPairOptions, KeyPairGenConfig } from './utils/types'; import { KFormatType, KeyEncoding } from './utils'; @@ -9,7 +8,7 @@ export class Dsa { native: DsaKeyPair; constructor(modulusLength: number, divisorLength?: number) { - this.native = NitroModules.createHybridObject('DsaKeyPair'); + this.native = new DsaKeyPair(); this.native.setModulusLength(modulusLength); if (divisorLength !== undefined && divisorLength >= 0) { this.native.setDivisorLength(divisorLength); diff --git a/packages/react-native-quick-crypto/src/ec.ts b/packages/react-native-quick-crypto/src/ec.ts index 1d0dd5e19..5d2f5a99c 100644 --- a/packages/react-native-quick-crypto/src/ec.ts +++ b/packages/react-native-quick-crypto/src/ec.ts @@ -1,6 +1,5 @@ -import { NitroModules } from 'react-native-nitro-modules'; -import type { EcKeyPair } from './specs/ecKeyPair.nitro'; -import type { KeyObjectHandle } from './specs/keyObjectHandle.nitro'; +import { EcKeyPair } from './specs/ecKeyPair.nitro'; +import { KeyObjectHandle } from './specs/keyObjectHandle.nitro'; import { CryptoKey, KeyObject, @@ -36,15 +35,8 @@ import { Buffer } from '@craftzdog/react-native-buffer'; import { ECDH } from './ecdh'; class EcUtils { - private static _native: EcKeyPair | undefined; - private static get native(): EcKeyPair { - if (!this._native) { - this._native = NitroModules.createHybridObject('EcKeyPair'); - } - return this._native; - } public static getSupportedCurves(): string[] { - return this.native.getSupportedCurves(); + return EcKeyPair.getSupportedCurves(); } } @@ -56,7 +48,7 @@ export class Ec { native: EcKeyPair; constructor(curve: string) { - this.native = NitroModules.createHybridObject('EcKeyPair'); + this.native = new EcKeyPair(); this.native.setCurve(curve); } @@ -150,8 +142,7 @@ export function ecImportKey( ); } - const handle = - NitroModules.createHybridObject('KeyObjectHandle'); + const handle = new KeyObjectHandle(); let keyType: number | undefined; try { keyType = handle.initJwk(jwk, namedCurve as NamedCurve); @@ -213,8 +204,7 @@ export function ecImportKey( if (format === 'raw') { // Raw format is only for public keys - use specialized EC raw import - const handle = - NitroModules.createHybridObject('KeyObjectHandle'); + const handle = new KeyObjectHandle(); const curveAlias = kNamedCurveAliases[namedCurve as keyof typeof kNamedCurveAliases]; // Only throw if initialization explicitly fails diff --git a/packages/react-native-quick-crypto/src/ecdh.ts b/packages/react-native-quick-crypto/src/ecdh.ts index 5136a3bed..ef5c124f7 100644 --- a/packages/react-native-quick-crypto/src/ecdh.ts +++ b/packages/react-native-quick-crypto/src/ecdh.ts @@ -1,5 +1,4 @@ -import { NitroModules } from 'react-native-nitro-modules'; -import type { ECDH as ECDHInterface } from './specs/ecdh.nitro'; +import { ECDH as ECDHInterface } from './specs/ecdh.nitro'; import { Buffer } from '@craftzdog/react-native-buffer'; import { toArrayBuffer } from './utils/conversion'; @@ -8,19 +7,10 @@ const POINT_CONVERSION_UNCOMPRESSED = 4; const POINT_CONVERSION_HYBRID = 6; export class ECDH { - private static _convertKeyHybrid: ECDHInterface | undefined; - private static get convertKeyHybrid(): ECDHInterface { - if (!this._convertKeyHybrid) { - this._convertKeyHybrid = - NitroModules.createHybridObject('ECDH'); - } - return this._convertKeyHybrid; - } - private _hybrid: ECDHInterface; constructor(curveName: string) { - this._hybrid = NitroModules.createHybridObject('ECDH'); + this._hybrid = new ECDHInterface(); this._hybrid.init(curveName); } @@ -117,7 +107,7 @@ export class ECDH { } const result = Buffer.from( - ECDH.convertKeyHybrid.convertKey(toArrayBuffer(keyBuf), curve, formatNum), + ECDHInterface.convertKey(toArrayBuffer(keyBuf), curve, formatNum), ); if (outputEncoding) { diff --git a/packages/react-native-quick-crypto/src/ed.ts b/packages/react-native-quick-crypto/src/ed.ts index 926db72f8..b1da6883c 100644 --- a/packages/react-native-quick-crypto/src/ed.ts +++ b/packages/react-native-quick-crypto/src/ed.ts @@ -1,4 +1,3 @@ -import { NitroModules } from 'react-native-nitro-modules'; import { Buffer } from '@craftzdog/react-native-buffer'; import type { AsymmetricKeyObject, PrivateKeyObject } from './keys/classes'; import { @@ -7,8 +6,8 @@ import { PublicKeyObject, PrivateKeyObject as PrivateKeyObjectClass, } from './keys/classes'; -import type { EdKeyPair } from './specs/edKeyPair.nitro'; -import type { KeyObjectHandle as KeyObjectHandleSpec } from './specs/keyObjectHandle.nitro'; +import { EdKeyPair } from './specs/edKeyPair.nitro'; +import { KeyObjectHandle as KeyObjectHandleSpec } from './specs/keyObjectHandle.nitro'; import type { BinaryLike, CFRGKeyPairType, @@ -44,7 +43,7 @@ export class Ed { constructor(type: CFRGKeyPairType, config: KeyPairGenConfig) { this.type = type; this.config = config; - this.native = NitroModules.createHybridObject('EdKeyPair'); + this.native = new EdKeyPair(); this.native.setCurve(type); } @@ -236,8 +235,7 @@ function resolveDhKeyInput( throw new Error(`namedCurve is required for EC raw key in ${name}`); } - const handle = - NitroModules.createHybridObject('KeyObjectHandle'); + const handle = new KeyObjectHandleSpec(); const keyData = toAB(input.key as BinaryLike); if (input.format === 'raw-public') { handle.initRawPublic(input.asymmetricKeyType, keyData, input.namedCurve); diff --git a/packages/react-native-quick-crypto/src/hash.ts b/packages/react-native-quick-crypto/src/hash.ts index d09a0f7ad..073965697 100644 --- a/packages/react-native-quick-crypto/src/hash.ts +++ b/packages/react-native-quick-crypto/src/hash.ts @@ -1,9 +1,8 @@ import { Stream } from 'readable-stream'; -import { NitroModules } from 'react-native-nitro-modules'; import type { TransformOptions } from 'readable-stream'; import { Buffer } from '@craftzdog/react-native-buffer'; -import type { Hash as NativeHash } from './specs/hash.nitro'; -import type { TurboShake as NativeTurboShake } from './specs/turboshake.nitro'; +import { Hash as NativeHash } from './specs/hash.nitro'; +import { TurboShake as NativeTurboShake } from './specs/turboshake.nitro'; import type { BinaryLike, Encoding, @@ -20,9 +19,8 @@ import { lazyDOMException } from './utils/errors'; import { normalizeHashName } from './utils/hashnames'; class HashUtils { - private static native = NitroModules.createHybridObject('Hash'); public static getSupportedHashAlgorithms(): string[] { - return this.native.getSupportedHashAlgorithms(); + return NativeHash.getSupportedHashAlgorithms(); } } @@ -80,7 +78,7 @@ class Hash extends Stream.Transform { return; } - this.native = NitroModules.createHybridObject('Hash'); + this.native = new NativeHash(); this.native.createHash(this.algorithm, this.options.outputLength); } @@ -181,7 +179,7 @@ class Hash extends Stream.Transform { * @since v1.0.0 */ getOpenSSLVersion(): string { - return this.native.getOpenSSLVersion(); + return NativeHash.getOpenSSLVersion(); } // Stream interface — surface synchronous errors via the callback so @@ -305,16 +303,7 @@ export const asyncDigest = async ( // TurboSHAKE / KangarooTwelve are not exposed by OpenSSL EVP, so we route // them to a dedicated Nitro module (cpp/turboshake) that ports the Node.js -// reference implementation. Lazy-load to keep the module out of the hot path -// for callers that only use SHA-2/SHA-3. -let nativeTurboShake: NativeTurboShake | undefined; -const getTurboShake = (): NativeTurboShake => { - if (!nativeTurboShake) { - nativeTurboShake = - NitroModules.createHybridObject('TurboShake'); - } - return nativeTurboShake; -}; +// reference implementation. // RFC 9861 §2.2 default per the WICG Modern Algos draft for TurboSHAKE. const kDefaultTurboShakeDomainSeparation = 0x1f; @@ -351,7 +340,7 @@ const turboShakeDigest = async ( 'OperationError', ); } - return getTurboShake().turboShake( + return NativeTurboShake.turboShake( name, ds, algorithm.outputLength / 8, @@ -383,7 +372,7 @@ const kangarooTwelveDigest = async ( algorithm.customization !== undefined ? bufferLikeToArrayBuffer(algorithm.customization) : undefined; - return getTurboShake().kangarooTwelve( + return NativeTurboShake.kangarooTwelve( name, algorithm.outputLength / 8, bufferLikeToArrayBuffer(data), diff --git a/packages/react-native-quick-crypto/src/hkdf.ts b/packages/react-native-quick-crypto/src/hkdf.ts index f20b0fe6d..d739b5b04 100644 --- a/packages/react-native-quick-crypto/src/hkdf.ts +++ b/packages/react-native-quick-crypto/src/hkdf.ts @@ -1,6 +1,5 @@ import { Buffer } from '@craftzdog/react-native-buffer'; -import { NitroModules } from 'react-native-nitro-modules'; -import type { Hkdf as HkdfNative } from './specs/hkdf.nitro'; +import { Hkdf as HkdfNative } from './specs/hkdf.nitro'; import { binaryLikeToArrayBuffer, normalizeHashName } from './utils'; import type { BinaryLike } from './utils'; import type { CryptoKey } from './keys'; @@ -20,15 +19,6 @@ export interface HkdfCallback { (err: Error | null, derivedKey?: Buffer): void; } -// Lazy load native module -let native: HkdfNative; -function getNative(): HkdfNative { - if (native == null) { - native = NitroModules.createHybridObject('Hkdf'); - } - return native; -} - function validateCallback(callback: HkdfCallback) { if (callback === undefined || typeof callback !== 'function') { throw new Error('No callback provided to hkdf'); @@ -111,24 +101,21 @@ export function hkdf( validateHkdfKeylen(normalizedDigest, keylen); - const nativeMod = getNative(); - nativeMod - .deriveKey( - normalizedDigest, - sanitizedKey, - sanitizedSalt, - sanitizedInfo, - keylen, - 'full', - ) - .then( - res => { - callback(null, Buffer.from(res)); - }, - err => { - callback(err); - }, - ); + HkdfNative.deriveKey( + normalizedDigest, + sanitizedKey, + sanitizedSalt, + sanitizedInfo, + keylen, + 'full', + ).then( + res => { + callback(null, Buffer.from(res)); + }, + err => { + callback(err); + }, + ); } catch (err) { callback(err as Error); } @@ -148,8 +135,7 @@ export function hkdfSync( validateHkdfKeylen(normalizedDigest, keylen); - const nativeMod = getNative(); - const result = nativeMod.deriveKeySync( + const result = HkdfNative.deriveKeySync( normalizedDigest, sanitizedKey, sanitizedSalt, @@ -173,7 +159,7 @@ export function hkdfExtractSync( const sanitizedIkm = sanitizeInput(ikm, 'IKM'); const sanitizedSalt = sanitizeInput(salt, 'Salt'); - const result = getNative().deriveKeySync( + const result = HkdfNative.deriveKeySync( normalizedDigest, sanitizedIkm, sanitizedSalt, @@ -201,19 +187,17 @@ export function hkdfExtract( const sanitizedIkm = sanitizeInput(ikm, 'IKM'); const sanitizedSalt = sanitizeInput(salt, 'Salt'); - getNative() - .deriveKey( - normalizedDigest, - sanitizedIkm, - sanitizedSalt, - new ArrayBuffer(0), - hashLen, - 'extract', - ) - .then( - res => callback(null, Buffer.from(res)), - err => callback(err), - ); + HkdfNative.deriveKey( + normalizedDigest, + sanitizedIkm, + sanitizedSalt, + new ArrayBuffer(0), + hashLen, + 'extract', + ).then( + res => callback(null, Buffer.from(res)), + err => callback(err), + ); } catch (err) { callback(err as Error); } @@ -239,7 +223,7 @@ export function hkdfExpandSync( validateHkdfKeylen(normalizedDigest, keylen); - const result = getNative().deriveKeySync( + const result = HkdfNative.deriveKeySync( normalizedDigest, sanitizedPrk, new ArrayBuffer(0), @@ -274,19 +258,17 @@ export function hkdfExpand( validateHkdfKeylen(normalizedDigest, keylen); - getNative() - .deriveKey( - normalizedDigest, - sanitizedPrk, - new ArrayBuffer(0), - sanitizedInfo, - keylen, - 'expand', - ) - .then( - res => callback(null, Buffer.from(res)), - err => callback(err), - ); + HkdfNative.deriveKey( + normalizedDigest, + sanitizedPrk, + new ArrayBuffer(0), + sanitizedInfo, + keylen, + 'expand', + ).then( + res => callback(null, Buffer.from(res)), + err => callback(err), + ); } catch (err) { callback(err as Error); } @@ -313,8 +295,7 @@ export function hkdfDeriveBits( validateHkdfKeylen(normalizedDigest, keylen); - const nativeMod = getNative(); - const result = nativeMod.deriveKeySync( + const result = HkdfNative.deriveKeySync( normalizedDigest, binaryLikeToArrayBuffer(keyBuffer), binaryLikeToArrayBuffer(salt), diff --git a/packages/react-native-quick-crypto/src/hmac.ts b/packages/react-native-quick-crypto/src/hmac.ts index 1cc8a30ca..75074c6e3 100644 --- a/packages/react-native-quick-crypto/src/hmac.ts +++ b/packages/react-native-quick-crypto/src/hmac.ts @@ -1,8 +1,7 @@ import { Buffer } from '@craftzdog/react-native-buffer'; import { Stream } from 'readable-stream'; -import { NitroModules } from 'react-native-nitro-modules'; import type { TransformOptions } from 'readable-stream'; -import type { Hmac as NativeHmac } from './specs/hmac.nitro'; +import { Hmac as NativeHmac } from './specs/hmac.nitro'; import type { BinaryLike, Encoding } from './utils/types'; import { ab2str, binaryLikeToArrayBuffer } from './utils/conversion'; @@ -35,7 +34,7 @@ class Hmac extends Stream.Transform { this.algorithm = args.algorithm; this.key = args.key; - this.native = NitroModules.createHybridObject('Hmac'); + this.native = new NativeHmac(); this.native.createHmac(this.algorithm, binaryLikeToArrayBuffer(this.key)); } diff --git a/packages/react-native-quick-crypto/src/keys/classes.ts b/packages/react-native-quick-crypto/src/keys/classes.ts index c68bcb05e..863544a7b 100644 --- a/packages/react-native-quick-crypto/src/keys/classes.ts +++ b/packages/react-native-quick-crypto/src/keys/classes.ts @@ -1,14 +1,13 @@ import { Buffer } from '@craftzdog/react-native-buffer'; -import { NitroModules } from 'react-native-nitro-modules'; import type { AsymmetricKeyType, EncodingOptions, JWK, KeyDetail, - KeyObjectHandle, KeyUsage, SubtleAlgorithm, } from '../utils'; +import { KeyObjectHandle } from '../specs/keyObjectHandle.nitro'; import { KeyType, KFormatType, KeyEncoding, getSortedUsages } from '../utils'; import { parsePrivateKeyEncoding, parsePublicKeyEncoding } from './utils'; @@ -105,7 +104,7 @@ export class KeyObject { throw new Error(`invalid KeyObject type: ${type}`); if (handleOrKey instanceof ArrayBuffer) { - this.handle = NitroModules.createHybridObject('KeyObjectHandle'); + this.handle = new KeyObjectHandle(); let keyType: KeyType; switch (type) { case 'public': @@ -155,9 +154,7 @@ export class KeyObject { if (type !== 'secret' && type !== 'public' && type !== 'private') throw new Error(`invalid KeyObject type: ${type}`); - const handle = NitroModules.createHybridObject( - 'KeyObjectHandle', - ) as KeyObjectHandle; + const handle = new KeyObjectHandle(); let keyType: KeyType; switch (type) { case 'public': diff --git a/packages/react-native-quick-crypto/src/keys/index.ts b/packages/react-native-quick-crypto/src/keys/index.ts index dea3b0228..a89377d85 100644 --- a/packages/react-native-quick-crypto/src/keys/index.ts +++ b/packages/react-native-quick-crypto/src/keys/index.ts @@ -27,8 +27,8 @@ import { parsePrivateKeyEncoding, parsePublicKeyEncoding, } from './utils'; -import { NitroModules } from 'react-native-nitro-modules'; -import type { BinaryLike, JWK, KeyObjectHandle } from '../utils'; +import type { BinaryLike, JWK } from '../utils'; +import { KeyObjectHandle } from '../specs/keyObjectHandle.nitro'; import { binaryLikeToArrayBuffer as toAB, isStringOrBuffer, @@ -37,10 +37,8 @@ import { KeyType, } from '../utils'; import { randomBytes } from '../random'; -import type { - SlhDsaKeyPairType, - SlhDsaPrivateKeyFactoryHandle, -} from '../utils'; +import type { SlhDsaKeyPairType } from '../utils'; +import { isSlhDsaPrivateKeyFactoryHandle } from '../utils'; import { SLH_DSA_VARIANTS } from '../slhdsa'; interface KeyInputObject { @@ -73,8 +71,7 @@ function createPublicKeyFromRaw(input: KeyInputObject): PublicKeyObject { if (input.asymmetricKeyType === 'ec' && !input.namedCurve) { throw new Error('options.namedCurve is required for EC raw key import'); } - const handle = - NitroModules.createHybridObject('KeyObjectHandle'); + const handle = new KeyObjectHandle(); handle.initRawPublic( input.asymmetricKeyType, toAB(input.key as BinaryLike), @@ -112,11 +109,11 @@ export async function createPrivateKeyAsync(input: { } catch { throw new Error(error); } - const factory = - NitroModules.createHybridObject( - 'KeyObjectHandle', - ); + const factory = new KeyObjectHandle(); try { + if (!isSlhDsaPrivateKeyFactoryHandle(factory)) { + throw new Error('SLH-DSA raw private key import is unavailable'); + } const handle = await factory.importSlhDsaRawPrivateKey(variant, input.key); try { return new PrivateKeyObject(handle); @@ -145,8 +142,7 @@ function createPrivateKeyFromRaw(input: KeyInputObject): PrivateKeyObject { if (input.asymmetricKeyType === 'ec' && !input.namedCurve) { throw new Error('options.namedCurve is required for EC raw key import'); } - const handle = - NitroModules.createHybridObject('KeyObjectHandle'); + const handle = new KeyObjectHandle(); if (input.format === 'raw-seed') { handle.initRawSeed(input.asymmetricKeyType, toAB(input.key as BinaryLike)); } else { @@ -260,8 +256,7 @@ function createPublicKey(key: KeyInput): PublicKeyObject { return createPublicKeyFromRaw(key as KeyInputObject); } if (typeof key === 'object' && 'key' in key && key.format === 'jwk') { - const handle = - NitroModules.createHybridObject('KeyObjectHandle'); + const handle = new KeyObjectHandle(); const keyType = handle.initJwk(key.key as JWK); if (keyType === undefined) { throw new Error('Failed to import JWK'); @@ -269,8 +264,7 @@ function createPublicKey(key: KeyInput): PublicKeyObject { if (keyType === KeyType.PRIVATE) { // Extract public from private const exported = handle.exportKey(KFormatType.DER, KeyEncoding.SPKI); - const pubHandle = - NitroModules.createHybridObject('KeyObjectHandle'); + const pubHandle = new KeyObjectHandle(); pubHandle.init( KeyType.PUBLIC, exported, @@ -313,8 +307,7 @@ function createPrivateKey(key: KeyInput): PrivateKeyObject { return createPrivateKeyFromRaw(key as KeyInputObject); } if (typeof key === 'object' && 'key' in key && key.format === 'jwk') { - const handle = - NitroModules.createHybridObject('KeyObjectHandle'); + const handle = new KeyObjectHandle(); const keyType = handle.initJwk(key.key as JWK); if (keyType === undefined || keyType !== KeyType.PRIVATE) { throw new Error('Failed to import private key from JWK'); diff --git a/packages/react-native-quick-crypto/src/keys/publicCipher.ts b/packages/react-native-quick-crypto/src/keys/publicCipher.ts index 584e8d762..64fc75eb2 100644 --- a/packages/react-native-quick-crypto/src/keys/publicCipher.ts +++ b/packages/react-native-quick-crypto/src/keys/publicCipher.ts @@ -1,6 +1,5 @@ -import { NitroModules } from 'react-native-nitro-modules'; import { Buffer } from '@craftzdog/react-native-buffer'; -import type { RsaCipher } from '../specs/rsaCipher.nitro'; +import { RsaCipher } from '../specs/rsaCipher.nitro'; import type { BinaryLike } from '../utils'; import { binaryLikeToArrayBuffer as toAB, @@ -108,13 +107,12 @@ export function publicEncrypt( true, ); - const rsaCipher: RsaCipher = NitroModules.createHybridObject('RsaCipher'); const data = toAB(buffer); const paddingMode = padding ?? constants.RSA_PKCS1_OAEP_PADDING; const hashAlgorithm = oaepHash || 'sha1'; try { - const encrypted = rsaCipher.encrypt( + const encrypted = RsaCipher.encrypt( keyHandle.handle, data, paddingMode, @@ -133,12 +131,11 @@ export function publicDecrypt( ): Buffer { const { keyHandle, padding } = preparePublicCipherKey(key, false); - const rsaCipher: RsaCipher = NitroModules.createHybridObject('RsaCipher'); const data = toAB(buffer); const paddingMode = padding ?? constants.RSA_PKCS1_PADDING; try { - const decrypted = rsaCipher.publicDecrypt( + const decrypted = RsaCipher.publicDecrypt( keyHandle.handle, data, paddingMode, @@ -210,12 +207,11 @@ export function privateEncrypt( ): Buffer { const { keyHandle, padding } = preparePrivateCipherKey(key, true); - const rsaCipher: RsaCipher = NitroModules.createHybridObject('RsaCipher'); const data = toAB(buffer); const paddingMode = padding ?? constants.RSA_PKCS1_PADDING; try { - const encrypted = rsaCipher.privateEncrypt( + const encrypted = RsaCipher.privateEncrypt( keyHandle.handle, data, paddingMode, @@ -235,13 +231,12 @@ export function privateDecrypt( false, ); - const rsaCipher: RsaCipher = NitroModules.createHybridObject('RsaCipher'); const data = toAB(buffer); const paddingMode = padding ?? constants.RSA_PKCS1_OAEP_PADDING; const hashAlgorithm = oaepHash || 'sha1'; try { - const decrypted = rsaCipher.privateDecrypt( + const decrypted = RsaCipher.privateDecrypt( keyHandle.handle, data, paddingMode, diff --git a/packages/react-native-quick-crypto/src/keys/signVerify.ts b/packages/react-native-quick-crypto/src/keys/signVerify.ts index f25996b3b..a6bdf3ead 100644 --- a/packages/react-native-quick-crypto/src/keys/signVerify.ts +++ b/packages/react-native-quick-crypto/src/keys/signVerify.ts @@ -1,6 +1,5 @@ import { Buffer } from '@craftzdog/react-native-buffer'; -import { NitroModules } from 'react-native-nitro-modules'; -import type { +import { SignHandle as SignHandleSpec, VerifyHandle as VerifyHandleSpec, } from '../specs/sign.nitro'; @@ -159,7 +158,7 @@ export class Sign { private handle: SignHandleSpec; constructor(algorithm: string) { - this.handle = NitroModules.createHybridObject('SignHandle'); + this.handle = new SignHandleSpec(); this.handle.init(algorithm); } @@ -196,8 +195,7 @@ export class Verify { private handle: VerifyHandleSpec; constructor(algorithm: string) { - this.handle = - NitroModules.createHybridObject('VerifyHandle'); + this.handle = new VerifyHandleSpec(); this.handle.init(algorithm); } diff --git a/packages/react-native-quick-crypto/src/mldsa.ts b/packages/react-native-quick-crypto/src/mldsa.ts index 0c9234e7e..81e2f93c7 100644 --- a/packages/react-native-quick-crypto/src/mldsa.ts +++ b/packages/react-native-quick-crypto/src/mldsa.ts @@ -1,5 +1,4 @@ -import { NitroModules } from 'react-native-nitro-modules'; -import type { MlDsaKeyPair } from './specs/mlDsaKeyPair.nitro'; +import { MlDsaKeyPair } from './specs/mlDsaKeyPair.nitro'; import { CryptoKey, KeyObject, @@ -23,7 +22,7 @@ export class MlDsa { constructor(variant: MlDsaVariant) { this.variant = variant; - this.native = NitroModules.createHybridObject('MlDsaKeyPair'); + this.native = new MlDsaKeyPair(); this.native.setVariant(variant); } diff --git a/packages/react-native-quick-crypto/src/mlkem.ts b/packages/react-native-quick-crypto/src/mlkem.ts index 090ac6393..88d406b8c 100644 --- a/packages/react-native-quick-crypto/src/mlkem.ts +++ b/packages/react-native-quick-crypto/src/mlkem.ts @@ -1,5 +1,4 @@ -import { NitroModules } from 'react-native-nitro-modules'; -import type { MlKemKeyPair } from './specs/mlKemKeyPair.nitro'; +import { MlKemKeyPair } from './specs/mlKemKeyPair.nitro'; import { CryptoKey, KeyObject, @@ -65,7 +64,7 @@ export class MlKem { constructor(variant: MlKemVariant) { this.variant = variant; - this.native = NitroModules.createHybridObject('MlKemKeyPair'); + this.native = new MlKemKeyPair(); this.native.setVariant(variant); } diff --git a/packages/react-native-quick-crypto/src/pbkdf2.ts b/packages/react-native-quick-crypto/src/pbkdf2.ts index 6a8f7e49a..5c6761e93 100644 --- a/packages/react-native-quick-crypto/src/pbkdf2.ts +++ b/packages/react-native-quick-crypto/src/pbkdf2.ts @@ -1,5 +1,4 @@ import { Buffer } from '@craftzdog/react-native-buffer'; -import { NitroModules } from 'react-native-nitro-modules'; import type { BinaryLike } from './utils'; import { HashContext, @@ -9,7 +8,7 @@ import { normalizeHashName, } from './utils'; import type { SubtleAlgorithm } from './utils'; -import type { Pbkdf2 } from './specs/pbkdf2.nitro'; +import { Pbkdf2 } from './specs/pbkdf2.nitro'; import { promisify } from 'util'; import type { CryptoKey } from './keys'; @@ -21,16 +20,6 @@ type Password = BinaryLike; type Salt = BinaryLike; type Pbkdf2Callback = (err: Error | null, derivedKey?: Buffer) => void; -// to use native bits in sub-functions, use getNative(). don't call it at top-level! -let native: Pbkdf2; -function getNative(): Pbkdf2 { - if (native == null) { - // lazy-load the Nitro HybridObject - native = NitroModules.createHybridObject('Pbkdf2'); - } - return native; -} - const MAX_INT32 = 2147483647; function validateParameters(iterations: number, keylen: number): void { @@ -83,23 +72,20 @@ export function pbkdf2( const sanitizedSalt = sanitizeInput(salt, WRONG_SALT); const normalizedDigest = normalizeHashName(digest, HashContext.Node); - getNative(); - native - .pbkdf2( - sanitizedPassword, - sanitizedSalt, - iterations, - keylen, - normalizedDigest, - ) - .then( - (res: ArrayBuffer) => { - callback!(null, Buffer.from(res)); - }, - (e: Error) => { - callback!(e); - }, - ); + Pbkdf2.pbkdf2( + sanitizedPassword, + sanitizedSalt, + iterations, + keylen, + normalizedDigest, + ).then( + (res: ArrayBuffer) => { + callback!(null, Buffer.from(res)); + }, + (e: Error) => { + callback!(e); + }, + ); } export function pbkdf2Sync( @@ -114,8 +100,7 @@ export function pbkdf2Sync( const sanitizedSalt = sanitizeInput(salt, WRONG_SALT); const algo = normalizeHashName(digest, HashContext.Node); - getNative(); - const result: ArrayBuffer = native.pbkdf2Sync( + const result: ArrayBuffer = Pbkdf2.pbkdf2Sync( sanitizedPassword, sanitizedSalt, iterations, diff --git a/packages/react-native-quick-crypto/src/prime.ts b/packages/react-native-quick-crypto/src/prime.ts index 944d13999..be11bb3a9 100644 --- a/packages/react-native-quick-crypto/src/prime.ts +++ b/packages/react-native-quick-crypto/src/prime.ts @@ -1,17 +1,8 @@ -import { NitroModules } from 'react-native-nitro-modules'; import { Buffer } from '@craftzdog/react-native-buffer'; -import type { Prime as NativePrime } from './specs/prime.nitro'; +import { Prime as NativePrime } from './specs/prime.nitro'; import type { BinaryLike } from './utils'; import { binaryLikeToArrayBuffer } from './utils'; -let native: NativePrime; -function getNative(): NativePrime { - if (native == null) { - native = NitroModules.createHybridObject('Prime'); - } - return native; -} - export interface GeneratePrimeOptions { safe?: boolean; bigint?: boolean; @@ -58,7 +49,7 @@ export function generatePrimeSync( const add = toOptionalArrayBuffer(options?.add); const rem = toOptionalArrayBuffer(options?.rem); const result = Buffer.from( - getNative().generatePrimeSync(size, safe, add, rem), + NativePrime.generatePrimeSync(size, safe, add, rem), ); if (options?.bigint) { return bufferToBigInt(result); @@ -85,8 +76,7 @@ export function generatePrime( const rem = toOptionalArrayBuffer(options?.rem); const wantBigint = options?.bigint ?? false; - getNative() - .generatePrime(size, safe, add, rem) + NativePrime.generatePrime(size, safe, add, rem) .then(ab => { const result = Buffer.from(ab); if (wantBigint) { @@ -107,7 +97,7 @@ export function checkPrimeSync( typeof candidate === 'bigint' ? bigIntToBuffer(candidate) : binaryLikeToArrayBuffer(candidate); - return getNative().checkPrimeSync(buf, checks); + return NativePrime.checkPrimeSync(buf, checks); } type CheckPrimeCallback = (err: Error | null, result: boolean) => void; @@ -127,8 +117,7 @@ export function checkPrime( ? bigIntToBuffer(candidate) : binaryLikeToArrayBuffer(candidate); - getNative() - .checkPrime(buf, checks) + NativePrime.checkPrime(buf, checks) .then(result => callback?.(null, result)) .catch((err: Error) => callback?.(err, false)); } diff --git a/packages/react-native-quick-crypto/src/random.ts b/packages/react-native-quick-crypto/src/random.ts index fabc6c557..8ee0873b8 100644 --- a/packages/react-native-quick-crypto/src/random.ts +++ b/packages/react-native-quick-crypto/src/random.ts @@ -6,18 +6,7 @@ import { QuotaExceededError, rejectSharedArrayBuffer, } from './utils'; -import { NitroModules } from 'react-native-nitro-modules'; -import type { Random } from './specs/random.nitro'; - -// to use native bits in sub-functions, use getNative(). don't call it at top-level! -let random: Random; -function getNative(): Random { - if (random == null) { - // lazy-load the Nitro HybridObject - random = NitroModules.createHybridObject('Random'); - } - return random; -} +import { Random } from './specs/random.nitro'; export function randomFill( buffer: T, @@ -63,10 +52,9 @@ export function randomFill(buffer: ABV, ...rest: unknown[]): void { size = viewLength - offset; } - getNative(); const ab = abvToArrayBuffer(buffer); const start = viewOffset + offset; - random.randomFill(ab, start, size).then( + Random.randomFill(ab, start, size).then( (res: ArrayBuffer) => { // The native async path operates on a copy of the underlying buffer to // avoid races with JS-owned memory on the worker thread, so the @@ -90,11 +78,10 @@ export function randomFillSync( ): T; export function randomFillSync(buffer: ABV, offset: number = 0, size?: number) { - getNative(); const viewOffset = ArrayBuffer.isView(buffer) ? buffer.byteOffset : 0; const viewLength = buffer.byteLength; const arrayBuffer = abvToArrayBuffer(buffer); - random.randomFillSync( + Random.randomFillSync( arrayBuffer, viewOffset + offset, size ?? viewLength - offset, diff --git a/packages/react-native-quick-crypto/src/rsa.ts b/packages/react-native-quick-crypto/src/rsa.ts index f5852bfbb..7ccb6ee5f 100644 --- a/packages/react-native-quick-crypto/src/rsa.ts +++ b/packages/react-native-quick-crypto/src/rsa.ts @@ -1,4 +1,3 @@ -import { NitroModules } from 'react-native-nitro-modules'; import { Buffer } from '@craftzdog/react-native-buffer'; import { CryptoKey, @@ -22,7 +21,7 @@ import type { GenerateKeyPairOptions, KeyPairGenConfig, } from './utils'; -import type { RsaKeyPair } from './specs/rsaKeyPair.nitro'; +import { RsaKeyPair } from './specs/rsaKeyPair.nitro'; export class Rsa { native: RsaKeyPair; @@ -32,7 +31,7 @@ export class Rsa { publicExponent: Uint8Array, hashAlgorithm: string, ) { - this.native = NitroModules.createHybridObject('RsaKeyPair'); + this.native = new RsaKeyPair(); this.native.setModulusLength(modulusLength); this.native.setPublicExponent( publicExponent.buffer.slice( diff --git a/packages/react-native-quick-crypto/src/scrypt.ts b/packages/react-native-quick-crypto/src/scrypt.ts index b4315add9..183e24045 100644 --- a/packages/react-native-quick-crypto/src/scrypt.ts +++ b/packages/react-native-quick-crypto/src/scrypt.ts @@ -1,6 +1,5 @@ import { Buffer } from '@craftzdog/react-native-buffer'; -import { NitroModules } from 'react-native-nitro-modules'; -import type { Scrypt as NativeScrypt } from './specs/scrypt.nitro'; +import { Scrypt as NativeScrypt } from './specs/scrypt.nitro'; import { binaryLikeToArrayBuffer } from './utils'; import type { BinaryLike } from './utils'; @@ -19,15 +18,6 @@ export interface ScryptOptions { type ScryptCallback = (err: Error | null, derivedKey?: Buffer) => void; -// Lazy load native module -let native: NativeScrypt; -function getNative(): NativeScrypt { - if (native == null) { - native = NitroModules.createHybridObject('Scrypt'); - } - return native; -} - const defaults = { N: 16384, r: 8, @@ -158,17 +148,22 @@ export function scrypt( validateScryptKeylen(keylen); - const nativeMod = getNative(); - nativeMod - .deriveKey(sanitizedPassword, sanitizedSalt, N, r, p, maxmem, keylen) - .then( - res => { - cb(null, Buffer.from(res)); - }, - err => { - cb(err); - }, - ); + NativeScrypt.deriveKey( + sanitizedPassword, + sanitizedSalt, + N, + r, + p, + maxmem, + keylen, + ).then( + res => { + cb(null, Buffer.from(res)); + }, + err => { + cb(err); + }, + ); } catch (err) { cb(err as Error); } @@ -186,8 +181,7 @@ export function scryptSync( validateScryptKeylen(keylen); - const nativeMod = getNative(); - const result = nativeMod.deriveKeySync( + const result = NativeScrypt.deriveKeySync( sanitizedPassword, sanitizedSalt, N, diff --git a/packages/react-native-quick-crypto/src/slhdsa.ts b/packages/react-native-quick-crypto/src/slhdsa.ts index 4af1f75d6..66ada0422 100644 --- a/packages/react-native-quick-crypto/src/slhdsa.ts +++ b/packages/react-native-quick-crypto/src/slhdsa.ts @@ -1,5 +1,4 @@ -import { NitroModules } from 'react-native-nitro-modules'; -import type { SlhDsaKeyPair } from './specs/slhDsaKeyPair.nitro'; +import { SlhDsaKeyPair } from './specs/slhDsaKeyPair.nitro'; import { CryptoKey, KeyObject, @@ -43,8 +42,7 @@ export class SlhDsa { constructor(variant: SlhDsaVariant) { this.variant = variant; - this.native = - NitroModules.createHybridObject('SlhDsaKeyPair'); + this.native = new SlhDsaKeyPair(); this.native.setVariant(variant); } diff --git a/packages/react-native-quick-crypto/src/specs/argon2.nitro.ts b/packages/react-native-quick-crypto/src/specs/argon2.nitro.ts index a623b44ca..1d42894cc 100644 --- a/packages/react-native-quick-crypto/src/specs/argon2.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/argon2.nitro.ts @@ -1,7 +1,16 @@ -import type { HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/Argon2'; -export interface Argon2 extends HybridObject<{ ios: 'c++'; android: 'c++' }> { - hash( +@Apple({ + language: 'c++', + implementation: { className: 'HybridArgon2', include: '"HybridArgon2.hpp"' }, +}) +@Android({ + language: 'c++', + implementation: { className: 'HybridArgon2', include: '"HybridArgon2.hpp"' }, +}) +export declare class Argon2 extends HybridObject { + static hash( algorithm: string, message: ArrayBuffer, nonce: ArrayBuffer, @@ -14,7 +23,7 @@ export interface Argon2 extends HybridObject<{ ios: 'c++'; android: 'c++' }> { associatedData?: ArrayBuffer, ): Promise; - hashSync( + static hashSync( algorithm: string, message: ArrayBuffer, nonce: ArrayBuffer, diff --git a/packages/react-native-quick-crypto/src/specs/blake3.nitro.ts b/packages/react-native-quick-crypto/src/specs/blake3.nitro.ts index 76d13a55c..b75230880 100644 --- a/packages/react-native-quick-crypto/src/specs/blake3.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/blake3.nitro.ts @@ -1,6 +1,16 @@ -import type { HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/Blake3'; -export interface Blake3 extends HybridObject<{ ios: 'c++'; android: 'c++' }> { +@Apple({ + language: 'c++', + implementation: { className: 'HybridBlake3', include: '"HybridBlake3.hpp"' }, +}) +@Android({ + language: 'c++', + implementation: { className: 'HybridBlake3', include: '"HybridBlake3.hpp"' }, +}) +export declare class Blake3 extends HybridObject { + constructor(); initHash(): void; initKeyed(key: ArrayBuffer): void; initDeriveKey(context: string): void; @@ -8,5 +18,5 @@ export interface Blake3 extends HybridObject<{ ios: 'c++'; android: 'c++' }> { digest(length?: number): ArrayBuffer; reset(): void; copy(): Blake3; - getVersion(): string; + static getVersion(): string; } diff --git a/packages/react-native-quick-crypto/src/specs/certificate.nitro.ts b/packages/react-native-quick-crypto/src/specs/certificate.nitro.ts index 37c4ee41b..83404a979 100644 --- a/packages/react-native-quick-crypto/src/specs/certificate.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/certificate.nitro.ts @@ -1,8 +1,22 @@ -import type { HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/Certificate'; -export interface Certificate - extends HybridObject<{ ios: 'c++'; android: 'c++' }> { - verifySpkac(spkac: ArrayBuffer): boolean; - exportPublicKey(spkac: ArrayBuffer): ArrayBuffer; - exportChallenge(spkac: ArrayBuffer): ArrayBuffer; +@Apple({ + language: 'c++', + implementation: { + className: 'HybridCertificate', + include: '"HybridCertificate.hpp"', + }, +}) +@Android({ + language: 'c++', + implementation: { + className: 'HybridCertificate', + include: '"HybridCertificate.hpp"', + }, +}) +export declare class Certificate extends HybridObject { + static verifySpkac(spkac: ArrayBuffer): boolean; + static exportPublicKey(spkac: ArrayBuffer): ArrayBuffer; + static exportChallenge(spkac: ArrayBuffer): ArrayBuffer; } diff --git a/packages/react-native-quick-crypto/src/specs/cipher.nitro.ts b/packages/react-native-quick-crypto/src/specs/cipher.nitro.ts index 362f11d0b..9a0301e89 100644 --- a/packages/react-native-quick-crypto/src/specs/cipher.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/cipher.nitro.ts @@ -1,4 +1,6 @@ -import type { HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/Cipher'; +export * from '#nitro/CipherFactory'; type CipherArgs = { isCipher: boolean; @@ -17,7 +19,15 @@ interface CipherInfo { ivLength?: number; } -export interface Cipher extends HybridObject<{ ios: 'c++'; android: 'c++' }> { +@Apple({ + language: 'c++', + implementation: { className: 'HybridCipher', include: '"HybridCipher.hpp"' }, +}) +@Android({ + language: 'c++', + implementation: { className: 'HybridCipher', include: '"HybridCipher.hpp"' }, +}) +export declare class Cipher extends HybridObject { update(data: ArrayBuffer): ArrayBuffer; final(): ArrayBuffer; setArgs(args: CipherArgs): void; @@ -25,15 +35,28 @@ export interface Cipher extends HybridObject<{ ios: 'c++'; android: 'c++' }> { setAutoPadding(autoPad: boolean): boolean; setAuthTag(tag: ArrayBuffer): boolean; getAuthTag(): ArrayBuffer; - getSupportedCiphers(): string[]; - getCipherInfo( + static getSupportedCiphers(): string[]; + static getCipherInfo( name: string, keyLength?: number, ivLength?: number, ): CipherInfo | undefined; } -export interface CipherFactory - extends HybridObject<{ ios: 'c++'; android: 'c++' }> { - createCipher(args: CipherArgs): Cipher; +@Apple({ + language: 'c++', + implementation: { + className: 'HybridCipherFactory', + include: '"HybridCipherFactory.hpp"', + }, +}) +@Android({ + language: 'c++', + implementation: { + className: 'HybridCipherFactory', + include: '"HybridCipherFactory.hpp"', + }, +}) +export declare class CipherFactory extends HybridObject { + static createCipher(args: CipherArgs): Cipher; } diff --git a/packages/react-native-quick-crypto/src/specs/dhKeyPair.nitro.ts b/packages/react-native-quick-crypto/src/specs/dhKeyPair.nitro.ts index 0f943e9a1..5a7bf8f8f 100644 --- a/packages/react-native-quick-crypto/src/specs/dhKeyPair.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/dhKeyPair.nitro.ts @@ -1,7 +1,22 @@ -import type { HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/DhKeyPair'; -export interface DhKeyPair - extends HybridObject<{ ios: 'c++'; android: 'c++' }> { +@Apple({ + language: 'c++', + implementation: { + className: 'HybridDhKeyPair', + include: '"HybridDhKeyPair.hpp"', + }, +}) +@Android({ + language: 'c++', + implementation: { + className: 'HybridDhKeyPair', + include: '"HybridDhKeyPair.hpp"', + }, +}) +export declare class DhKeyPair extends HybridObject { + constructor(); generateKeyPair(): Promise; generateKeyPairSync(): void; diff --git a/packages/react-native-quick-crypto/src/specs/diffie-hellman.nitro.ts b/packages/react-native-quick-crypto/src/specs/diffie-hellman.nitro.ts index afcb8a369..d1f96762a 100644 --- a/packages/react-native-quick-crypto/src/specs/diffie-hellman.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/diffie-hellman.nitro.ts @@ -1,7 +1,22 @@ -import type { HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/DiffieHellman'; -export interface DiffieHellman - extends HybridObject<{ ios: 'c++'; android: 'c++' }> { +@Apple({ + language: 'c++', + implementation: { + className: 'HybridDiffieHellman', + include: '"HybridDiffieHellman.hpp"', + }, +}) +@Android({ + language: 'c++', + implementation: { + className: 'HybridDiffieHellman', + include: '"HybridDiffieHellman.hpp"', + }, +}) +export declare class DiffieHellman extends HybridObject { + constructor(); init(prime: ArrayBuffer, generator: ArrayBuffer): void; initWithSize(primeLength: number, generator: number): void; generateKeys(): ArrayBuffer; diff --git a/packages/react-native-quick-crypto/src/specs/dsaKeyPair.nitro.ts b/packages/react-native-quick-crypto/src/specs/dsaKeyPair.nitro.ts index 82eb0cc73..b52120b27 100644 --- a/packages/react-native-quick-crypto/src/specs/dsaKeyPair.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/dsaKeyPair.nitro.ts @@ -1,7 +1,22 @@ -import type { HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/DsaKeyPair'; -export interface DsaKeyPair - extends HybridObject<{ ios: 'c++'; android: 'c++' }> { +@Apple({ + language: 'c++', + implementation: { + className: 'HybridDsaKeyPair', + include: '"HybridDsaKeyPair.hpp"', + }, +}) +@Android({ + language: 'c++', + implementation: { + className: 'HybridDsaKeyPair', + include: '"HybridDsaKeyPair.hpp"', + }, +}) +export declare class DsaKeyPair extends HybridObject { + constructor(); generateKeyPair(): Promise; generateKeyPairSync(): void; diff --git a/packages/react-native-quick-crypto/src/specs/ecKeyPair.nitro.ts b/packages/react-native-quick-crypto/src/specs/ecKeyPair.nitro.ts index bbba7662e..8ac38dd3d 100644 --- a/packages/react-native-quick-crypto/src/specs/ecKeyPair.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/ecKeyPair.nitro.ts @@ -1,12 +1,27 @@ -import type { HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/EcKeyPair'; // Nitro-compatible interfaces defined locally interface KeyObject { extractable: boolean; } -export interface EcKeyPair - extends HybridObject<{ ios: 'c++'; android: 'c++' }> { +@Apple({ + language: 'c++', + implementation: { + className: 'HybridEcKeyPair', + include: '"HybridEcKeyPair.hpp"', + }, +}) +@Android({ + language: 'c++', + implementation: { + className: 'HybridEcKeyPair', + include: '"HybridEcKeyPair.hpp"', + }, +}) +export declare class EcKeyPair extends HybridObject { + constructor(); // generateKeyPair functions generateKeyPair(): Promise; generateKeyPairSync(): void; @@ -36,5 +51,5 @@ export interface EcKeyPair hashAlgorithm: string, ): boolean; - getSupportedCurves(): string[]; + static getSupportedCurves(): string[]; } diff --git a/packages/react-native-quick-crypto/src/specs/ecdh.nitro.ts b/packages/react-native-quick-crypto/src/specs/ecdh.nitro.ts index 17674bfc9..a19e92bdc 100644 --- a/packages/react-native-quick-crypto/src/specs/ecdh.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/ecdh.nitro.ts @@ -1,6 +1,16 @@ -import type { HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/ECDH'; -export interface ECDH extends HybridObject<{ ios: 'c++'; android: 'c++' }> { +@Apple({ + language: 'c++', + implementation: { className: 'HybridECDH', include: '"HybridECDH.hpp"' }, +}) +@Android({ + language: 'c++', + implementation: { className: 'HybridECDH', include: '"HybridECDH.hpp"' }, +}) +export declare class ECDH extends HybridObject { + constructor(); init(curveName: string): void; generateKeys(): ArrayBuffer; computeSecret(otherPublicKey: ArrayBuffer): ArrayBuffer; @@ -8,5 +18,9 @@ export interface ECDH extends HybridObject<{ ios: 'c++'; android: 'c++' }> { setPrivateKey(privateKey: ArrayBuffer): void; getPublicKey(): ArrayBuffer; setPublicKey(publicKey: ArrayBuffer): void; - convertKey(key: ArrayBuffer, curve: string, format: number): ArrayBuffer; + static convertKey( + key: ArrayBuffer, + curve: string, + format: number, + ): ArrayBuffer; } diff --git a/packages/react-native-quick-crypto/src/specs/edKeyPair.nitro.ts b/packages/react-native-quick-crypto/src/specs/edKeyPair.nitro.ts index 92a552106..3f4ee6b8d 100644 --- a/packages/react-native-quick-crypto/src/specs/edKeyPair.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/edKeyPair.nitro.ts @@ -1,7 +1,22 @@ -import type { HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/EdKeyPair'; -export interface EdKeyPair - extends HybridObject<{ ios: 'c++'; android: 'c++' }> { +@Apple({ + language: 'c++', + implementation: { + className: 'HybridEdKeyPair', + include: '"HybridEdKeyPair.hpp"', + }, +}) +@Android({ + language: 'c++', + implementation: { + className: 'HybridEdKeyPair', + include: '"HybridEdKeyPair.hpp"', + }, +}) +export declare class EdKeyPair extends HybridObject { + constructor(); diffieHellman(privateKey: ArrayBuffer, publicKey: ArrayBuffer): ArrayBuffer; generateKeyPair( diff --git a/packages/react-native-quick-crypto/src/specs/hash.nitro.ts b/packages/react-native-quick-crypto/src/specs/hash.nitro.ts index ad2039721..6e5977cd9 100644 --- a/packages/react-native-quick-crypto/src/specs/hash.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/hash.nitro.ts @@ -1,10 +1,20 @@ -import type { HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/Hash'; -export interface Hash extends HybridObject<{ ios: 'c++'; android: 'c++' }> { +@Apple({ + language: 'c++', + implementation: { className: 'HybridHash', include: '"HybridHash.hpp"' }, +}) +@Android({ + language: 'c++', + implementation: { className: 'HybridHash', include: '"HybridHash.hpp"' }, +}) +export declare class Hash extends HybridObject { + constructor(); createHash(algorithm: string, outputLength?: number): void; update(data: ArrayBuffer | string): void; digest(encoding?: string): ArrayBuffer; copy(outputLength?: number): Hash; - getSupportedHashAlgorithms(): string[]; - getOpenSSLVersion(): string; + static getSupportedHashAlgorithms(): string[]; + static getOpenSSLVersion(): string; } diff --git a/packages/react-native-quick-crypto/src/specs/hkdf.nitro.ts b/packages/react-native-quick-crypto/src/specs/hkdf.nitro.ts index c98ebe5f5..367be0c75 100644 --- a/packages/react-native-quick-crypto/src/specs/hkdf.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/hkdf.nitro.ts @@ -1,11 +1,20 @@ -import type { HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/Hkdf'; // RFC 5869 stage: 'full' (extract+expand), 'extract' (PRK only), or // 'expand' (from an existing PRK). export type HkdfMode = 'full' | 'extract' | 'expand'; -export interface Hkdf extends HybridObject<{ ios: 'c++'; android: 'c++' }> { - deriveKeySync( +@Apple({ + language: 'c++', + implementation: { className: 'HybridHkdf', include: '"HybridHkdf.hpp"' }, +}) +@Android({ + language: 'c++', + implementation: { className: 'HybridHkdf', include: '"HybridHkdf.hpp"' }, +}) +export declare class Hkdf extends HybridObject { + static deriveKeySync( algorithm: string, key: ArrayBuffer, salt: ArrayBuffer, @@ -14,7 +23,7 @@ export interface Hkdf extends HybridObject<{ ios: 'c++'; android: 'c++' }> { mode: HkdfMode, ): ArrayBuffer; - deriveKey( + static deriveKey( algorithm: string, key: ArrayBuffer, salt: ArrayBuffer, diff --git a/packages/react-native-quick-crypto/src/specs/hmac.nitro.ts b/packages/react-native-quick-crypto/src/specs/hmac.nitro.ts index 489e4eb91..d050bc32e 100644 --- a/packages/react-native-quick-crypto/src/specs/hmac.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/hmac.nitro.ts @@ -1,6 +1,16 @@ -import type { HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/Hmac'; -export interface Hmac extends HybridObject<{ ios: 'c++'; android: 'c++' }> { +@Apple({ + language: 'c++', + implementation: { className: 'HybridHmac', include: '"HybridHmac.hpp"' }, +}) +@Android({ + language: 'c++', + implementation: { className: 'HybridHmac', include: '"HybridHmac.hpp"' }, +}) +export declare class Hmac extends HybridObject { + constructor(); createHmac(algorithm: string, key: ArrayBuffer): void; update(data: ArrayBuffer | string): void; digest(): ArrayBuffer; diff --git a/packages/react-native-quick-crypto/src/specs/keyObjectHandle.nitro.ts b/packages/react-native-quick-crypto/src/specs/keyObjectHandle.nitro.ts index b964716c1..8b9b0e11c 100644 --- a/packages/react-native-quick-crypto/src/specs/keyObjectHandle.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/keyObjectHandle.nitro.ts @@ -1,4 +1,5 @@ -import { type HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/KeyObjectHandle'; import type { AsymmetricKeyType, JWK, @@ -9,8 +10,22 @@ import type { NamedCurve, } from '../utils'; -export interface KeyObjectHandle - extends HybridObject<{ ios: 'c++'; android: 'c++' }> { +@Apple({ + language: 'c++', + implementation: { + className: 'HybridKeyObjectHandle', + include: '"HybridKeyObjectHandle.hpp"', + }, +}) +@Android({ + language: 'c++', + implementation: { + className: 'HybridKeyObjectHandle', + include: '"HybridKeyObjectHandle.hpp"', + }, +}) +export declare class KeyObjectHandle extends HybridObject { + constructor(); exportKey( format?: KFormatType, type?: KeyEncoding, diff --git a/packages/react-native-quick-crypto/src/specs/kmac.nitro.ts b/packages/react-native-quick-crypto/src/specs/kmac.nitro.ts index 14c52000c..003b4b8fa 100644 --- a/packages/react-native-quick-crypto/src/specs/kmac.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/kmac.nitro.ts @@ -1,6 +1,16 @@ -import type { HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/Kmac'; -export interface Kmac extends HybridObject<{ ios: 'c++'; android: 'c++' }> { +@Apple({ + language: 'c++', + implementation: { className: 'HybridKmac', include: '"HybridKmac.hpp"' }, +}) +@Android({ + language: 'c++', + implementation: { className: 'HybridKmac', include: '"HybridKmac.hpp"' }, +}) +export declare class Kmac extends HybridObject { + constructor(); createKmac( algorithm: string, key: ArrayBuffer, diff --git a/packages/react-native-quick-crypto/src/specs/mlDsaKeyPair.nitro.ts b/packages/react-native-quick-crypto/src/specs/mlDsaKeyPair.nitro.ts index d7bfbcb26..759a6228a 100644 --- a/packages/react-native-quick-crypto/src/specs/mlDsaKeyPair.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/mlDsaKeyPair.nitro.ts @@ -1,7 +1,22 @@ -import type { HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/MlDsaKeyPair'; -export interface MlDsaKeyPair - extends HybridObject<{ ios: 'c++'; android: 'c++' }> { +@Apple({ + language: 'c++', + implementation: { + className: 'HybridMlDsaKeyPair', + include: '"HybridMlDsaKeyPair.hpp"', + }, +}) +@Android({ + language: 'c++', + implementation: { + className: 'HybridMlDsaKeyPair', + include: '"HybridMlDsaKeyPair.hpp"', + }, +}) +export declare class MlDsaKeyPair extends HybridObject { + constructor(); generateKeyPair( publicFormat: number, publicType: number, diff --git a/packages/react-native-quick-crypto/src/specs/mlKemKeyPair.nitro.ts b/packages/react-native-quick-crypto/src/specs/mlKemKeyPair.nitro.ts index f465cfcdb..038cd0caf 100644 --- a/packages/react-native-quick-crypto/src/specs/mlKemKeyPair.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/mlKemKeyPair.nitro.ts @@ -1,7 +1,22 @@ -import type { HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/MlKemKeyPair'; -export interface MlKemKeyPair - extends HybridObject<{ ios: 'c++'; android: 'c++' }> { +@Apple({ + language: 'c++', + implementation: { + className: 'HybridMlKemKeyPair', + include: '"HybridMlKemKeyPair.hpp"', + }, +}) +@Android({ + language: 'c++', + implementation: { + className: 'HybridMlKemKeyPair', + include: '"HybridMlKemKeyPair.hpp"', + }, +}) +export declare class MlKemKeyPair extends HybridObject { + constructor(); setVariant(variant: string): void; generateKeyPair( diff --git a/packages/react-native-quick-crypto/src/specs/pbkdf2.nitro.ts b/packages/react-native-quick-crypto/src/specs/pbkdf2.nitro.ts index ccddfe3d5..081c22c4c 100644 --- a/packages/react-native-quick-crypto/src/specs/pbkdf2.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/pbkdf2.nitro.ts @@ -1,14 +1,23 @@ -import { type HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/Pbkdf2'; -export interface Pbkdf2 extends HybridObject<{ ios: 'c++'; android: 'c++' }> { - pbkdf2( +@Apple({ + language: 'c++', + implementation: { className: 'HybridPbkdf2', include: '"HybridPbkdf2.hpp"' }, +}) +@Android({ + language: 'c++', + implementation: { className: 'HybridPbkdf2', include: '"HybridPbkdf2.hpp"' }, +}) +export declare class Pbkdf2 extends HybridObject { + static pbkdf2( password: ArrayBuffer, salt: ArrayBuffer, iterations: number, keylen: number, digest: string, ): Promise; - pbkdf2Sync( + static pbkdf2Sync( password: ArrayBuffer, salt: ArrayBuffer, iterations: number, diff --git a/packages/react-native-quick-crypto/src/specs/prime.nitro.ts b/packages/react-native-quick-crypto/src/specs/prime.nitro.ts index d18191926..df15b81fa 100644 --- a/packages/react-native-quick-crypto/src/specs/prime.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/prime.nitro.ts @@ -1,18 +1,27 @@ -import { type HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/Prime'; -export interface Prime extends HybridObject<{ ios: 'c++'; android: 'c++' }> { - generatePrime( +@Apple({ + language: 'c++', + implementation: { className: 'HybridPrime', include: '"HybridPrime.hpp"' }, +}) +@Android({ + language: 'c++', + implementation: { className: 'HybridPrime', include: '"HybridPrime.hpp"' }, +}) +export declare class Prime extends HybridObject { + static generatePrime( size: number, safe: boolean, add?: ArrayBuffer, rem?: ArrayBuffer, ): Promise; - generatePrimeSync( + static generatePrimeSync( size: number, safe: boolean, add?: ArrayBuffer, rem?: ArrayBuffer, ): ArrayBuffer; - checkPrime(candidate: ArrayBuffer, checks: number): Promise; - checkPrimeSync(candidate: ArrayBuffer, checks: number): boolean; + static checkPrime(candidate: ArrayBuffer, checks: number): Promise; + static checkPrimeSync(candidate: ArrayBuffer, checks: number): boolean; } diff --git a/packages/react-native-quick-crypto/src/specs/random.nitro.ts b/packages/react-native-quick-crypto/src/specs/random.nitro.ts index de8d1bb1f..7c10ee6da 100644 --- a/packages/react-native-quick-crypto/src/specs/random.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/random.nitro.ts @@ -1,12 +1,21 @@ -import { type HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/Random'; -export interface Random extends HybridObject<{ ios: 'c++'; android: 'c++' }> { - randomFill( +@Apple({ + language: 'c++', + implementation: { className: 'HybridRandom', include: '"HybridRandom.hpp"' }, +}) +@Android({ + language: 'c++', + implementation: { className: 'HybridRandom', include: '"HybridRandom.hpp"' }, +}) +export declare class Random extends HybridObject { + static randomFill( buffer: ArrayBuffer, offset: number, size: number, ): Promise; - randomFillSync( + static randomFillSync( buffer: ArrayBuffer, offset: number, size: number, diff --git a/packages/react-native-quick-crypto/src/specs/rsaCipher.nitro.ts b/packages/react-native-quick-crypto/src/specs/rsaCipher.nitro.ts index 4521d41c5..7e197b052 100644 --- a/packages/react-native-quick-crypto/src/specs/rsaCipher.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/rsaCipher.nitro.ts @@ -1,8 +1,22 @@ -import type { HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/RsaCipher'; import type { KeyObjectHandle } from './keyObjectHandle.nitro'; -export interface RsaCipher - extends HybridObject<{ ios: 'c++'; android: 'c++' }> { +@Apple({ + language: 'c++', + implementation: { + className: 'HybridRsaCipher', + include: '"HybridRsaCipher.hpp"', + }, +}) +@Android({ + language: 'c++', + implementation: { + className: 'HybridRsaCipher', + include: '"HybridRsaCipher.hpp"', + }, +}) +export declare class RsaCipher extends HybridObject { /** * Encrypt data using RSA with specified padding * @param keyHandle The public key handle @@ -12,7 +26,7 @@ export interface RsaCipher * @param label Optional label for OAEP * @returns Encrypted data */ - encrypt( + static encrypt( keyHandle: KeyObjectHandle, data: ArrayBuffer, padding: number, @@ -29,7 +43,7 @@ export interface RsaCipher * @param label Optional label for OAEP * @returns Decrypted data */ - decrypt( + static decrypt( keyHandle: KeyObjectHandle, data: ArrayBuffer, padding: number, @@ -44,7 +58,7 @@ export interface RsaCipher * @param padding RSA padding mode (1=PKCS1) * @returns Decrypted data */ - publicDecrypt( + static publicDecrypt( keyHandle: KeyObjectHandle, data: ArrayBuffer, padding: number, @@ -57,7 +71,7 @@ export interface RsaCipher * @param padding RSA padding mode (1=PKCS1) * @returns Encrypted data */ - privateEncrypt( + static privateEncrypt( keyHandle: KeyObjectHandle, data: ArrayBuffer, padding: number, @@ -72,7 +86,7 @@ export interface RsaCipher * @param label Optional label for OAEP * @returns Decrypted data */ - privateDecrypt( + static privateDecrypt( keyHandle: KeyObjectHandle, data: ArrayBuffer, padding: number, diff --git a/packages/react-native-quick-crypto/src/specs/rsaKeyPair.nitro.ts b/packages/react-native-quick-crypto/src/specs/rsaKeyPair.nitro.ts index b607b90cc..2a94b457d 100644 --- a/packages/react-native-quick-crypto/src/specs/rsaKeyPair.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/rsaKeyPair.nitro.ts @@ -1,12 +1,27 @@ -import type { HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/RsaKeyPair'; // Nitro-compatible interfaces defined locally interface KeyObject { extractable: boolean; } -export interface RsaKeyPair - extends HybridObject<{ ios: 'c++'; android: 'c++' }> { +@Apple({ + language: 'c++', + implementation: { + className: 'HybridRsaKeyPair', + include: '"HybridRsaKeyPair.hpp"', + }, +}) +@Android({ + language: 'c++', + implementation: { + className: 'HybridRsaKeyPair', + include: '"HybridRsaKeyPair.hpp"', + }, +}) +export declare class RsaKeyPair extends HybridObject { + constructor(); // generateKeyPair functions generateKeyPair(): Promise; generateKeyPairSync(): void; diff --git a/packages/react-native-quick-crypto/src/specs/scrypt.nitro.ts b/packages/react-native-quick-crypto/src/specs/scrypt.nitro.ts index 6d0571982..d087b3075 100644 --- a/packages/react-native-quick-crypto/src/specs/scrypt.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/scrypt.nitro.ts @@ -1,7 +1,16 @@ -import type { HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/Scrypt'; -export interface Scrypt extends HybridObject<{ ios: 'c++'; android: 'c++' }> { - deriveKey( +@Apple({ + language: 'c++', + implementation: { className: 'HybridScrypt', include: '"HybridScrypt.hpp"' }, +}) +@Android({ + language: 'c++', + implementation: { className: 'HybridScrypt', include: '"HybridScrypt.hpp"' }, +}) +export declare class Scrypt extends HybridObject { + static deriveKey( password: ArrayBuffer, salt: ArrayBuffer, N: number, @@ -11,7 +20,7 @@ export interface Scrypt extends HybridObject<{ ios: 'c++'; android: 'c++' }> { keylen: number, ): Promise; - deriveKeySync( + static deriveKeySync( password: ArrayBuffer, salt: ArrayBuffer, N: number, diff --git a/packages/react-native-quick-crypto/src/specs/sign.nitro.ts b/packages/react-native-quick-crypto/src/specs/sign.nitro.ts index c1703f881..b315f3ae8 100644 --- a/packages/react-native-quick-crypto/src/specs/sign.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/sign.nitro.ts @@ -1,8 +1,24 @@ -import type { HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/SignHandle'; +export * from '#nitro/VerifyHandle'; import type { KeyObjectHandle } from './keyObjectHandle.nitro'; -export interface SignHandle - extends HybridObject<{ ios: 'c++'; android: 'c++' }> { +@Apple({ + language: 'c++', + implementation: { + className: 'HybridSignHandle', + include: '"HybridSignHandle.hpp"', + }, +}) +@Android({ + language: 'c++', + implementation: { + className: 'HybridSignHandle', + include: '"HybridSignHandle.hpp"', + }, +}) +export declare class SignHandle extends HybridObject { + constructor(); init(algorithm: string): void; update(data: ArrayBuffer): void; @@ -15,8 +31,22 @@ export interface SignHandle ): ArrayBuffer; } -export interface VerifyHandle - extends HybridObject<{ ios: 'c++'; android: 'c++' }> { +@Apple({ + language: 'c++', + implementation: { + className: 'HybridVerifyHandle', + include: '"HybridVerifyHandle.hpp"', + }, +}) +@Android({ + language: 'c++', + implementation: { + className: 'HybridVerifyHandle', + include: '"HybridVerifyHandle.hpp"', + }, +}) +export declare class VerifyHandle extends HybridObject { + constructor(); init(algorithm: string): void; update(data: ArrayBuffer): void; diff --git a/packages/react-native-quick-crypto/src/specs/slhDsaKeyPair.nitro.ts b/packages/react-native-quick-crypto/src/specs/slhDsaKeyPair.nitro.ts index d954be055..278246261 100644 --- a/packages/react-native-quick-crypto/src/specs/slhDsaKeyPair.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/slhDsaKeyPair.nitro.ts @@ -1,7 +1,22 @@ -import type { HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/SlhDsaKeyPair'; -export interface SlhDsaKeyPair - extends HybridObject<{ ios: 'c++'; android: 'c++' }> { +@Apple({ + language: 'c++', + implementation: { + className: 'HybridSlhDsaKeyPair', + include: '"HybridSlhDsaKeyPair.hpp"', + }, +}) +@Android({ + language: 'c++', + implementation: { + className: 'HybridSlhDsaKeyPair', + include: '"HybridSlhDsaKeyPair.hpp"', + }, +}) +export declare class SlhDsaKeyPair extends HybridObject { + constructor(); generateKeyPair( publicFormat: number, publicType: number, diff --git a/packages/react-native-quick-crypto/src/specs/turboshake.nitro.ts b/packages/react-native-quick-crypto/src/specs/turboshake.nitro.ts index b06021622..67f970636 100644 --- a/packages/react-native-quick-crypto/src/specs/turboshake.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/turboshake.nitro.ts @@ -1,18 +1,32 @@ -import type { HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/TurboShake'; export type TurboShakeVariant = 'TurboSHAKE128' | 'TurboSHAKE256'; export type KangarooTwelveVariant = 'KT128' | 'KT256'; -export interface TurboShake - extends HybridObject<{ ios: 'c++'; android: 'c++' }> { - turboShake( +@Apple({ + language: 'c++', + implementation: { + className: 'HybridTurboShake', + include: '"HybridTurboShake.hpp"', + }, +}) +@Android({ + language: 'c++', + implementation: { + className: 'HybridTurboShake', + include: '"HybridTurboShake.hpp"', + }, +}) +export declare class TurboShake extends HybridObject { + static turboShake( variant: TurboShakeVariant, domainSeparation: number, outputLength: number, data: ArrayBuffer, ): Promise; - kangarooTwelve( + static kangarooTwelve( variant: KangarooTwelveVariant, outputLength: number, data: ArrayBuffer, diff --git a/packages/react-native-quick-crypto/src/specs/utils.nitro.ts b/packages/react-native-quick-crypto/src/specs/utils.nitro.ts index 86a7e1da0..1a626e7c0 100644 --- a/packages/react-native-quick-crypto/src/specs/utils.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/utils.nitro.ts @@ -1,5 +1,15 @@ -import { type HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/Utils'; -export interface Utils extends HybridObject<{ ios: 'c++'; android: 'c++' }> { - timingSafeEqual(a: ArrayBuffer, b: ArrayBuffer): boolean; +@Apple({ + language: 'c++', + implementation: { className: 'HybridUtils', include: '"HybridUtils.hpp"' }, +}) +@Android({ + language: 'c++', + implementation: { className: 'HybridUtils', include: '"HybridUtils.hpp"' }, +}) +export declare class Utils extends HybridObject { + constructor(); + static timingSafeEqual(a: ArrayBuffer, b: ArrayBuffer): boolean; } diff --git a/packages/react-native-quick-crypto/src/specs/x509certificate.nitro.ts b/packages/react-native-quick-crypto/src/specs/x509certificate.nitro.ts index 9a5498941..6e160983d 100644 --- a/packages/react-native-quick-crypto/src/specs/x509certificate.nitro.ts +++ b/packages/react-native-quick-crypto/src/specs/x509certificate.nitro.ts @@ -1,8 +1,23 @@ -import type { HybridObject } from 'react-native-nitro-modules'; +import { Android, Apple, type HybridObject } from 'nitro-core'; +export * from '#nitro/X509CertificateHandle'; import type { KeyObjectHandle } from './keyObjectHandle.nitro'; -export interface X509CertificateHandle - extends HybridObject<{ ios: 'c++'; android: 'c++' }> { +@Apple({ + language: 'c++', + implementation: { + className: 'HybridX509Certificate', + include: '"HybridX509Certificate.hpp"', + }, +}) +@Android({ + language: 'c++', + implementation: { + className: 'HybridX509Certificate', + include: '"HybridX509Certificate.hpp"', + }, +}) +export declare class X509CertificateHandle extends HybridObject { + constructor(); init(buffer: ArrayBuffer): void; subject(): string; diff --git a/packages/react-native-quick-crypto/src/subtle.ts b/packages/react-native-quick-crypto/src/subtle.ts index 8302e5aac..89c639dac 100644 --- a/packages/react-native-quick-crypto/src/subtle.ts +++ b/packages/react-native-quick-crypto/src/subtle.ts @@ -40,10 +40,9 @@ import { } from './utils/validation'; import { asyncDigest } from './hash'; import { createSecretKey, createPublicKey } from './keys'; -import { NitroModules } from 'react-native-nitro-modules'; -import type { KeyObjectHandle } from './specs/keyObjectHandle.nitro'; -import type { RsaCipher } from './specs/rsaCipher.nitro'; -import type { CipherFactory } from './specs/cipher.nitro'; +import { KeyObjectHandle } from './specs/keyObjectHandle.nitro'; +import { RsaCipher } from './specs/rsaCipher.nitro'; +import { CipherFactory } from './specs/cipher.nitro'; import { pbkdf2DeriveBits } from './pbkdf2'; import { ecImportKey, @@ -54,7 +53,7 @@ import { import { rsa_generateKeyPair } from './rsa'; import { getRandomValues } from './random'; import { createHmac } from './hmac'; -import type { Kmac } from './specs/kmac.nitro'; +import { Kmac } from './specs/kmac.nitro'; import { timingSafeEqual } from './utils/timingSafeEqual'; import { createSign, createVerify } from './keys/signVerify'; import { @@ -901,8 +900,7 @@ function ecExportKey(key: CryptoKey, format: KWebCryptoKeyFormat): ArrayBuffer { raw[0] = 0x04; raw.set(x, 1); raw.set(y, 1 + x.length); - const tmp = - NitroModules.createHybridObject('KeyObjectHandle'); + const tmp = new KeyObjectHandle(); const curveAlias = kNamedCurveAliases[namedCurve as keyof typeof kNamedCurveAliases]; if (!tmp.initECRaw(curveAlias, raw.buffer as ArrayBuffer)) { @@ -969,16 +967,12 @@ async function rsaCipher( ? bufferLikeToArrayBuffer(rsaParams.label) : undefined; - // Create RSA cipher instance - const rsaCipherModule = - NitroModules.createHybridObject('RsaCipher'); - // RSA-OAEP padding constant = 4 const RSA_PKCS1_OAEP_PADDING = 4; if (mode === CipherOrWrapMode.kWebCryptoCipherEncrypt) { // Encrypt with public key - return rsaCipherModule.encrypt( + return RsaCipher.encrypt( key.keyObject.handle, data, RSA_PKCS1_OAEP_PADDING, @@ -987,7 +981,7 @@ async function rsaCipher( ); } else { // Decrypt with private key - return rsaCipherModule.decrypt( + return RsaCipher.decrypt( key.keyObject.handle, data, RSA_PKCS1_OAEP_PADDING, @@ -1048,9 +1042,7 @@ async function aesCtrCipher( const cipherType = `aes-${keyLength}-ctr`; // Create cipher - const factory = - NitroModules.createHybridObject('CipherFactory'); - const cipher = factory.createCipher({ + const cipher = CipherFactory.createCipher({ isCipher: mode === CipherOrWrapMode.kWebCryptoCipherEncrypt, cipherType, cipherKey: bufferLikeToArrayBuffer(key.keyObject.export()), @@ -1089,9 +1081,7 @@ async function aesCbcCipher( const cipherType = `aes-${keyLength}-cbc`; // Create cipher - const factory = - NitroModules.createHybridObject('CipherFactory'); - const cipher = factory.createCipher({ + const cipher = CipherFactory.createCipher({ isCipher: mode === CipherOrWrapMode.kWebCryptoCipherEncrypt, cipherType, cipherKey: bufferLikeToArrayBuffer(key.keyObject.export()), @@ -1136,9 +1126,7 @@ async function aesAeadCipher( const keyLength = (key.algorithm as { length: number }).length; const cipherType = `aes-${keyLength}-${config.cipherSuffix}`; - const factory = - NitroModules.createHybridObject('CipherFactory'); - const cipher = factory.createCipher({ + const cipher = CipherFactory.createCipher({ isCipher: mode === CipherOrWrapMode.kWebCryptoCipherEncrypt, cipherType, cipherKey: bufferLikeToArrayBuffer(key.keyObject.export()), @@ -1277,10 +1265,7 @@ async function aesKwCipher( 0xa6, 0xa6, 0xa6, 0xa6, 0xa6, 0xa6, 0xa6, 0xa6, ]); - const factory = - NitroModules.createHybridObject('CipherFactory'); - - const cipher = factory.createCipher({ + const cipher = CipherFactory.createCipher({ isCipher: isWrap, cipherType, cipherKey, @@ -1327,9 +1312,7 @@ async function chaCha20Poly1305Cipher( const tagByteLength = 16; // 128 bits = 16 bytes // Create cipher using existing ChaCha20-Poly1305 implementation - const factory = - NitroModules.createHybridObject('CipherFactory'); - const cipher = factory.createCipher({ + const cipher = CipherFactory.createCipher({ isCipher: mode === CipherOrWrapMode.kWebCryptoCipherEncrypt, cipherType: 'chacha20-poly1305', cipherKey: bufferLikeToArrayBuffer(key.keyObject.export()), @@ -1567,7 +1550,7 @@ function kmacSignVerify( const keyData = key.keyObject.export(); - const kmac = NitroModules.createHybridObject('Kmac'); + const kmac = new Kmac(); let customizationBuffer: ArrayBuffer | undefined; if (algorithm.customization !== undefined) { @@ -1632,8 +1615,7 @@ async function kmacImportKey( ); } - const handle = - NitroModules.createHybridObject('KeyObjectHandle'); + const handle = new KeyObjectHandle(); let keyType: KeyType | undefined; try { keyType = handle.initJwk(jwk, undefined); @@ -1750,8 +1732,7 @@ function rsaImportKey( } } - const handle = - NitroModules.createHybridObject('KeyObjectHandle'); + const handle = new KeyObjectHandle(); let keyType: KeyType | undefined; try { keyType = handle.initJwk(jwk, undefined); @@ -1870,8 +1851,7 @@ async function hmacImportKey( } } - const handle = - NitroModules.createHybridObject('KeyObjectHandle'); + const handle = new KeyObjectHandle(); let keyType: KeyType | undefined; try { keyType = handle.initJwk(jwk, undefined); @@ -1948,8 +1928,7 @@ async function aesImportKey( validateJwkStructure(jwk, extractable, keyUsages, 'enc'); checkUsages(); - const handle = - NitroModules.createHybridObject('KeyObjectHandle'); + const handle = new KeyObjectHandle(); let keyType: KeyType | undefined; try { keyType = handle.initJwk(jwk, undefined); @@ -2051,8 +2030,7 @@ function edImportKey( } else if (format === 'raw') { checkUsages(); const keyData = bufferLikeToArrayBuffer(data as BufferLike); - const handle = - NitroModules.createHybridObject('KeyObjectHandle'); + const handle = new KeyObjectHandle(); handle.init(1, keyData); keyObject = new PublicKeyObject(handle); } else if (format === 'jwk') { @@ -2083,8 +2061,7 @@ function edImportKey( } checkUsages(); - const handle = - NitroModules.createHybridObject('KeyObjectHandle'); + const handle = new KeyObjectHandle(); let keyType: KeyType | undefined; try { keyType = handle.initJwk(jwkData); @@ -2188,8 +2165,7 @@ function pqcImportKeyObject( } else if (format === 'raw-public') { // ML-DSA / ML-KEM reject plain 'raw' — only 'raw-public' is accepted for // public-key import (Node webcrypto.js:493-499, 506-511). - const handle = - NitroModules.createHybridObject('KeyObjectHandle'); + const handle = new KeyObjectHandle(); if ( !handle.initPqcRaw( name, @@ -2204,8 +2180,7 @@ function pqcImportKeyObject( } return { keyObject: new PublicKeyObject(handle), isPublic: true }; } else if (format === 'raw-seed') { - const handle = - NitroModules.createHybridObject('KeyObjectHandle'); + const handle = new KeyObjectHandle(); if ( !handle.initPqcRaw( name, @@ -2219,8 +2194,7 @@ function pqcImportKeyObject( } else if (format === 'jwk') { const jwkData = data as JWK; const isPublic = jwkData.priv === undefined; - const handle = - NitroModules.createHybridObject('KeyObjectHandle'); + const handle = new KeyObjectHandle(); let keyType: KeyType | undefined; try { keyType = handle.initJwk(jwkData); diff --git a/packages/react-native-quick-crypto/src/utils/conversion.ts b/packages/react-native-quick-crypto/src/utils/conversion.ts index c8a7fde21..119df2981 100644 --- a/packages/react-native-quick-crypto/src/utils/conversion.ts +++ b/packages/react-native-quick-crypto/src/utils/conversion.ts @@ -1,11 +1,10 @@ import { Buffer as CraftzdogBuffer } from '@craftzdog/react-native-buffer'; import { Buffer as SafeBuffer } from 'safe-buffer'; -import { NitroModules } from 'react-native-nitro-modules'; -import type { Utils } from '../specs/utils.nitro'; +import { Utils } from '../specs/utils.nitro'; import type { ABV, BinaryLikeNode, BufferLike } from './types'; import { Platform } from 'react-native'; -type UtilsWithStringConverter = Utils & { +interface UtilsWithStringConverter extends Utils { bufferToString( buffer: ArrayBuffer, encoding: string, @@ -13,10 +12,26 @@ type UtilsWithStringConverter = Utils & { end?: number, ): string; stringToBuffer(str: string, encoding: string): ArrayBuffer; -}; +} + +function hasStringConverter(u: Utils): u is UtilsWithStringConverter { + return ( + 'bufferToString' in u && + typeof u.bufferToString === 'function' && + 'stringToBuffer' in u && + typeof u.stringToBuffer === 'function' + ); +} + +function createUtils(): UtilsWithStringConverter { + const u = new Utils(); + if (!hasStringConverter(u)) { + throw new Error('Utils string converters are unavailable'); + } + return u; +} -const utils = - NitroModules.createHybridObject('Utils'); +const utils = createUtils(); const isHermes = (global as { HermesInternal?: unknown }).HermesInternal != null; diff --git a/packages/react-native-quick-crypto/src/utils/timingSafeEqual.ts b/packages/react-native-quick-crypto/src/utils/timingSafeEqual.ts index c63aa9325..10f55aebe 100644 --- a/packages/react-native-quick-crypto/src/utils/timingSafeEqual.ts +++ b/packages/react-native-quick-crypto/src/utils/timingSafeEqual.ts @@ -1,16 +1,7 @@ -import { NitroModules } from 'react-native-nitro-modules'; -import type { Utils } from '../specs/utils.nitro'; +import { Utils } from '../specs/utils.nitro'; import type { ABV } from './types'; import { binaryLikeToArrayBuffer } from './conversion'; -let utils: Utils; -function getNative(): Utils { - if (utils == null) { - utils = NitroModules.createHybridObject('Utils'); - } - return utils; -} - export function timingSafeEqual(a: ABV, b: ABV): boolean { // Use binaryLikeToArrayBuffer (not abvToArrayBuffer) so that TypedArray / // Buffer views are sliced to their `byteOffset`/`byteLength` window. The @@ -24,5 +15,5 @@ export function timingSafeEqual(a: ABV, b: ABV): boolean { throw new RangeError('Input buffers must have the same byte length'); } - return getNative().timingSafeEqual(bufA, bufB); + return Utils.timingSafeEqual(bufA, bufB); } diff --git a/packages/react-native-quick-crypto/src/utils/types.ts b/packages/react-native-quick-crypto/src/utils/types.ts index 46ce07081..50de22567 100644 --- a/packages/react-native-quick-crypto/src/utils/types.ts +++ b/packages/react-native-quick-crypto/src/utils/types.ts @@ -563,6 +563,15 @@ export interface SlhDsaPrivateKeyFactoryHandle extends KeyObjectHandleType { ): Promise; } +export function isSlhDsaPrivateKeyFactoryHandle( + handle: KeyObjectHandleType, +): handle is SlhDsaPrivateKeyFactoryHandle { + return ( + 'importSlhDsaRawPrivateKey' in handle && + typeof handle.importSlhDsaRawPrivateKey === 'function' + ); +} + export type RawDiffieHellmanKeyInput = { key: ArrayBuffer | ArrayBufferView | string; format: 'raw-public' | 'raw-private' | 'raw-seed'; diff --git a/packages/react-native-quick-crypto/src/x509certificate.ts b/packages/react-native-quick-crypto/src/x509certificate.ts index b654fad53..165c79d25 100644 --- a/packages/react-native-quick-crypto/src/x509certificate.ts +++ b/packages/react-native-quick-crypto/src/x509certificate.ts @@ -1,6 +1,5 @@ -import { NitroModules } from 'react-native-nitro-modules'; import { Buffer } from '@craftzdog/react-native-buffer'; -import type { X509CertificateHandle } from './specs/x509certificate.nitro'; +import { X509CertificateHandle } from './specs/x509certificate.nitro'; import { PublicKeyObject, KeyObject } from './keys'; import type { BinaryLike } from './utils'; import { binaryLikeToArrayBuffer } from './utils'; @@ -74,9 +73,7 @@ export class X509Certificate { private readonly cache = new Map(); constructor(buffer: BinaryLike) { - this.handle = NitroModules.createHybridObject( - 'X509CertificateHandle', - ); + this.handle = new X509CertificateHandle(); // For string input, route through binaryLikeToArrayBuffer so the result // is a tight ArrayBuffer of just the encoded bytes. `Buffer.from(str).buffer` diff --git a/plans/done/1102-port-nitro-specs-v1.md b/plans/done/1102-port-nitro-specs-v1.md new file mode 100644 index 000000000..a7e5488e8 --- /dev/null +++ b/plans/done/1102-port-nitro-specs-v1.md @@ -0,0 +1,80 @@ +# Port the Nitro specs to Nitro Modules v1 + +Issue #1102. Port the 28 `.nitro.ts` specs (30 HybridObjects) to Nitro Modules v1 (`margelo/nitro@43e09c1`, npm `1.0.0-alpha.nightly.138.g43e09c161101`), regenerate with nitrogen v1, port the C++ hybrid objects, and replace the 66 `createHybridObject` call sites (65 in the package, 1 in the example). This is the first PR into the new `next` branch, created from `main` at 5f9560e2. + +Done when RNQC compiles against Nitro Modules v1 on Android (real example build) and iOS (every translation unit passes a syntax-only compile for the simulator target), and `scripts/check-ncrypto-openssl-deprecations.sh` passes. + +## Live tracker + +- [x] Phase 1: JS/toolchain flip. Bump Nitro packages, rewrite `nitro.json`, port specs, regenerate, replace call sites, fix bob, Metro and tsconfig for decorators and `#nitro/*`. +- [x] Phase 2: C++ foundation and stateless modules, plus the standalone compile script. +- [x] Phase 3: C++ stateful modules. The compile script passes for every TU on both targets. + - [x] 3a: cipher (base, CCM, ChaCha20, ChaCha20-Poly1305, GCM, OCB, XChaCha20-Poly1305, XSalsa20, XSalsa20-Poly1305, factory), Hash, Hmac, Kmac, Blake3, SignHandle, VerifyHandle, X509Certificate. + - [x] 3b: keypair modules (DhKeyPair, DiffieHellman, DsaKeyPair, EcKeyPair, ECDH, EdKeyPair, MlDsaKeyPair, MlKemKeyPair, RsaKeyPair, SlhDsaKeyPair). +- [x] Phase 4: Android compile proof (cpp-adapter, nitro-core cmake shim, Gradle build of the library) and the deprecation script. +- [x] Independent review and fixes. +- [x] Move plan, push `next` and the branch, open PR into `next`. + +## Phase 3 remaining TUs (after 3a) + +`scripts/check-nitro-v1-compile.sh` (both targets) fails on exactly these 3b TUs, each because its header still includes the unported `"HybridXSpec.hpp"`: + +- Hand-written (10): `dh/{HybridDhKeyPair,HybridDiffieHellman}`, `dsa/HybridDsaKeyPair`, `ec/HybridEcKeyPair`, `ecdh/HybridECDH`, `ed25519/HybridEdKeyPair`, `mldsa/HybridMlDsaKeyPair`, `mlkem/HybridMlKemKeyPair`, `rsa/HybridRsaKeyPair`, `slhdsa/HybridSlhDsaKeyPair`. +- Generated SpecClass TUs that go green once the matching impl header is ported (10 per target): DhKeyPair, DiffieHellman, DsaKeyPair, ECDH, EcKeyPair, EdKeyPair, MlDsaKeyPair, MlKemKeyPair, RsaKeyPair, SlhDsaKeyPair. + +Phase 3 callers of ported helpers: `KeyObjectData::CreateSecret`/`GetSymmetricKey` and `GetPublicOrPrivateKey`/`GetPrivateKey` now take/return value `ArrayBuffer`/`std::optional`; `ToNativeArrayBuffer(...)` returns `ArrayBuffer` (deep copy); `dataOrEmpty(const ArrayBuffer&)` is the null-safe pointer helper. + +## Decisions + +- Compile proof: real Android example build and an iOS syntax-only compile script. iOS link and run are deferred to #1103/#1104. (User, 2026-11-28.) +- Generate with `"environment": "bare"` now. Specs import from `nitro-core`. (User, 2026-11-28.) +- Decision 4 from #1100: statics for stateless members, constructors for stateful classes. + +## Assumptions + +- Static modules: Argon2, Certificate, Hkdf, Pbkdf2, Prime, Random, Scrypt, TurboShake, RsaCipher, CipherFactory (`createCipher`). Mixed classes get statics for their member-free methods: Hash (`getSupportedHashAlgorithms`, `getOpenSSLVersion`), Cipher (`getSupportedCiphers`, `getCipherInfo`), Blake3 (`getVersion`), EcKeyPair (`getSupportedCurves`), ECDH (`convertKey`), Utils (`timingSafeEqual`). Everything else gets a zero-argument constructor and keeps its existing `init`-style methods. +- Raw JSI methods use an extended nested `Class` that overrides `getHybridClass()`, so they stay instance methods (Utils, KeyObjectHandle). +- `ToNativeArrayBuffer`-style helpers deep-copy (`ArrayBuffer::copy`), never `asOwning()`, so that JS cannot mutate bytes that native code is reading. +- No JS runtime install of `react-native-nitro-modules` in #1102. The RN entry point is #1101's job. +- Keep bob's three targets with `configFile: true` and a package `babel.config.js` that enables the decorators parser. The entry-point redesign is #1101's job. +- Package peers: `react-native-nitro-modules` and `nitro-core` are pinned to exactly `1.0.0-alpha.nightly.138.g43e09c161101` (review fix; decision 7 from #1100 pins RNQC 2.0 to an exact Nitro Modules v1 nightly, and generated bindings are tied to that nightly's headers) and both optional (`peerDependenciesMeta`, per #1100). Both are also pinned exactly as package devDependencies; the example pins `nitro-core` and `react-native-nitro-modules` exactly. +- Static-only specs declare no constructor. `Cipher` also has no constructor (instances only come from `CipherFactory.createCipher`) and keeps instance methods plus two statics. +- Raw JSI methods (`Utils.stringToBuffer`/`bufferToString`, `KeyObjectHandle.importSlhDsaRawPrivateKey`) are not in the specs, so JS reaches them through `in`/`typeof` type guards (`hasStringConverter`, `isSlhDsaPrivateKeyFactoryHandle`) instead of casts. The example deep-imports the spec class (`react-native-quick-crypto/src/specs/keyObjectHandle.nitro`) to construct the handle; #1101 should replace that with the real entry point. +- The package `babel.config.js` now uses the bob preset (bob targets `commonjs` and `module` run with `configFile: true`); Jest does not read it. +- Phase 2 compile script: `scripts/check-nitro-v1-compile.sh [--target ios|android|all] [--list] [files...]`. It needs the iOS OpenSSL headers (`ios/openssl`, fetched by the podspec at `pod install`) and, for Android, the `openssl-static` prefab headers from the Gradle cache (`OPENSSL_ANDROID_INCLUDE` overrides, else falls back to the iOS headers). `cpp-adapter.cpp` is excluded until Phase 4 and the Swift or `.mm` generated files are not compiled. libsodium is off unless `SODIUM_ENABLED=1`. +- `ArrayBuffer::data()` is `nullptr` for empty buffers, so Phase 2 passes OpenSSL, ncrypto and fastpbkdf2 a non-null `dataOrEmpty(...)` pointer where the old copy was always non-null. Empty results use `ArrayBuffer::empty()` (RsaCipher, Certificate); every other `wrap` keeps its original deleter (none of the Phase 2 wrap sites cleansed; no cleanse deleter was removed). +- v1 structs lost their default constructors, so `KeyDetail{}` became an all-`nullopt` `emptyKeyDetail()` helper in `HybridKeyObjectHandle.cpp`. +- `KeyObjectData::Data::symmetric_key` is a `const std::optional` (no default `ArrayBuffer`); `KeyObjectHandle.init` and `initJwk` still deep-copy into it before `CreateSecret`. +- The nested `Class` for `KeyObjectHandle` and `Utils` keeps the spec `name`, extends `Spec::Class`, and overrides `getHybridClass()`; the registered class stays `Spec::Class` whose generated constructor builds the extended instance. +- Phase 3a: `HybridCipher` is not `final`; subclasses override `init(const ArrayBuffer&, const ArrayBuffer&)` and `HybridCipherFactory::createCipher` stays `static inline` returning `shared_ptr` (subclasses reached via `static_pointer_cast`). `getSupportedCiphers`/`getCipherInfo` are plain statics; the public default constructor stays because the factory instantiates the base. Spec parameters `std::optional` became `const std::optional&`. +- Phase 3a: zero-length results (`CCM` decrypt final, `ChaCha20` final, libsodium update/final empties) use `ArrayBuffer::empty()` instead of a wrapped zero-length or null-pointer buffer. No `wrap` site in 3a used a cleansing deleter, so none was removed; the destructor wipes (`secureZero`, `sodium_memzero`) are untouched. `CRYPTO_memcmp` is not used by these ciphers (OpenSSL and libsodium verify tags internally), so no comparison changed. +- Phase 3a: `data()` of empty `ArrayBuffer`s feeding OpenSSL, libsodium memcpy and blake3 goes through `dataOrEmpty(...)`. Kmac and Hmac key handling is unchanged (empty KMAC key still rejected; empty HMAC key still replaced by the dummy byte). `HybridBlake3::update` lost its `if (!data)` null check because `ArrayBuffer` is a value type. +- Phase 3b: mechanical port only. `EdKeyPair` async methods (`generateKeyPair`, `sign`, `verify`) capture `shared_cast` self instead of bare `this`; the Dh, Dsa, Ec and Rsa `generateKeyPair` lambdas still capture bare `this` as before. `KeyObject` has no default constructor in v1, so the placeholder returns in `EcKeyPair::importKey` use `KeyObject keyObj(false)` (JS ignores the value). `getSupportedCurves` and `convertKey` are plain statics. Buffers feeding OpenSSL use `dataOrEmpty`; no cleansing deleter existed in these files, so none changed. +- Phase 4: `cpp-adapter.cpp` calls the generated `margelo::nitro::crypto::registerAllNatives()` (header `QuickCrypto/private/QuickCryptoOnLoad.hpp`). `android/cmake/nitro-core/nitro-core-config.cmake` (shipped via package `files`) maps `nitro-core::NitroModules` onto `react-native-nitro-modules::NitroModules` plus ReactAndroid jsi/reactnative and the Folly defines, wired by `set(nitro-core_DIR ...)` in `CMakeLists.txt`. OpenSSL prefab, libsodium, blake3 and `--exclude-libs,ALL` are unchanged. `QuickCryptoPackage.java` and `build.gradle` needed no change: the generated Kotlin `QuickCryptoOnLoad.initializeNative()` is not called, and the package still loads the library via `System.loadLibrary`. +- The PR targets `next`, so the `agentscm/local-validation` attestation does not apply (`docs/local-e2e.md`). + +## Evidence + +- Phase 1 (macOS, commit 435b2de1): `bun install`; `bun --filter="react-native-quick-crypto" specs` (nitrogen v1: Generated 30/30 HybridObjects); `bun tsc` (root, both workspaces) exit 0; `bun lint` exit 0; `bun format` exit 0; `bun --filter="react-native-quick-crypto" prepare` (tsc + bob build, commonjs/module/typescript) exit 0; `cd packages/react-native-quick-crypto && bun run test` 3 suites, 19 tests passed; `bun run circular` no cycles. Native does not compile at this commit (C++ unported). + +- Phase 2 (macOS, Xcode iphonesimulator SDK, NDK 29.0.14206865, commit f9d82ee8): `scripts/check-nitro-v1-compile.sh` with no files on `arm64-apple-ios16.0-simulator` and `aarch64-linux-android26`. Every Phase 2 TU passes on both (all `cpp/{argon2,certificate,hkdf,keys,pbkdf2,prime,random,scrypt,turboshake,utils}`, `cpp/cipher/HybridRsaCipher.cpp`, generated shared, Apple and Android Class TUs for the ported modules, `QuickCryptoAutolinking.cpp`, `QuickCryptoOnLoad.cpp`, ncrypto sources). 63 of 108 TUs pass per target; the 45 failures are the Phase 3 list above. Negative control: `scripts/check-nitro-v1-compile.sh cpp/hash/HybridHash.cpp` exits 1 (`'HybridHashSpec.hpp' file not found`). `clang-format -i` on modified C++ files. `OPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl@3.6 scripts/check-ncrypto-openssl-deprecations.sh` exit 0 (OpenSSL 3.6.2); without the override the script picks Homebrew `openssl@4` (4.1 deprecations in unmodified `ncrypto.cpp`) and fails, unrelated to this diff. No TypeScript changed. + +- Phase 3a (macOS, Xcode iphonesimulator SDK, NDK 29.0.14206865, working tree on top of df3344ab, committed as the Phase 3a commit): `scripts/check-nitro-v1-compile.sh` with no files on `arm64-apple-ios16.0-simulator` and `aarch64-linux-android26`: 88 of 108 TUs pass per target; the 20 failures per target are exactly the Phase 3b list above (10 hand-written, 10 generated SpecClass). All 3a TUs and their generated Spec/SpecClass TUs pass on both targets. `SODIUM_ENABLED=1 scripts/check-nitro-v1-compile.sh cpp/cipher/X*.cpp` (XChaCha20-Poly1305, XSalsa20, XSalsa20-Poly1305 with the libsodium branches compiled in) passes on both targets. `clang-format -i` on modified C++ files. No runtime run. + +- Phase 3b (macOS, Xcode iphonesimulator SDK, NDK 29.0.14206865, working tree on top of df289542, committed as the Phase 3b commit): `scripts/check-nitro-v1-compile.sh` with no files: all 108 TUs pass on `arm64-apple-ios16.0-simulator` and all 108 on `aarch64-linux-android26`. Same run with `SODIUM_ENABLED=1`: 108/108 on both. `clang-format -i` on modified C++. `OPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl@3.6 scripts/check-ncrypto-openssl-deprecations.sh` exit 0. Grep of `packages/react-native-quick-crypto/cpp` for `HybridObject(TAG)`, `HybridObject("`, `shared_ptr`, `NativeArrayBuffer>`, `loadHybridMethods`, `shared_ptr, +# or ~/Library/Android/sdk/ndk/ +# - OpenSSL headers. iOS: packages/react-native-quick-crypto/ios/openssl (downloaded by +# the podspec during `pod install`; the checksum-pinned URL is in QuickCrypto.podspec). +# Android: the openssl-static prefab headers from the Gradle cache (run the example's +# Android build once), override with OPENSSL_ANDROID_INCLUDE; falls back to the iOS headers. +# - Optional: SODIUM_ENABLED=1 adds the libsodium headers (ios/libsodium-stable) and +# BLSALLOC_SODIUM=1. JOBS= sets parallelism. + +set -uo pipefail + +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +pkg="$repo_root/packages/react-native-quick-crypto" +gen="$pkg/nitrogen/generated" + +targets=(ios android) +list_only=0 +files=() +while [[ $# -gt 0 ]]; do + case "$1" in + --target) + case "${2:-}" in + ios) targets=(ios) ;; + android) targets=(android) ;; + all) targets=(ios android) ;; + *) echo "--target expects ios|android|all" >&2; exit 2 ;; + esac + shift 2 + ;; + --list) list_only=1; shift ;; + -h|--help) sed -n '2,/^set /p' "$0" | sed '$d'; exit 0 ;; + *) files+=("$1"); shift ;; + esac +done + +die() { echo "error: $*" >&2; exit 2; } + +find_nitro_core() { + local d + for d in "$pkg/node_modules/nitro-core" "$repo_root/node_modules/nitro-core"; do + if [[ -d "$d/native/cpp/include" ]]; then echo "$d/native/cpp/include"; return; fi + done + die "nitro-core headers not found; run bun install" +} + +find_jsi() { + local d + for d in "$repo_root/node_modules/react-native/ReactCommon/jsi" "$pkg/node_modules/react-native/ReactCommon/jsi"; do + if [[ -d "$d/jsi" ]]; then echo "$d"; return; fi + done + die "JSI headers not found; run bun install" +} + +find_ndk_clang() { + local root="${ANDROID_NDK_HOME:-}" + if [[ -z "$root" || ! -d "$root" ]]; then + local sdk="${ANDROID_HOME:-${ANDROID_SDK_ROOT:-$HOME/Library/Android/sdk}}" + root="$(ls -d "$sdk"/ndk/*/ 2>/dev/null | sort -V | tail -1)" + root="${root%/}" + fi + [[ -n "$root" && -d "$root" ]] || die "Android NDK not found; set ANDROID_NDK_HOME" + local c + for c in "$root"/toolchains/llvm/prebuilt/*/bin/clang++; do + [[ -x "$c" ]] && { echo "$c"; return; } + done + die "clang++ not found in NDK $root" +} + +find_android_openssl() { + if [[ -n "${OPENSSL_ANDROID_INCLUDE:-}" ]]; then echo "$OPENSSL_ANDROID_INCLUDE"; return; fi + local h + h="$(ls -d "$HOME"/.gradle/caches/*/transforms/*/transformed/*openssl-static*/prefab/modules/crypto/include 2>/dev/null | tail -1)" + if [[ -n "$h" ]]; then echo "$h"; else echo "$pkg/ios/openssl/include"; fi +} + +default_files() { + find "$pkg/cpp" -name '*.cpp' | sort + find "$gen/shared/c++" -maxdepth 1 -name '*.cpp' | sort + find "$pkg/deps/ncrypto/src" -maxdepth 1 -name '*.cpp' | sort + if [[ "$1" == ios ]]; then + find "$gen/apple/c++" -maxdepth 1 -name '*.cpp' | sort + echo "$gen/apple/QuickCryptoAutolinking.cpp" + else + find "$gen/android/c++" -maxdepth 1 -name '*.cpp' | sort + echo "$gen/android/QuickCryptoOnLoad.cpp" + fi +} + +nitro_include="$(find_nitro_core)" +jsi_include="$(find_jsi)" + +common=(-std=c++20 -fsyntax-only -DNCRYPTO_EVP_ONLY=1 + -I "$nitro_include" -I "$jsi_include" + -I "$gen/shared/c++/include" -I "$gen/shared/c++" + -I "$pkg/deps/ncrypto/include" -I "$pkg/deps/simdutf/include" -I "$pkg/deps/simdutf/src" + -I "$pkg/deps/blake3/c" -I "$pkg/deps/fastpbkdf2") +for d in "$pkg"/cpp/*/; do common+=(-I "${d%/}"); done +if [[ "${SODIUM_ENABLED:-0}" == 1 ]]; then + sodium_inc="$pkg/ios/libsodium-stable/src/libsodium/include" + [[ -d "$sodium_inc" ]] || die "SODIUM_ENABLED=1 but $sodium_inc is missing" + common+=(-DBLSALLOC_SODIUM=1 -I "$sodium_inc" -I "$sodium_inc/sodium") +fi + +build_cmd() { + case "$1" in + ios) + local sdk + sdk="$(xcrun --sdk iphonesimulator --show-sdk-path)" || die "iphonesimulator SDK not found" + [[ -f "$pkg/ios/openssl/quickcrypto_openssl_prefix.h" ]] || die "iOS OpenSSL missing; run pod install (podspec downloads it)" + cmd=(xcrun --sdk iphonesimulator clang++ -target arm64-apple-ios16.0-simulator -isysroot "$sdk" + -I "$gen/apple/c++/include" -I "$pkg/ios/openssl/include" + -include "$pkg/ios/openssl/quickcrypto_openssl_prefix.h") + ;; + android) + local ossl + ossl="$(find_android_openssl)" + [[ -d "$ossl/openssl" ]] || die "Android OpenSSL headers not found at $ossl" + cmd=("$(find_ndk_clang)" --target=aarch64-linux-android26 + -I "$gen/android/include" -I "$gen/android/c++/include" -I "$ossl") + ;; + esac + cmd+=("${common[@]}") +} + +check_one() { + local f="$1" out + out="$("${cmd[@]}" "$f" 2>&1)" + if [[ $? -ne 0 ]]; then + printf 'FAIL %s\n%s\n' "$f" "$(echo "$out" | grep -E 'error' | head -"${MAXERR:-6}" | sed 's/^/ /')" + return 1 + fi + printf 'ok %s\n' "$f" +} + +rc=0 +for target in "${targets[@]}"; do + cmd=() + build_cmd "$target" + if [[ ${#files[@]} -gt 0 ]]; then + tus=() + for f in "${files[@]}"; do + if [[ "$f" != /* ]]; then + if [[ -f "$PWD/$f" ]]; then f="$PWD/$f"; else f="$repo_root/$f"; fi + fi + [[ -f "$f" ]] || die "no such file: $f" + tus+=("$f") + done + else + tus=() + while IFS= read -r f; do tus+=("$f"); done < <(default_files "$target") + fi + if [[ $list_only -eq 1 ]]; then + echo "== $target"; printf '%s\n' "${tus[@]}"; continue + fi + echo "== $target (${#tus[@]} TUs)" + jobs="${JOBS:-$(sysctl -n hw.ncpu 2>/dev/null || nproc)}" + results="$(mktemp)" + export -f check_one + printf '%s\0' "${tus[@]}" | CMDSTR="$(printf '%q ' "${cmd[@]}")" MAXERR="${MAXERR:-6}" xargs -0 -n 1 -P "$jobs" bash -c ' + eval "cmd=($CMDSTR)" + '"$(declare -f check_one)"' + check_one "$1"' _ >"$results" + sed "s#$repo_root/##" "$results" + fails="$(grep -c '^FAIL' "$results")" + oks="$(grep -c '^ok ' "$results")" + rm -f "$results" + if [[ "$fails" -ne 0 || "$oks" -ne "${#tus[@]}" ]]; then + echo "== $target: $fails TU(s) failed, $oks of ${#tus[@]} passed" + rc=1 + else + echo "== $target: all ${#tus[@]} TUs passed" + fi +done +exit $rc