Skip to content

Commit 5303d9e

Browse files
committed
chore: more cleanup
1 parent 4052275 commit 5303d9e

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

packages/react-native-quick-crypto/cpp/cipher/CCMCipher.cpp

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -124,26 +124,20 @@ std::shared_ptr<ArrayBuffer> CCMCipher::final() {
124124
unsigned long err = ERR_get_error();
125125
char err_buf[256];
126126
ERR_error_string_n(err, err_buf, sizeof(err_buf));
127-
if (!is_cipher) {
128-
throw std::runtime_error("Decryption finalization failed (possibly invalid tag): " + std::string(err_buf));
129-
} else {
130-
throw std::runtime_error("Encryption finalization failed: " + std::string(err_buf));
131-
}
127+
throw std::runtime_error("Encryption finalization failed: " + std::string(err_buf));
132128
}
133129

134-
if (is_cipher) {
135-
if (auth_tag_len == 0) {
136-
auth_tag_len = sizeof(auth_tag);
137-
}
130+
if (auth_tag_len == 0) {
131+
auth_tag_len = sizeof(auth_tag);
132+
}
138133

139-
if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_GET_TAG, auth_tag_len, auth_tag) != 1) {
140-
unsigned long err = ERR_get_error();
141-
char err_buf[256];
142-
ERR_error_string_n(err, err_buf, sizeof(err_buf));
143-
throw std::runtime_error("Failed to get auth tag after finalization: " + std::string(err_buf));
144-
}
145-
auth_tag_state = kAuthTagKnown;
134+
if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_CCM_GET_TAG, auth_tag_len, auth_tag) != 1) {
135+
unsigned long err = ERR_get_error();
136+
char err_buf[256];
137+
ERR_error_string_n(err, err_buf, sizeof(err_buf));
138+
throw std::runtime_error("Failed to get auth tag after finalization: " + std::string(err_buf));
146139
}
140+
auth_tag_state = kAuthTagKnown;
147141

148142
unsigned char* final_output = out_buf.release();
149143
return std::make_shared<NativeArrayBuffer>(final_output, out_len, [=]() { delete[] final_output; });

packages/react-native-quick-crypto/cpp/cipher/HybridCipher.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ std::shared_ptr<ArrayBuffer> HybridCipher::final() {
133133

134134
// Context should NOT be freed here. It might be needed for getAuthTag() for GCM/OCB.
135135
// The context will be freed by the destructor (~HybridCipher) when the object goes out of scope.
136-
// EVP_CIPHER_CTX_free(ctx);
137-
// ctx = nullptr; // Prevent further use
138136

139137
// Return the shared_ptr<NativeArrayBuffer> (implicit upcast to shared_ptr<ArrayBuffer>)
140138
return native_final_chunk;

0 commit comments

Comments
 (0)