Skip to content

Commit 2f7c382

Browse files
committed
clang-format
1 parent a27166e commit 2f7c382

25 files changed

Lines changed: 824 additions & 839 deletions

cpp/FastCryptoHostObject.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
// Copyright 2022 Margelo
22
#include "FastCryptoHostObject.h"
3+
4+
#include <Hash/HashInstaller.h>
35
#include <ReactCommon/TurboModuleUtils.h>
46
#include <jsi/jsi.h>
5-
#include <vector>
7+
68
#include <memory>
7-
#include <Hash/HashInstaller.h>
9+
#include <vector>
10+
811
#include "HMAC/HmacInstaller.h"
9-
#include "fastpbkdf2/Pbkdf2HostObject.h"
1012
#include "Random/RandomHostObject.h"
13+
#include "fastpbkdf2/Pbkdf2HostObject.h"
1114

1215
namespace margelo {
1316

1417
namespace jsi = facebook::jsi;
1518

16-
FastCryptoHostObject::FastCryptoHostObject(std::shared_ptr<react::CallInvoker> jsCallInvoker,
17-
std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue) :
18-
SmartHostObject(jsCallInvoker, workerQueue) {
19-
19+
FastCryptoHostObject::FastCryptoHostObject(
20+
std::shared_ptr<react::CallInvoker> jsCallInvoker,
21+
std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue)
22+
: SmartHostObject(jsCallInvoker, workerQueue) {
2023
this->fields.push_back(getHmacFieldDefinition(jsCallInvoker, workerQueue));
2124
this->fields.push_back(getHashFieldDefinition(jsCallInvoker, workerQueue));
2225
this->fields.push_back(JSI_VALUE("pbkdf2", {
23-
auto hostObject = std::make_shared<Pbkdf2HostObject>(jsCallInvoker,
24-
workerQueue);
25-
return jsi::Object::createFromHostObject(runtime, hostObject);
26-
}));
26+
auto hostObject =
27+
std::make_shared<Pbkdf2HostObject>(jsCallInvoker, workerQueue);
28+
return jsi::Object::createFromHostObject(runtime, hostObject);
29+
}));
2730
this->fields.push_back(JSI_VALUE("random", {
28-
auto hostObject = std::make_shared<RandomHostObject>(jsCallInvoker,
29-
workerQueue);
30-
return jsi::Object::createFromHostObject(runtime, hostObject);
31+
auto hostObject =
32+
std::make_shared<RandomHostObject>(jsCallInvoker, workerQueue);
33+
return jsi::Object::createFromHostObject(runtime, hostObject);
3134
}));
3235
}
3336

cpp/FastCryptoHostObject.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,26 @@
22
#ifndef CPP_FASTCRYPTOHOSTOBJECT_H_
33
#define CPP_FASTCRYPTOHOSTOBJECT_H_
44

5-
#include <jsi/jsi.h>
65
#include <ReactCommon/CallInvoker.h>
6+
#include <jsi/jsi.h>
7+
78
#include <memory>
8-
#include "Utils/DispatchQueue.h"
9+
910
#include "JSI Utils/SmartHostObject.h"
11+
#include "Utils/DispatchQueue.h"
1012

