Skip to content

Commit

Permalink
Merge pull request #41 from GlitchedPolygons/feature/#15-l8w8jwt_deco…
Browse files Browse the repository at this point in the history
…de_raw

Feature/#15 l8w8jwt decode raw
  • Loading branch information
GlitchedPolygons authored Jan 31, 2024
2 parents e9029b7 + 460c25c commit b7318c8
Show file tree
Hide file tree
Showing 132 changed files with 4,729 additions and 2,756 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2.1
jobs:
build-x64:
machine:
image: ubuntu-2004:202101-01
image: ubuntu-2204:2024.01.1
resource_class: medium
steps:
- checkout
Expand Down
14 changes: 10 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ set(CMAKE_C_STANDARD 11)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake" ${CMAKE_MODULE_PATH})

set(L8W8JWT_MAJOR 2)
set(L8W8JWT_MINOR 2)
set(L8W8JWT_PATCH 1)
set(L8W8JWT_MINOR 3)
set(L8W8JWT_PATCH 0)
set(L8W8JWT_VERSION_STRING "${L8W8JWT_MAJOR}.${L8W8JWT_MINOR}.${L8W8JWT_PATCH}")

option(L8W8JWT_ENABLE_TESTS "Build l8w8jwt tests." OFF)
Expand All @@ -30,6 +30,10 @@ option(L8W8JWT_SMALL_STACK "Build the library for a device that has a particular
option(L8W8JWT_PLATFORM_TIME_ALT "Build the library with alternate `time` API implementation." OFF)
option(L8W8JWT_ENABLE_EDDSA "Build the library with EdDSA support (this will include a dependency for lib/ed25519)." OFF)

option(L8W8JWT_PLATFORM_MALLOC_ALT "Build the library with alternate `malloc` implementation." OFF)
option(L8W8JWT_PLATFORM_CALLOC_ALT "Build the library with alternate `calloc` implementation." OFF)
option(L8W8JWT_PLATFORM_REALLOC_ALT "Build the library with alternate `realloc` implementation." OFF)

option(L8W8JWT_DLL "Use l8w8jwt as a DLL." OFF)
option(L8W8JWT_BUILD_DLL "Build l8w8jwt as a DLL." OFF)

Expand Down Expand Up @@ -122,16 +126,18 @@ else ()
set(l8w8jwt_sources_eddsa "")
endif ()

add_library(${PROJECT_NAME} ${l8w8jwt_headers} ${l8w8jwt_sources} ${l8w8jwt_sources_eddsa})

if (L8W8JWT_BUILD_DLL OR BUILD_SHARED_LIBS)
add_library(${PROJECT_NAME} SHARED ${l8w8jwt_headers} ${l8w8jwt_sources} ${l8w8jwt_sources_eddsa})
set_property(TARGET mbedtls PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET mbedx509 PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET mbedcrypto PROPERTY POSITION_INDEPENDENT_CODE ON)
set_property(TARGET ${everest_target} PROPERTY POSITION_INDEPENDENT_CODE ON)
set_target_properties(${PROJECT_NAME} PROPERTIES
VERSION ${L8W8JWT_VERSION_STRING}
SOVERSION ${L8W8JWT_MAJOR}
)
else ()
add_library(${PROJECT_NAME} ${l8w8jwt_headers} ${l8w8jwt_sources} ${l8w8jwt_sources_eddsa})
endif ()

if (L8W8JWT_PACKAGE)
Expand Down
36 changes: 29 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,29 @@ Make sure to do a recursive clone, otherwise you need to `git submodule update -

### How to use

Just add l8w8jwt as a git submodule to your project (e.g. into some `lib/` or `deps/` folder inside your project's repo; `{repo_root}/lib/` is used here in the following example).
Just add l8w8jwt as a git submodule to your project (e.g. into some `lib/` or `deps/` folder
inside your project's repo; `{repo_root}/lib/` is used here in the following example).

```
git submodule add https://github.com/GlitchedPolygons/l8w8jwt.git lib/l8w8jwt
git submodule update --init --recursive
```

If you don't want to use git submodules, you can also start vendoring a specific version of l8w8jwt by copying its full repo content into the folder where you keep your project's external libraries/dependencies.
If you don't want to use git submodules, you can also start vendoring a specific version of l8w8jwt
by copying its full repo content into the folder where you keep your project's external libraries/dependencies.

### Building and linking

If you use CMake you can just `add_subdirectory(path_to_git_submodule)` and then `target_link_libraries(your_project PRIVATE l8w8jwt)` inside your **CMakeLists.txt** file.
If you use CMake you can just `add_subdirectory(path_to_git_submodule)`
and then `target_link_libraries(your_project PRIVATE l8w8jwt)` inside your **CMakeLists.txt** file.

If you use GCC, [check out this issue's log here](https://github.com/GlitchedPolygons/l8w8jwt/issues/2).

For devices with a particularly small stack, please define the `L8W8JWT_SMALL_STACK` pre-processor definition and set it to `1`.

For devices which do not support system time via standard C `time` API, please define the `MBEDTLS_PLATFORM_TIME_ALT` pre-processor definition and set it to `1`. Additionally, you would also need to provide the alternate time API via function pointer `l8w8jwt_time` defined in [timehelper.h](include/l8w8jwt/timehelper.h)
For devices which do not support system time via standard C `time` API, please define the `MBEDTLS_PLATFORM_TIME_ALT`
pre-processor definition and set it to `1`.
Additionally, you would also need to provide the alternate time API via function pointer `l8w8jwt_time` defined in [timehelper.h](include/l8w8jwt/timehelper.h)

#### Build shared library/DLL

Expand All @@ -52,14 +57,17 @@ If the build succeeds, you should have a new _.tar.gz_ file inside the `build/`

This command works on Windows too: just use the [Git Bash for Windows](https://git-scm.com/download/win) CLI!

**NOTE:** If you use the l8w8jwt shared library in your project on Windows, remember to `#define L8W8JWT_DLL 1` before including any of the l8w8jwt headers! Maybe even set it as a pre-processor definition. Otherwise the headers won't have the necessary `__declspec(dllimport)` declarations!
**NOTE:** If you use the l8w8jwt shared library in your project on Windows,
remember to `#define L8W8JWT_DLL 1` before including any of the l8w8jwt headers!
Maybe even set it as a pre-processor definition, otherwise the headers won't have the necessary `__declspec(dllimport)` declarations!

#### MinGW on Windows

```bash
bash build-mingw.sh
```
Run this using e.g. "Git Bash for Windows". Make sure that you have your MinGW installation directory inside your `PATH` - otherwise this script will fail when trying to call `mingw32-make.exe`.
Run this using e.g. "Git Bash for Windows".
Make sure that you have your MinGW installation directory inside your `PATH` - otherwise this script will fail when trying to call `mingw32-make.exe`.

Official release builds are made using `mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe`.

Expand All @@ -71,7 +79,21 @@ cmake -DBUILD_SHARED_LIBS=Off -DL8W8JWT_PACKAGE=On -DCMAKE_BUILD_TYPE=Release ..
cmake --build . --config Release
```

**NOTE:** When compiling l8w8jwt as a static lib, remember to link against the MbedTLS libs too! Those will be placed inside the `build/mbedtls/library/` directory after successful compilation.
**NOTE:** When compiling l8w8jwt as a static lib, remember to link against the MbedTLS libs too!
Those will be placed inside the `build/mbedtls/library/` directory after successful compilation.

### Custom allocators

If you want to provide some custom implementation of `malloc`, `calloc` or `realloc`,
please define the below pre-processor definitions and set their corresponding value to `1`.
Additionally, you would also need to provide the alternate implementation for the API
via function pointer defined in [utils.h](include/l8w8jwt/util.h)

| Method | Pre-processor | Function pointer |
|-----------|-----------------------------------|---------------------|
| malloc | L8W8JWT_PLATFORM_MALLOC_ALT | l8w8jwt_malloc |
| calloc | L8W8JWT_PLATFORM_CALLOC_ALT | l8w8jwt_calloc |
| realloc | L8W8JWT_PLATFORM_REALLOC_ALT | l8w8jwt_realloc |

## Examples

Expand Down
2 changes: 1 addition & 1 deletion build-mingw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ rm -rf "$REPO"/out
rm -rf "$REPO"/build-mingw
mkdir -p "$REPO"/build-mingw/include && cd "$REPO"/build-mingw || exit

cmake -G "MinGW Makefiles" -DL8W8JWT_SYSNAME="mingw-w64" -DBUILD_SHARED_LIBS=On -DUSE_SHARED_MBEDTLS_LIBRARY=Off "-D${PROJECT_NAME}_BUILD_DLL=On" "-D${PROJECT_NAME}_PACKAGE=On" -DCMAKE_BUILD_TYPE=Release ..
cmake -G "MinGW Makefiles" -DL8W8JWT_SYSNAME="mingw-w64" -DUSE_SHARED_MBEDTLS_LIBRARY=Off "-D${PROJECT_NAME}_BUILD_DLL=On" "-D${PROJECT_NAME}_PACKAGE=On" -DCMAKE_BUILD_TYPE=Release ..

mingw32-make.exe

Expand Down
2 changes: 1 addition & 1 deletion build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SET projname=L8W8JWT
if exist %out% ( rd /s /q %out% )
mkdir %out% && cd %out%

cmake -DBUILD_SHARED_LIBS=On -DUSE_SHARED_MBEDTLS_LIBRARY=Off "-D%projname%_BUILD_DLL=On" "-D%projname%_PACKAGE=On" -DCMAKE_BUILD_TYPE=Release ..
cmake -DUSE_SHARED_MBEDTLS_LIBRARY=Off "-D%projname%_BUILD_DLL=On" "-D%projname%_PACKAGE=On" -DCMAKE_BUILD_TYPE=Release ..

cmake --build . --config Release

Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ rm -rf "$REPO"/out
rm -rf "$REPO"/build
mkdir -p "$REPO"/build/include && cd "$REPO"/build || exit

cmake -DBUILD_SHARED_LIBS=On -DUSE_SHARED_MBEDTLS_LIBRARY=Off "-D${PROJECT_NAME}_BUILD_DLL=On" "-D${PROJECT_NAME}_PACKAGE=On" -DCMAKE_BUILD_TYPE=Release ..
cmake -DUSE_SHARED_MBEDTLS_LIBRARY=Off "-D${PROJECT_NAME}_BUILD_DLL=On" "-D${PROJECT_NAME}_PACKAGE=On" -DCMAKE_BUILD_TYPE=Release ..

cmake --build . --config Release

Expand Down
Loading

0 comments on commit b7318c8

Please sign in to comment.