diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..0d08e26 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file + +version: 2 +updates: + - package-ecosystem: "github-actions" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "weekly" diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 0000000..9d3bfda --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,35 @@ +name: build-and-test + +on: + push: + # all branches + pull_request: + # all branches + + # This enables the Run Workflow button on the Actions tab. + workflow_dispatch: + +jobs: + build-and-test: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install Opendylan + uses: dylan-lang/install-opendylan@v3 + + - name: Download dependencies + run: dylan update + + - name: Build tests + run: dylan build base64-test-suite + + - name: Run tests + run: _build/bin/base64-test-suite --progress none --report surefire > _build/TEST-base64.xml + + - name: Publish Test Report + if: success() || failure() + uses: mikepenz/action-junit-report@v4 + with: + report_paths: '**/_build/TEST-*.xml' diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..46d23fa --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +# backup files +*~ +*.bak +.DS_Store + +# project file +*.hdp + +# documentation build directory +build/ + +# compiler build directory +_build/ + +# dylan tool package cache +_packages/ + +# package registry folder +registry/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..280586e --- /dev/null +++ b/README.md @@ -0,0 +1,85 @@ +# Base64 +[![build-and-test](https://github.com/dylan-lang/base64/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/dylan-lang/base64/actions/workflows/build-and-test.yml) + +Base64 implementation for Dylan + +## Abstract + +This library implements the Base64 transfer encoding algorithm as +defined in [RFC 1521](https://datatracker.ietf.org/doc/html/rfc1521) +by Borensten & Freed, September 1993. + +# Usage + +## Functions exported + +This library exports two functions + +- `base-64-encode (string) => (string)` and + +- `base-64-decode (string) => (string)` + +## Types of encoding + +The functions have two types of encoding/decoding: + +- `#"standard"` (default) and + +- `#"http"` + +The main difference between them are the padding characters used. You +can choose the type with the key parameter `encoding:` (see example below). + +## Example + +### Standard encoding/decoding + +Here is an example of usage of the standard encoding/decoding: + +```dylan +// Example string to encode +let original-string = "Many hands make light work."; + +// Encoding the string to base64 standard +let encoded-standard = base64-encode(original-string); +format-out("Encoded string: %=\n", encoded-standard); + +// Shows in output +// Encoded string: "TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcmsu" + +// Decoding the string in base64 standard +let decoded-string = base64-decode(encoded-standard); +format-out("Decoded string: %=\n", decoded-string); + +// Shows in output +// Decoded string: "Many hands make light work." +``` +### HTTP encoding/decoding + +To show the http encoding/decoding we will use a text that forces the +padding (base64 encoding uses padding to ensure that the length of the +encoded string is a multiple of 4 bytes). + +```dylan +// Example string to encode, note the missing dot at the end +let original-string = "Many hands make light work"; + +// Encoding the string to base64 http +let encoded-http = base64-encode(original-string, encoding: #"http"); +format-out("Encoded string: %=\n", encoded-http); + +// Shows in output (note the padding character '@') +// Encoded string: "TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcms@" + +// Decoding the string in base64 http +let decoded-string = base64-decode(encoded-http, encoding: #"http"); +format-out("Decoded string: %=\n", decoded-string); + +// Shows in output +// Decoded string: "Many hands make light work" +``` + +## Author + +Original version written in Common Lisp by Juri Pakaste . +Converted to Dylan by Carl Gay, July 2002. \ No newline at end of file diff --git a/dylan-package.json b/dylan-package.json new file mode 100644 index 0000000..20f6089 --- /dev/null +++ b/dylan-package.json @@ -0,0 +1,13 @@ +{ + "category": "encoding", + "contact": "dylan-lang@googlegroups.com", + "dependencies": [ ], + "dev-dependencies": [ "testworks" ], + "description": "Base64 encoding", + "name": "base64", + "version": "0.1.1", + "url": "https://github.com/dylan-lang/base64", + "keywords": [ "base64", "binary" ], + "license": "Unlicensed", + "license-url": "http://unlicense.org/" +} diff --git a/tests/base64-test-suite.dylan b/tests/base64-test-suite.dylan new file mode 100644 index 0000000..e8b7ff3 --- /dev/null +++ b/tests/base64-test-suite.dylan @@ -0,0 +1,30 @@ +Module: base64-test-suite + +define constant $text-samples + = #["Many hands make light work.", + "Many hands make light work"]; + +define constant $encoded-standard-samples + = #["TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcmsu", + "TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcms="]; + +define constant $encoded-http-samples + = #["TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcmsu", + "TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcms@"]; + +define test test-base64-standard () + for (text in $text-samples, encoded in $encoded-standard-samples) + assert-equal(encoded, base64-encode(text)); + assert-equal(text, base64-decode(encoded)) + end +end; + +define test test-base64-http () + for (text in $text-samples, encoded in $encoded-http-samples) + assert-equal(encoded, base64-encode(text, encoding: #"http")); + assert-equal(text, base64-decode(encoded, encoding: #"http")) + end +end; + +// Use `_build/bin/base64-test-suite --help` to see options. +run-test-application() diff --git a/tests/base64-test-suite.lid b/tests/base64-test-suite.lid new file mode 100644 index 0000000..c624fad --- /dev/null +++ b/tests/base64-test-suite.lid @@ -0,0 +1,4 @@ +Library: base64-test-suite +Files: library.dylan + base64-test-suite.dylan +Target-Type: executable diff --git a/tests/library.dylan b/tests/library.dylan new file mode 100644 index 0000000..3d0ebca --- /dev/null +++ b/tests/library.dylan @@ -0,0 +1,13 @@ +Module: dylan-user + +define library base64-test-suite + use common-dylan; + use testworks; + use base64; +end library; + +define module base64-test-suite + use common-dylan; + use testworks; + use base64; +end module;