Skip to content

Commit

Permalink
Update workflows and refactor code format. (#14)
Browse files Browse the repository at this point in the history
* code format.

* only arduino vendor.

* version.

* year
  • Loading branch information
dojyorin authored Aug 17, 2024
1 parent ede89a7 commit 9eb8276
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 82 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
35 changes: 8 additions & 27 deletions .github/workflows/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 7 additions & 19 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 4 additions & 2 deletions examples/decode/decode.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "arduino_base64.hpp"

void setup(){
void setup() {
Serial.begin(115200);
while(!Serial);

Expand All @@ -11,4 +11,6 @@ void setup(){
Serial.println((const char*)output);
}

void loop(){}
void loop() {
// nop
}
6 changes: 4 additions & 2 deletions examples/encode/encode.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "arduino_base64.hpp"

void setup(){
void setup() {
Serial.begin(115200);
while(!Serial);

Expand All @@ -12,4 +12,6 @@ void setup(){
Serial.println(output);
}

void loop(){}
void loop() {
// nop
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/arduino_base64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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*`.
Expand Down
50 changes: 25 additions & 25 deletions src/base64.cpp
Original file line number Diff line number Diff line change
@@ -1,118 +1,118 @@
#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;
}
}

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];
}

position = 0;
}
}

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++ = '=';
}
}

*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;
}

position = 0;
}
}

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++;
}

Expand Down

0 comments on commit 9eb8276

Please sign in to comment.