1113
namespace margelo {
1214

1315
namespace jsi = facebook::jsi;
1416
namespace react = facebook::react;
1517

1618
class JSI_EXPORT FastCryptoHostObject : public SmartHostObject {
17-
public:
18-
explicit FastCryptoHostObject(std::shared_ptr<react::CallInvoker> jsCallInvoker,
19-
std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
19+
public:
20+
explicit FastCryptoHostObject(
21+
std::shared_ptr<react::CallInvoker> jsCallInvoker,
22+
std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
2023

21-
virtual ~FastCryptoHostObject() {
22-
}
24+
virtual ~FastCryptoHostObject() {}
2325
};
2426

2527
} // namespace margelo

cpp/HMAC/HmacHostObject.cpp

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
//Copyright 2022 Margelo
1+
// Copyright 2022 Margelo
22

33
#include "HmacHostObject.h"
44

55
#include <jsi/jsi.h>
6-
#include <string>
76
#include <openssl/hmac.h>
7+
8+
#include <string>
89
#include <vector>
10+
911
#include "../../../../Downloads/cpp/JSI Utils/TypedArray.h"
1012

1113
#define OUT
@@ -24,65 +26,57 @@ const EVP_MD* parseHashAlgorithm(const std::string& hashAlgorithm) {
2426
if (hashAlgorithm == "sha512") {
2527
return EVP_sha512();
2628
}
27-
const EVP_MD* res = EVP_get_digestbyname(hashAlgorithm.c_str());
28-
if (res != nullptr) {
29-
return res;
30-
}
31-
throw std::runtime_error("Invalid Hash Algorithm!");
29+
const EVP_MD* res = EVP_get_digestbyname(hashAlgorithm.c_str());
30+
if (res != nullptr) {
31+
return res;
32+
}
33+
throw std::runtime_error("Invalid Hash Algorithm!");
3234
}
3335

34-
HmacHostObject::HmacHostObject(const std::string& hashAlgorithm,
35-
jsi::Runtime & runtime,
36-
jsi::ArrayBuffer & key,
37-
std::shared_ptr<react::CallInvoker> jsCallInvoker,
38-
std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue) :
39-
SmartHostObject(jsCallInvoker, workerQueue) {
36+
HmacHostObject::HmacHostObject(
37+
const std::string& hashAlgorithm, jsi::Runtime& runtime,
38+
jsi::ArrayBuffer& key, std::shared_ptr<react::CallInvoker> jsCallInvoker,
39+
std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue)
40+
: SmartHostObject(jsCallInvoker, workerQueue) {
4041
this->context = HMAC_CTX_new();
4142
if (key.size(runtime) == 0) {
42-
HMAC_Init_ex(this->context,
43-
"",
44-
0,
45-
parseHashAlgorithm(hashAlgorithm),
46-
nullptr);
43+
HMAC_Init_ex(this->context, "", 0, parseHashAlgorithm(hashAlgorithm),
44+
nullptr);
4745
} else {
48-
HMAC_Init_ex(this->context,
49-
key.data(runtime),
50-
static_cast<int>(key.size(runtime)),
51-
parseHashAlgorithm(hashAlgorithm),
52-
nullptr);
46+
HMAC_Init_ex(this->context, key.data(runtime),
47+
static_cast<int>(key.size(runtime)),
48+
parseHashAlgorithm(hashAlgorithm), nullptr);
5349
}
5450

55-
5651
this->fields.push_back(HOST_LAMBDA("update", {
57-
if (!arguments[0].isObject() || !arguments[0].getObject(runtime).isArrayBuffer(runtime)) {
58-
throw jsi::JSError(runtime, "HmacHostObject::update: First argument ('message') has to be of type ArrayBuffer!");
59-
}
52+
if (!arguments[0].isObject() ||
53+
!arguments[0].getObject(runtime).isArrayBuffer(runtime)) {
54+
throw jsi::JSError(runtime,
55+
"HmacHostObject::update: First argument ('message') "
56+
"has to be of type ArrayBuffer!");
57+
}
6058

61-
auto message = arguments[0].getObject(runtime).getArrayBuffer(runtime);
59+
auto message = arguments[0].getObject(runtime).getArrayBuffer(runtime);
6260

63-
HMAC_Update(this->context,
64-
message.data(runtime),
65-
message.size(runtime));
61+
HMAC_Update(this->context, message.data(runtime), message.size(runtime));
6662

67-
return jsi::Value::undefined();
68-
}));
63+
return jsi::Value::undefined();
64+
}));
6965

7066
this->fields.push_back(HOST_LAMBDA("digest", {
71-
auto size = HMAC_size(this->context);
67+
auto size = HMAC_size(this->context);
7268

73-
unsigned char* OUT md = new unsigned char[size];
74-
unsigned int OUT length;
69+
unsigned char* OUT md = new unsigned char[size];
70+
unsigned int OUT length;
7571

76-
HMAC_Final(this->context,
77-
md,
78-
&length);
72+
HMAC_Final(this->context, md, &length);
7973

80-
TypedArray<TypedArrayKind::Uint8Array> typedArray(runtime, length);
81-
std::vector<unsigned char> vec(md, md + length);
82-
typedArray.update(runtime, vec);
74+
TypedArray<TypedArrayKind::Uint8Array> typedArray(runtime, length);
75+
std::vector<unsigned char> vec(md, md + length);
76+
typedArray.update(runtime, vec);
8377

84-
return typedArray;
85-
}));
78+
return typedArray;
79+
}));
8680
}
8781

