Skip to content

Commit

Permalink
Do not use externs directly due to inline
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdy committed Oct 4, 2023
1 parent 0864e33 commit 852eabb
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"scripts": {
"preinstall": "scripts/download-libraries.sh",
"install": "node-gyp configure && node-gyp build && mkdir -p dist/ && cp build/Release/asherah.node dist/asherah.node && cp src/asherah.d.ts dist/asherah.d.ts",
"install": "scripts/build.sh",
"test:mocha": "mocha",
"test": "nyc npm run test:mocha",
"posttest": "npm run lint",
Expand Down
3 changes: 3 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

node-gyp configure && node-gyp build && mkdir -p dist/ && cp build/Release/asherah.node dist/asherah.node && cp src/asherah.d.ts dist/asherah.d.ts
5 changes: 2 additions & 3 deletions src/asherah.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ void setup(const Napi::CallbackInfo &info) {
Napi::String product_id = config_json.Get("ProductID").As<Napi::String>();
Napi::String service_name = config_json.Get("ServiceName").As<Napi::String>();

est_intermediate_key_overhead =
product_id.Utf8Value().length() + service_name.Utf8Value().length();
set_est_intermediate_key_overhead(product_id.Utf8Value().length() + service_name.Utf8Value().length());

Napi::Value verbose = config_json.Get("Verbose");
if (likely(verbose.IsBoolean())) {
Expand Down Expand Up @@ -745,7 +744,7 @@ void set_safety_padding_overhead(const Napi::CallbackInfo &info) {

Napi::Number safety_padding_number = info[0].ToNumber();

safety_padding_bytes = (size_t)safety_padding_number.Int32Value();
set_safety_padding_bytes((size_t)safety_padding_number.Int32Value());
}

Napi::Object Init(Napi::Env env, Napi::Object exports) {
Expand Down
8 changes: 8 additions & 0 deletions src/cobhan_napi_interop.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#include <stddef.h>
size_t est_intermediate_key_overhead = 0;
size_t safety_padding_bytes = 0;

void set_est_intermediate_key_overhead(size_t est_intermediate_key_overhead) {
::est_intermediate_key_overhead = est_intermediate_key_overhead;
}

void set_safety_padding_bytes(size_t safety_padding_bytes) {
::safety_padding_bytes = safety_padding_bytes;
}
7 changes: 5 additions & 2 deletions src/cobhan_napi_interop.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
#include "logging.h"
#include "hints.h"

extern "C" size_t est_intermediate_key_overhead;
extern "C" size_t safety_padding_bytes;
extern size_t est_intermediate_key_overhead;
extern size_t safety_padding_bytes;

const size_t est_encryption_overhead = 48;
const size_t est_envelope_overhead = 185;
const double base64_overhead = 1.34;

const size_t cobhan_header_size_bytes = 64 / 8;

void set_est_intermediate_key_overhead(size_t est_intermediate_key_overhead);
void set_safety_padding_bytes(size_t safety_padding_bytes);

std::string napi_status_to_string(napi_status status) {
switch (status) {
case napi_ok:
Expand Down

0 comments on commit 852eabb

Please sign in to comment.