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." diff --git a/README.md b/README.md index c2c8806..0e620c6 100644 --- a/README.md +++ b/README.md @@ -106,14 +106,14 @@ 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 -- 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/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 diff --git a/include/AsymJwt.h b/include/AsymJwt.h index c0fe3f2..e90cb68 100644 --- a/include/AsymJwt.h +++ b/include/AsymJwt.h @@ -1,15 +1,20 @@ -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 #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];