Skip to content

Commit

Permalink
Merge pull request #3 from dojyorin/dev
Browse files Browse the repository at this point in the history
Improve code and add actions workflow.
  • Loading branch information
dojyorin authored Jan 15, 2023
2 parents 0d9b90c + a000255 commit 7f6b98b
Show file tree
Hide file tree
Showing 13 changed files with 287 additions and 138 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Release
"on":
push:
tags: v[0-9]+.[0-9]+.[0-9]+
jobs:
release:
name: 'Release: ${{github.ref_name}}'
runs-on: ubuntu-latest
steps:
- name: clone repository
uses: actions/checkout@v3
- name: dispatch release
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
54 changes: 54 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Test
"on":
push:
branches:
- dev
paths-ignore:
- .git*
- '**.md'
- '*.properties'
pull_request:
branches:
- master
- dev
paths-ignore:
- .git*
- '**.md'
- '*.properties'
jobs:
test:
name: 'Test: ${{matrix.board.name}}'
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
board:
- vendor: arduino
arch: samd
name: arduino_zero_native
- vendor: adafruit
arch: samd
name: adafruit_trinket_m0
- vendor: teensy
arch: avr
name: teensy41
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://www.pjrc.com/teensy/package_teensy_index.json
board:
vendor: teensy
steps:
- name: clone repository
uses: actions/checkout@v3
- name: install arduino and run test
uses: arduino/compile-sketches@v1
with:
fqbn: ${{matrix.board.vendor}}:${{matrix.board.arch}}:${{matrix.board.name}}
platforms: |-
- name: ${{matrix.board.vendor}}:${{matrix.board.arch}}
source-url: ${{matrix.index}}
24 changes: 24 additions & 0 deletions .github/workflows_json/release.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "Release",
"on": {
"push": {
"tags": "v[0-9]+.[0-9]+.[0-9]+"
}
},
"jobs": {
"release": {
"name": "Release: ${{github.ref_name}}",
"runs-on": "ubuntu-latest",
"steps": [{
"name": "clone repository",
"uses": "actions/checkout@v3"
}, {
"name": "dispatch release",
"uses": "softprops/action-gh-release@v1",
"with": {
"generate_release_notes": true
}
}]
}
}
}
77 changes: 77 additions & 0 deletions .github/workflows_json/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"name": "Test",
"on": {
"push": {
"branches": [
"dev"
],
"paths-ignore": [
".git*",
"**.md",
"*.properties"
]
},
"pull_request": {
"branches": [
"master",
"dev"
],
"paths-ignore": [
".git*",
"**.md",
"*.properties"
]
}
},
"jobs": {
"test": {
"name": "Test: ${{matrix.board.name}}",
"runs-on": "ubuntu-latest",
"strategy": {
"fail-fast": true,
"matrix": {
"board": [{
"vendor": "arduino",
"arch": "samd",
"name": "arduino_zero_native"
}, {
"vendor": "adafruit",
"arch": "samd",
"name": "adafruit_trinket_m0"
}, {
"vendor": "teensy",
"arch": "avr",
"name": "teensy41"
}],
"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://www.pjrc.com/teensy/package_teensy_index.json",
"board": {
"vendor": "teensy"
}
}]
}
},
"steps": [{
"name": "clone repository",
"uses": "actions/checkout@v3"
}, {
"name": "install arduino and run test",
"uses": "arduino/compile-sketches@v1",
"with": {
"fqbn": "${{matrix.board.vendor}}:${{matrix.board.arch}}:${{matrix.board.name}}",
"platforms": "- name: ${{matrix.board.vendor}}:${{matrix.board.arch}}\n source-url: ${{matrix.index}}"
}
}]
}
}
}
4 changes: 4 additions & 0 deletions .github/workflows_json/to_yaml.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set -uC
cd ${0%/*}

yq -P -I 4 ./${1}.json | head -c -1 | tee ../workflows/${1}.yaml &> /dev/null
Empty file added .gitignore
Empty file.
2 changes: 1 addition & 1 deletion LICENSE → LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Kazuki Ota
Copyright (c) 2023 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
88 changes: 39 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,55 @@
# Arduino Base64 Codec
Binary based simple Base64 Codec for Arduino.
# **Arduino BASE64 Codec**
Binary based simple BASE64 Codec for Arduino.

# Example
## Encode
```c++
const char* rawData = "foobar";
size_t rawLength = strlen(rawData);
const char data[] = "foobar";
size_t dataLength = strlen(data);
char result[BASE64::encodeLength(dataLength)];

char encoded[BASE64::encodeLength(rawLength)];
BASE64::encode((const uint8_t*)rawData, rawLength, encoded);

Serial.println(encoded);
BASE64::encode((const uint8_t*)data, dataLength, result);
```
## Decode
```c++
const char* encoded = "Zm9vYmFy";
uint8_t raw[BASE64::decodeLength(encoded)];
BASE64::decode(encoded, raw);
const char data[] = "Zm9vYmFy";
uint8_t result[BASE64::decodeLength(data)];
Serial.println((char*)raw);
BASE64::decode(data, result);
```

# API
## void BASE64::encode(const uint8_t* input, size_t inputLength, char* output)
**Arguments**
- `input`: Receives raw binary data as a byte array.
- `inputLength`: Number of bytes of input data.
- `output`: Base64 encoded string.

**Return**
- Nothing.

**Note**
- If the input data is `char*` string, cast it to `uint8_t*`.

## size_t BASE64::encodeLength(size_t inputLength)
**Arguments**
- `inputLength`: Number of bytes of input data.

**Return**
- Number of characters after Base64 encoding.

## void BASE64::decode(const char* input, uint8_t* output)
**Arguments**
- `input`: Receives string data as a base64 encoded.
- `output`: Raw binary data.

**Return**
- Nothing.

**Note**
- If the output data is string, you can cast it to `char*`.

## size_t BASE64::decodeLength(const char* input)
**Arguments**
- `input`: Receives string data as a base64 encoded.

**Return**
- Number of bytes after Base64 decoding.
## `BASE64::encode()`
- Arguments
- `input` : `const uint8_t*` ... Binary data.
- `inputLength` : `size_t` ... Number of bytes of input data.
- `output` : `char*` ... BASE64 encoded string.
- Result
- `void`

If the input data is string such as `char*`, cast it to `uint8_t*`.

## `BASE64::encodeLength()`
- Arguments
- `inputLength` : `size_t` ... Number of bytes of input data.
- Result
- `size_t` ... Number of characters after BASE64 encoding.

## `BASE64::decode()`
- Arguments
- `input` : `const char*` ... BASE64 encoded string.
- `output` : `uint8_t*` ... Binary data.
- Result
- `void`

If the output data is string, you can cast it to `char*`.

## `BASE64::decodeLength()`
- Arguments
- `input` : `const char*` ... BASE64 encoded string.
- Result
- `size_t` ... Number of bytes after BASE64 decoding.

# Disclaimer
According to MIT License.
8 changes: 4 additions & 4 deletions examples/decode/decode.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ void setup(){
Serial.begin(115200);
while(!Serial);

const char* encoded = "Zm9vYmFy";
const char data[] = "Zm9vYmFy";
uint8_t result[BASE64::decodeLength(data)];

uint8_t raw[BASE64::decodeLength(encoded)];
BASE64::decode(encoded, raw);
BASE64::decode(data, result);

Serial.println((char*)raw);
Serial.println((char*)result);
}

void loop(){}
10 changes: 5 additions & 5 deletions examples/encode/encode.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ void setup(){
Serial.begin(115200);
while(!Serial);

const char* rawData = "foobar";
size_t rawLength = strlen(rawData);
const char data[] = "foobar";
size_t dataLength = strlen(data);
char result[BASE64::encodeLength(dataLength)];

char encoded[BASE64::encodeLength(rawLength)];
BASE64::encode((const uint8_t*)rawData, rawLength, encoded);
BASE64::encode((const uint8_t*)data, dataLength, result);

Serial.println(encoded);
Serial.println(result);
}

void loop(){}
8 changes: 4 additions & 4 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=Base64_Codec
version=1.0.6
name=BASE64_Codec
version=1.0.7
author=dojyorin
maintainer=https://github.com/dojyorin
sentence=Base64 codec
paragraph=Binary based simple Base64 codec.
sentence=BASE64 Codec
paragraph=Binary based simple BASE64 codec.
category=Other
url=https://github.com/dojyorin/arduino_base64.git
architectures=*
Loading

0 comments on commit 7f6b98b

Please sign in to comment.