-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add ciphers #573
Draft
boorad
wants to merge
8
commits into
main
Choose a base branch
from
feat/add-ciphers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
feat: add ciphers #573
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d7de1f1
feat: add ciphers
boorad 8b422a1
TS/Nitro work
boorad 8e2aedd
Nitro spec format correction
boorad 0610e90
C++ compiling and couple tests passing
boorad 954f6e9
lint & format
boorad 264a5f7
bump checkbox component
boorad a9a5937
android build
boorad c69956f
ts
boorad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { | ||
Cipher, | ||
createCipheriv, | ||
randomFillSync, | ||
} from 'react-native-quick-crypto'; | ||
import { expect } from 'chai'; | ||
import { test } from '../util'; | ||
|
||
const SUITE = 'cipher'; | ||
const key = 'secret'; | ||
const iv = randomFillSync(new Uint8Array(16)); | ||
|
||
test(SUITE, 'cipher - valid algorithm', async () => { | ||
const cipher = createCipheriv('aes-128-cbc', key, iv, {}); | ||
expect(cipher).to.be.instanceOf(Cipher); | ||
}); | ||
|
||
test(SUITE, 'cipher - invalid algorithm', async () => { | ||
expect(() => { | ||
// @ts-expect-error - testing bad algorithm | ||
createCipheriv('aes-128-boorad', key, iv, {}); | ||
}).to.throw(/Invalid Cipher Algorithm: aes-128-boorad/); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
packages/react-native-quick-crypto/cpp/cipher/HybridCipher.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include <memory> | ||
|
||
#include "HybridCipher.hpp" | ||
|
||
namespace margelo::nitro::crypto { | ||
|
||
std::shared_ptr<ArrayBuffer> | ||
HybridCipher::update( | ||
const std::shared_ptr<ArrayBuffer>& data | ||
) { | ||
return nullptr; | ||
} | ||
|
||
std::shared_ptr<ArrayBuffer> | ||
HybridCipher::final() { | ||
return nullptr; | ||
} | ||
|
||
void | ||
HybridCipher::copy() {} | ||
|
||
bool | ||
HybridCipher::setAAD( | ||
const std::shared_ptr<ArrayBuffer>& data, | ||
std::optional<double> plaintextLength | ||
) { | ||
return false; | ||
} | ||
|
||
bool | ||
HybridCipher::setAutoPadding( | ||
bool autoPad | ||
) { | ||
return false; | ||
} | ||
|
||
bool | ||
HybridCipher::setAuthTag( | ||
const std::shared_ptr<ArrayBuffer>& tag | ||
) { | ||
return false; | ||
} | ||
|
||
std::shared_ptr<ArrayBuffer> | ||
HybridCipher::getAuthTag() { | ||
return nullptr; | ||
} | ||
|
||
void | ||
HybridCipher::setArgs( | ||
const CipherArgs& args | ||
) { | ||
this->args = args; | ||
init(); | ||
} | ||
|
||
void | ||
HybridCipher::init() { | ||
// check if args are set | ||
if (!args.has_value()) { | ||
throw std::runtime_error("CipherArgs not set"); | ||
} | ||
auto args = this->args.value(); | ||
|
||
// check if cipherType is valid | ||
const EVP_CIPHER *const cipher = EVP_get_cipherbyname(args.cipherType.c_str()); | ||
if (cipher == nullptr) { | ||
throw std::runtime_error("Invalid Cipher Algorithm: " + args.cipherType); | ||
} | ||
} | ||
|
||
} // namespace margelo::nitro::crypto |
63 changes: 63 additions & 0 deletions
63
packages/react-native-quick-crypto/cpp/cipher/HybridCipher.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include <memory> | ||
#include <openssl/evp.h> | ||
#include <optional> | ||
|
||
#include "HybridCipherSpec.hpp" | ||
#include "CipherArgs.hpp" | ||
|
||
namespace margelo::nitro::crypto { | ||
|
||
using namespace facebook; | ||
|
||
class HybridCipher : public HybridCipherSpec { | ||
public: | ||
HybridCipher() : HybridObject(TAG) {} | ||
|
||
public: | ||
// Methods | ||
std::shared_ptr<ArrayBuffer> | ||
update( | ||
const std::shared_ptr<ArrayBuffer>& data | ||
) override; | ||
|
||
std::shared_ptr<ArrayBuffer> | ||
final() override; | ||
|
||
void | ||
copy() override; | ||
|
||
void | ||
setArgs( | ||
const CipherArgs& args | ||
) override; | ||
|
||
bool | ||
setAAD( | ||
const std::shared_ptr<ArrayBuffer>& data, | ||
std::optional<double> plaintextLength | ||
) override; | ||
|
||
bool | ||
setAutoPadding( | ||
bool autoPad | ||
) override; | ||
|
||
bool | ||
setAuthTag( | ||
const std::shared_ptr<ArrayBuffer>& tag | ||
) override; | ||
|
||
std::shared_ptr<ArrayBuffer> | ||
getAuthTag() override; | ||
|
||
private: | ||
// Methods | ||
void init(); | ||
|
||
private: | ||
// Properties | ||
std::optional<CipherArgs> args = std::nullopt; | ||
}; | ||
|
||
|
||
} // namespace margelo::nitro::crypto |
4 changes: 2 additions & 2 deletions
4
packages/react-native-quick-crypto/cpp/ed25519/HybridEdKeyPair.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/react-native-quick-crypto/cpp/ed25519/HybridEdKeyPair.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use
--filter
flag anymore?should other commands also be updated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I do
bun start
from top level (not in example folder), the command with--filter
rolls through 10 lines and truncates. This way, I see all the history in the terminal. The others don't need to change.