Skip to content

Commit

Permalink
refactor: constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
renanmav committed Jan 31, 2025
1 parent 467bb83 commit 3f29ac2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
12 changes: 2 additions & 10 deletions packages/react-native-quick-crypto/cpp/hash/HybridHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ HybridHash::copy()
if (!ctx) {
throw std::runtime_error("Hash context not initialized");
}

// Create a new HybridHash instance
auto newHash = std::make_shared<HybridHash>();

// Create a new context
EVP_MD_CTX* newCtx = EVP_MD_CTX_new();
Expand All @@ -106,13 +103,8 @@ HybridHash::copy()
EVP_MD_CTX_free(newCtx);
throw std::runtime_error("Failed to copy hash context");
}

// Initialize the new instance with the copied context
newHash->ctx = newCtx;
newHash->md = md;
newHash->algorithm = algorithm;

return newHash;

return std::make_shared<HybridHash>(newCtx, md, algorithm);
}

} // namespace margelo::nitro::crypto
10 changes: 10 additions & 0 deletions packages/react-native-quick-crypto/cpp/hash/HybridHash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ class HybridHash : public HybridHashSpec
public:
HybridHash()
: HybridObject(TAG)
, ctx(nullptr)
, md(nullptr)
, algorithm("")
{
}
HybridHash(EVP_MD_CTX* ctx, const EVP_MD* md, const std::string& algorithm)
: HybridObject(TAG)
, ctx(ctx)
, md(md)
, algorithm(algorithm)
{
}
~HybridHash();
Expand Down

0 comments on commit 3f29ac2

Please sign in to comment.