diff --git a/.github/workflows/release.json b/.github/workflows/release.json index 71d8bce..5e523ec 100644 --- a/.github/workflows/release.json +++ b/.github/workflows/release.json @@ -11,10 +11,10 @@ "runs-on": "ubuntu-latest", "steps": [{ "name": "clone repository", - "uses": "actions/checkout@v3" + "uses": "actions/checkout@v4" }, { "name": "dispatch release", - "uses": "softprops/action-gh-release@v1", + "uses": "softprops/action-gh-release@v2", "with": { "generate_release_notes": true } diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 93d83d6..81a2500 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -8,8 +8,8 @@ jobs: runs-on: ubuntu-latest steps: - name: clone repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: dispatch release - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 with: generate_release_notes: true \ No newline at end of file diff --git a/.github/workflows/test.json b/.github/workflows/test.json index 455116e..b5a8c5c 100644 --- a/.github/workflows/test.json +++ b/.github/workflows/test.json @@ -31,47 +31,28 @@ "matrix": { "board": [{ "vendor": "arduino", - "arch": "samd", - "name": "arduino_zero_native" + "arch": "avr", + "name": "uno" }, { - "vendor": "adafruit", + "vendor": "arduino", "arch": "samd", - "name": "adafruit_trinket_m0" - }, { - "vendor": "STMicroelectronics", - "arch": "stm32", - "name": "GenH5" + "name": "arduino_zero_native" }, { - "vendor": "teensy", - "arch": "avr", - "name": "teensy41" + "vendor": "arduino", + "arch": "renesas_uno", + "name": "minima" }], "include": [{ "index": "https://downloads.arduino.cc/packages/package_index.json", "board": { "vendor": "arduino" } - }, { - "index": "https://adafruit.github.io/arduino-board-index/package_adafruit_index.json", - "board": { - "vendor": "adafruit" - } - }, { - "index": "https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json", - "board": { - "vendor": "STMicroelectronics" - } - }, { - "index": "https://www.pjrc.com/teensy/package_teensy_index.json", - "board": { - "vendor": "teensy" - } }] } }, "steps": [{ "name": "clone repository", - "uses": "actions/checkout@v3" + "uses": "actions/checkout@v4" }, { "name": "install arduino and run test", "uses": "arduino/compile-sketches@v1", diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c2e8ad4..52c8d59 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -22,34 +22,22 @@ jobs: fail-fast: true matrix: board: + - vendor: arduino + arch: avr + name: uno - vendor: arduino arch: samd name: arduino_zero_native - - vendor: adafruit - arch: samd - name: adafruit_trinket_m0 - - vendor: STMicroelectronics - arch: stm32 - name: GenH5 - - vendor: teensy - arch: avr - name: teensy41 + - vendor: arduino + arch: renesas_uno + name: minima include: - index: https://downloads.arduino.cc/packages/package_index.json board: vendor: arduino - - index: https://adafruit.github.io/arduino-board-index/package_adafruit_index.json - board: - vendor: adafruit - - index: https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json - board: - vendor: STMicroelectronics - - index: https://www.pjrc.com/teensy/package_teensy_index.json - board: - vendor: teensy steps: - name: clone repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: install arduino and run test uses: arduino/compile-sketches@v1 with: diff --git a/LICENSE.md b/LICENSE.md index 1991302..e9a6825 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Kazuki Ota +Copyright (c) 2024 Kazuki Ota Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/examples/decode/decode.ino b/examples/decode/decode.ino index 5513849..00a994a 100644 --- a/examples/decode/decode.ino +++ b/examples/decode/decode.ino @@ -1,6 +1,6 @@ #include "arduino_base64.hpp" -void setup(){ +void setup() { Serial.begin(115200); while(!Serial); @@ -11,4 +11,6 @@ void setup(){ Serial.println((const char*)output); } -void loop(){} \ No newline at end of file +void loop() { + // nop +} \ No newline at end of file diff --git a/examples/encode/encode.ino b/examples/encode/encode.ino index 2e6ec72..e5cb1cc 100644 --- a/examples/encode/encode.ino +++ b/examples/encode/encode.ino @@ -1,6 +1,6 @@ #include "arduino_base64.hpp" -void setup(){ +void setup() { Serial.begin(115200); while(!Serial); @@ -12,4 +12,6 @@ void setup(){ Serial.println(output); } -void loop(){} \ No newline at end of file +void loop() { + // nop +} \ No newline at end of file diff --git a/library.properties b/library.properties index 5659a28..0b04412 100644 --- a/library.properties +++ b/library.properties @@ -1,6 +1,6 @@ name=base64_encode author=dojyorin -version=2.0.3 +version=2.0.4 architectures=* includes=arduino_base64.hpp sentence=Convert between binary and base64 encoded string. diff --git a/src/arduino_base64.hpp b/src/arduino_base64.hpp index 4eb78dc..b36790f 100644 --- a/src/arduino_base64.hpp +++ b/src/arduino_base64.hpp @@ -7,7 +7,7 @@ * Convert between binary and base64 encoded string. * @see https://github.com/dojyorin/arduino_base64 */ -namespace base64{ +namespace base64 { /** * Convert binary to base64 encoded string. * If input is string, cast to `uint8_t*`. diff --git a/src/base64.cpp b/src/base64.cpp index 0f6604e..f6e6018 100644 --- a/src/base64.cpp +++ b/src/base64.cpp @@ -1,11 +1,11 @@ #include "./arduino_base64.hpp" -namespace{ +namespace { constexpr char CODE[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - uint8_t indexOf(char search){ - for(uint8_t i = 0; i < 64; i++){ - if(::CODE[i] == search){ + uint8_t indexOf(char search) { + for(uint8_t i = 0; i < 64; i++) { + if(::CODE[i] == search) { return i; } } @@ -13,32 +13,32 @@ namespace{ return 0xFF; } - void to6x4(uint8_t* input, uint8_t* output){ + void to6x4(uint8_t* input, uint8_t* output) { output[0] = (input[0] & 0xFC) >> 2; output[1] = ((input[0] & 0x03) << 4) + ((input[1] & 0xF0) >> 4); output[2] = ((input[1] & 0x0F) << 2) + ((input[2] & 0xC0) >> 6); output[3] = input[2] & 0x3F; } - void to8x3(uint8_t* input, uint8_t* output){ + void to8x3(uint8_t* input, uint8_t* output) { output[0] = (input[0] << 2) + ((input[1] & 0x30) >> 4); output[1] = ((input[1] & 0x0F) << 4) + ((input[2] & 0x3C) >> 2); output[2] = ((input[2] & 0x03) << 6) + input[3]; } } -void base64::encode(const uint8_t* input, size_t inputLength, char* output){ +void base64::encode(const uint8_t* input, size_t inputLength, char* output) { uint8_t position = 0; uint8_t bit8x3[3] = {}; uint8_t bit6x4[4] = {}; - while(inputLength--){ + while(inputLength--) { bit8x3[position++] = *input++; - if(position == 3){ + if(position == 3) { ::to6x4(bit8x3, bit6x4); - for(const auto &v: bit6x4){ + for(const auto &v: bit6x4) { *output++ = ::CODE[v]; } @@ -46,18 +46,18 @@ void base64::encode(const uint8_t* input, size_t inputLength, char* output){ } } - if(position){ - for(uint8_t i = position; i < 3; i++){ + if(position) { + for(uint8_t i = position; i < 3; i++) { bit8x3[i] = 0x00; } ::to6x4(bit8x3, bit6x4); - for(uint8_t i = 0; i < position + 1; i++){ + for(uint8_t i = 0; i < position + 1; i++) { *output++ = ::CODE[bit6x4[i]]; } - while(position++ < 3){ + while(position++ < 3) { *output++ = '='; } } @@ -65,27 +65,27 @@ void base64::encode(const uint8_t* input, size_t inputLength, char* output){ *output = '\0'; } -size_t base64::encodeLength(size_t inputLength){ +size_t base64::encodeLength(size_t inputLength) { return (inputLength + 2 - ((inputLength + 2) % 3)) / 3 * 4 + 1; } -void base64::decode(const char* input, uint8_t* output){ +void base64::decode(const char* input, uint8_t* output) { auto inputLength = strlen(input); uint8_t position = 0; uint8_t bit8x3[3] = {}; uint8_t bit6x4[4] = {}; - while(inputLength--){ - if(*input == '='){ + while(inputLength--) { + if(*input == '=') { break; } bit6x4[position++] = ::indexOf(*input++); - if(position == 4){ + if(position == 4) { ::to8x3(bit6x4, bit8x3); - for(const auto &v: bit8x3){ + for(const auto &v: bit8x3) { *output++ = v; } @@ -93,26 +93,26 @@ void base64::decode(const char* input, uint8_t* output){ } } - if(position){ - for(uint8_t i = position; i < 4; i++){ + if(position) { + for(uint8_t i = position; i < 4; i++) { bit6x4[i] = 0x00; } ::to8x3(bit6x4, bit8x3); - for(uint8_t i = 0; i < position - 1; i++){ + for(uint8_t i = 0; i < position - 1; i++) { *output++ = bit8x3[i]; } } } -size_t base64::decodeLength(const char* input){ +size_t base64::decodeLength(const char* input) { auto inputLength = strlen(input); uint8_t equal = 0; input += inputLength - 1; - while(*input-- == '='){ + while(*input-- == '=') { equal++; }