From 461632a0cd5b753493007f920e2c0ced0d0ec630 Mon Sep 17 00:00:00 2001 From: hrithik098 Date: Wed, 7 Dec 2022 19:04:38 +0530 Subject: [PATCH 1/4] bug: added missing `#` in logging MACRO --- README.md | 4 ++-- include/AsymJwt.h | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c2c8806..5a1f13b 100644 --- a/README.md +++ b/README.md @@ -110,10 +110,10 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file ## Configuration -- Enable debug mode by defining `AsymJwt_Logging` before including the library. +- Enable debug mode by defining `ASYMJWT_DEBUG` before including the library. ```cpp - #define AsymJwt_Logging 1 + #define ASYMJWT_DEBUG 1 #include ``` diff --git a/include/AsymJwt.h b/include/AsymJwt.h index c0fe3f2..1a8284a 100644 --- a/include/AsymJwt.h +++ b/include/AsymJwt.h @@ -1,9 +1,10 @@ -ifdef AsymJwt_Logging +#ifdef ASYMJWT_DEBUG #define AsymJwt_Log(...) Serial.print(__VA_ARGS__) #define AsymJwt_Logln(...) Serial.println(__VA_ARGS__) -else +#else #define AsymJwt_Log(...) (void)0 #define AsymJwt_Logln(...) (void)0 +#endif #include From d9803e3f43efcdfd205a4bb579000d0b905bda3a Mon Sep 17 00:00:00 2001 From: hrithik098 Date: Wed, 7 Dec 2022 19:05:06 +0530 Subject: [PATCH 2/4] example: added a simple example for platformIO --- examples/simple/platformio.ini | 7 +++++++ examples/simple/src/main.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 examples/simple/platformio.ini create mode 100644 examples/simple/src/main.cpp diff --git a/examples/simple/platformio.ini b/examples/simple/platformio.ini new file mode 100644 index 0000000..9c78623 --- /dev/null +++ b/examples/simple/platformio.ini @@ -0,0 +1,7 @@ +[env:release] +platform = espressif8266 +board = esp12e +framework = arduino +lib_deps = + ; https://github.com/qube-ai/tiny-webthing.git + file://../../ \ No newline at end of file diff --git a/examples/simple/src/main.cpp b/examples/simple/src/main.cpp new file mode 100644 index 0000000..5fdb16e --- /dev/null +++ b/examples/simple/src/main.cpp @@ -0,0 +1,24 @@ +#include +#include + + +void setup() +{ + Serial.begin(9600); + Serial.println("Reading private ket...."); + while (!AsymJWT::readPrivKey("/private-key.der")) + { + Serial.println("Failed to read private key. Retrying in 2 seconds"); + delay(2000); + } +} + + +void loop() +{ + time_t iat = time(nullptr); + String payload = "{\"iat\":" + String(iat) + ",\"exp\":" + String(iat + 300) + ",\"thing_id\":\"" + "THING_ID" + "\"}"; + Serial.println(AsymJWT::generateJwt(payload)); + delay(200000); + Serial.println("Refreshing JWT."); +} \ No newline at end of file From ed1d866cff2801347dab1e3d47e2c2389898f57e Mon Sep 17 00:00:00 2001 From: hrithik098 Date: Wed, 7 Dec 2022 19:05:23 +0530 Subject: [PATCH 3/4] ci: added github action for merging and release --- .github/workflows/pr_test.yml | 42 ++++++++++++++++++++++++++ .github/workflows/release.yml | 55 +++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 .github/workflows/pr_test.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/pr_test.yml b/.github/workflows/pr_test.yml new file mode 100644 index 0000000..f458ca1 --- /dev/null +++ b/.github/workflows/pr_test.yml @@ -0,0 +1,42 @@ +name: PR Test (check if code compiles) + +on: + pull_request: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Cache pip + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Cache PlatformIO + uses: actions/cache@v2 + with: + path: ~/.platformio + key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} + + - name: Set up Python + uses: actions/setup-python@v2 + + - name: Install PlatformIO + run: | + python -m pip install --upgrade pip + pip install --upgrade platformio + + - name: Install dependencies + working-directory: ./examples/simple + run: pio pkg install + + - name: Build + working-directory: ./examples/simple + run: pio run diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ddfcfdb --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,55 @@ +name: Release Build + +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Cache pip + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Cache PlatformIO + uses: actions/cache@v2 + with: + path: ~/.platformio + key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} + + - name: Set up Python + uses: actions/setup-python@v2 + + - name: Install PlatformIO + run: | + python -m pip install --upgrade pip + pip install --upgrade platformio + + - name: Install dependencies + working-directory: ./examples/simple + run: pio pkg install + + - name: Build + working-directory: ./examples/simple + run: pio run + + - name: create env variable for lib version from library.json + id: lib_version + run: echo "::set-output name=version::$(cat library.json | grep "version" | cut -d '"' -f 4)" + + - name: Create Github Release + uses: ncipollo/release-action@v1 + with: + allowUpdates: true + tag: "v${{ steps.lib_version.outputs.version }}" + token: ${{ secrets.TOKEN_GITHUB }} + name: "v${{ steps.lib_version.outputs.version }}" + body: "This is a production build for the v${{ steps.lib_version.outputs.version }}. Changelog will be added in future versions." From 08551bd54c1927814718d6a842dfccc36ac11bef Mon Sep 17 00:00:00 2001 From: hrithik098 Date: Wed, 7 Dec 2022 19:21:53 +0530 Subject: [PATCH 4/4] refactor: moved `LittleFS` inside the `AsymJwt.h` --- README.md | 2 +- include/AsymJwt.h | 4 ++++ src/AsymJwt.cpp | 2 -- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5a1f13b..0e620c6 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ void loop() ## License -This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details +This project is licensed under the UnLicense - see the [LICENSE](LICENSE) file for details ## Configuration diff --git a/include/AsymJwt.h b/include/AsymJwt.h index 1a8284a..e90cb68 100644 --- a/include/AsymJwt.h +++ b/include/AsymJwt.h @@ -11,6 +11,10 @@ #ifndef AsymJwt_h #define AsymJwt_h + +#include "LittleFS.h" +#include "WiFiClientSecureBearSSL.h" + #include "crypto/make_jwt.h" #include "crypto/nn.h" #include "crypto/ecc.h" diff --git a/src/AsymJwt.cpp b/src/AsymJwt.cpp index a757072..b482720 100644 --- a/src/AsymJwt.cpp +++ b/src/AsymJwt.cpp @@ -1,7 +1,5 @@ #include "AsymJwt.h" -#include "LittleFS.h" -#include "WiFiClientSecureBearSSL.h" NN_DIGIT priv_key[9];