Skip to content

Commit

Permalink
feat: run nitrogen
Browse files Browse the repository at this point in the history
  • Loading branch information
renanmav committed Jan 26, 2025
1 parent 0f0a5d0 commit 13e0054
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 2 deletions.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions packages/react-native-quick-crypto/nitro.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"androidCxxLibName": "QuickCrypto"
},
"autolinking": {
"Hash": { "cpp": "HybridHash" },
"Cipher": { "cpp": "HybridCipher" },
"EdKeyPair": { "cpp": "HybridEdKeyPair" },
"Pbkdf2": { "cpp": "HybridPbkdf2" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ target_sources(
# Shared Nitrogen C++ sources
../nitrogen/generated/shared/c++/HybridCipherSpec.cpp
../nitrogen/generated/shared/c++/HybridEdKeyPairSpec.cpp
../nitrogen/generated/shared/c++/HybridHashSpec.cpp
../nitrogen/generated/shared/c++/HybridKeyObjectHandleSpec.cpp
../nitrogen/generated/shared/c++/HybridPbkdf2Spec.cpp
../nitrogen/generated/shared/c++/HybridRandomSpec.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <fbjni/fbjni.h>
#include <NitroModules/HybridObjectRegistry.hpp>

#include "HybridHash.hpp"
#include "HybridCipher.hpp"
#include "HybridEdKeyPair.hpp"
#include "HybridPbkdf2.hpp"
Expand All @@ -32,6 +33,15 @@ int initialize(JavaVM* vm) {


// Register Nitro Hybrid Objects
HybridObjectRegistry::registerHybridObjectConstructor(
"Hash",
[]() -> std::shared_ptr<HybridObject> {
static_assert(std::is_default_constructible_v<HybridHash>,
"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<HybridHash>();
}
);
HybridObjectRegistry::registerHybridObjectConstructor(
"Cipher",
[]() -> std::shared_ptr<HybridObject> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#import <type_traits>

#include "HybridHash.hpp"
#include "HybridCipher.hpp"
#include "HybridEdKeyPair.hpp"
#include "HybridPbkdf2.hpp"
Expand All @@ -24,6 +25,15 @@ + (void) load {
using namespace margelo::nitro;
using namespace margelo::nitro::crypto;

HybridObjectRegistry::registerHybridObjectConstructor(
"Hash",
[]() -> std::shared_ptr<HybridObject> {
static_assert(std::is_default_constructible_v<HybridHash>,
"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<HybridHash>();
}
);
HybridObjectRegistry::registerHybridObjectConstructor(
"Cipher",
[]() -> std::shared_ptr<HybridObject> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
///
/// HybridHashSpec.cpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#include "HybridHashSpec.hpp"

namespace margelo::nitro::crypto {

void HybridHashSpec::loadHybridMethods() {
// load base methods/properties
HybridObject::loadHybridMethods();
// load custom methods/properties
registerHybrids(this, [](Prototype& prototype) {
prototype.registerHybridMethod("copy", &HybridHashSpec::copy);
});
}

} // namespace margelo::nitro::crypto
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
///
/// HybridHashSpec.hpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © 2025 Marc Rousavy @ Margelo
///

#pragma once

#if __has_include(<NitroModules/HybridObject.hpp>)
#include <NitroModules/HybridObject.hpp>
#else
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
#endif

// Forward declaration of `ArrayBuffer` to properly resolve imports.
namespace NitroModules { class ArrayBuffer; }

#include <NitroModules/ArrayBuffer.hpp>

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
virtual ~HybridHashSpec() { }

public:
// Properties


public:
// Methods
virtual std::shared_ptr<ArrayBuffer> copy() = 0;

protected:
// Hybrid Setup
void loadHybridMethods() override;

protected:
// Tag for logging
static constexpr auto TAG = "Hash";
};

} // namespace margelo::nitro::crypto
3 changes: 1 addition & 2 deletions packages/react-native-quick-crypto/src/specs/hash.nitro.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { HybridObject } from 'react-native-nitro-modules';
import type { TransformOptions } from 'readable-stream';

export interface Hash extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
copy(options: TransformOptions[]): ArrayBuffer;
copy(): ArrayBuffer;
}

0 comments on commit 13e0054

Please sign in to comment.