8882
HmacHostObject::~HmacHostObject() {
@@ -91,4 +85,4 @@ HmacHostObject::~HmacHostObject() {
9185
}
9286
}
9387

94-
}
88+
} // namespace margelo

cpp/HMAC/HmacHostObject.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,27 @@
88
#define HmacHostObject_h
99

1010
#include <jsi/jsi.h>
11-
#include <string>
1211
#include <openssl/hmac.h>
12+
13+
#include <string>
14+
1315
#include "JSI Utils/SmartHostObject.h"
1416

1517
namespace margelo {
1618

1719
using namespace facebook;
1820

1921
class HmacHostObject : public SmartHostObject {
20-
21-
public:
22-
explicit HmacHostObject(const std::string& hashAlgorithm,
23-
jsi::Runtime & runtime,
24-
jsi::ArrayBuffer & key,
25-
std::shared_ptr<react::CallInvoker> jsCallInvoker,
26-
std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
27-
virtual ~HmacHostObject();
28-
29-
private:
30-
HMAC_CTX* context;
31-
22+
public:
23+
explicit HmacHostObject(
24+
const std::string& hashAlgorithm, jsi::Runtime& runtime,
25+
jsi::ArrayBuffer& key, std::shared_ptr<react::CallInvoker> jsCallInvoker,
26+
std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
27+
virtual ~HmacHostObject();
28+
29+
private:
30+
HMAC_CTX* context;
3231
};
33-
}
32+
} // namespace margelo
3433

3534
#endif /* HmacHostObject_h */

cpp/HMAC/HmacInstaller.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,32 @@
77

88
#include "HmacInstaller.h"
99

10-
#include "HmacHostObject.h"
1110
#include <openssl/hmac.h>
11+
12+
#include "HmacHostObject.h"
1213
#include "JSI Utils/JSIMacros.h"
1314

1415
using namespace facebook;
1516

1617
namespace margelo {
1718

18-
FieldDefinition getHmacFieldDefinition(std::shared_ptr<react::CallInvoker> jsCallInvoker,
19-
std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue) {
19+
FieldDefinition getHmacFieldDefinition(
20+
std::shared_ptr<react::CallInvoker> jsCallInvoker,
21+
std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue) {
2022
// createHmac(hashAlgorithm: 'sha1' | 'sha256' | 'sha512',
2123
// key: string)
2224
return HOST_LAMBDA("createHmac", {
23-
if (count != 2) {
24-
throw jsi::JSError(runtime, "createHmac(..) expects exactly 2 arguments!");
25-
}
26-
27-
auto hashAlgorithm = arguments[0].asString(runtime).utf8(runtime);
28-
auto key = arguments[1].getObject(runtime).getArrayBuffer(runtime);
29-
30-
auto hostObject = std::make_shared<HmacHostObject>(hashAlgorithm,
31-
runtime,
32-
key,
33-
jsCallInvoker,
34-
workerQueue);
35-
return jsi::Object::createFromHostObject(runtime, hostObject);
36-
});
37-
}
25+
if (count != 2) {
26+
throw jsi::JSError(runtime,
27+
"createHmac(..) expects exactly 2 arguments!");
28+
}
29+
30+
auto hashAlgorithm = arguments[0].asString(runtime).utf8(runtime);
31+
auto key = arguments[1].getObject(runtime).getArrayBuffer(runtime);
32+
33+
auto hostObject = std::make_shared<HmacHostObject>(
34+
hashAlgorithm, runtime, key, jsCallInvoker, workerQueue);
35+
return jsi::Object::createFromHostObject(runtime, hostObject);
36+
});
3837
}
38+
} // namespace margelo

cpp/HMAC/HmacInstaller.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <jsi/jsi.h>
2+
23
#include "JSI Utils/SmartHostObject.h"
34

45
namespace margelo {
@@ -7,6 +8,7 @@ namespace jsi = facebook::jsi;
78
/// It's signature is:
89
/// createHmac(hashAlgorithm: 'sha1' | 'sha256' | 'sha512',
910
/// key: string): HMAC
10-
FieldDefinition getHmacFieldDefinition(std::shared_ptr<react::CallInvoker> jsCallInvoker,
11-
std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
11+
FieldDefinition getHmacFieldDefinition(
12+
std::shared_ptr<react::CallInvoker> jsCallInvoker,
13+
std::shared_ptr<DispatchQueue::dispatch_queue> workerQueue);
1214
} // namespace margelo

0 commit comments

Comments
 (0)