Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6e0e420356 | ||
|
|
df5b7bc6ee | ||
|
|
0bd72a8c32 | ||
|
|
714f5c0130 | ||
|
|
f067816be3 | ||
|
|
66b6f5f82a | ||
|
|
c1e5d4e95b | ||
|
|
f68598dd02 | ||
|
|
daffaef0db | ||
|
|
95cb7074c4 | ||
|
|
2985033078 |
11
.github/workflows/automerge.yml
vendored
Normal file
11
.github/workflows/automerge.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# File managed by web3-bot. DO NOT EDIT.
|
||||
# See https://github.com/protocol/.github/ for details.
|
||||
|
||||
name: Automerge
|
||||
on: [ pull_request ]
|
||||
|
||||
jobs:
|
||||
automerge:
|
||||
uses: protocol/.github/.github/workflows/automerge.yml@master
|
||||
with:
|
||||
job: 'automerge'
|
||||
73
.github/workflows/go-check.yml
vendored
Normal file
73
.github/workflows/go-check.yml
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
# File managed by web3-bot. DO NOT EDIT.
|
||||
# See https://github.com/protocol/.github/ for details.
|
||||
|
||||
on: [push, pull_request]
|
||||
name: Go Checks
|
||||
|
||||
jobs:
|
||||
unit:
|
||||
runs-on: ubuntu-latest
|
||||
name: All
|
||||
env:
|
||||
RUNGOGENERATE: false
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: recursive
|
||||
- uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: "1.18.x"
|
||||
- name: Run repo-specific setup
|
||||
uses: ./.github/actions/go-check-setup
|
||||
if: hashFiles('./.github/actions/go-check-setup') != ''
|
||||
- name: Read config
|
||||
if: hashFiles('./.github/workflows/go-check-config.json') != ''
|
||||
run: |
|
||||
if jq -re .gogenerate ./.github/workflows/go-check-config.json; then
|
||||
echo "RUNGOGENERATE=true" >> $GITHUB_ENV
|
||||
fi
|
||||
- name: Install staticcheck
|
||||
run: go install honnef.co/go/tools/cmd/staticcheck@d7e217c1ff411395475b2971c0824e1e7cc1af98 # 2022.1 (v0.3.0)
|
||||
- name: Check that go.mod is tidy
|
||||
uses: protocol/multiple-go-modules@v1.2
|
||||
with:
|
||||
run: |
|
||||
go mod tidy
|
||||
if [[ -n $(git ls-files --other --exclude-standard --directory -- go.sum) ]]; then
|
||||
echo "go.sum was added by go mod tidy"
|
||||
exit 1
|
||||
fi
|
||||
git diff --exit-code -- go.sum go.mod
|
||||
- name: gofmt
|
||||
if: ${{ success() || failure() }} # run this step even if the previous one failed
|
||||
run: |
|
||||
out=$(gofmt -s -l .)
|
||||
if [[ -n "$out" ]]; then
|
||||
echo $out | awk '{print "::error file=" $0 ",line=0,col=0::File is not gofmt-ed."}'
|
||||
exit 1
|
||||
fi
|
||||
- name: go vet
|
||||
if: ${{ success() || failure() }} # run this step even if the previous one failed
|
||||
uses: protocol/multiple-go-modules@v1.2
|
||||
with:
|
||||
run: go vet ./...
|
||||
- name: staticcheck
|
||||
if: ${{ success() || failure() }} # run this step even if the previous one failed
|
||||
uses: protocol/multiple-go-modules@v1.2
|
||||
with:
|
||||
run: |
|
||||
set -o pipefail
|
||||
staticcheck ./... | sed -e 's@\(.*\)\.go@./\1.go@g'
|
||||
- name: go generate
|
||||
uses: protocol/multiple-go-modules@v1.2
|
||||
if: (success() || failure()) && env.RUNGOGENERATE == 'true'
|
||||
with:
|
||||
run: |
|
||||
git clean -fd # make sure there aren't untracked files / directories
|
||||
go generate ./...
|
||||
# check if go generate modified or added any files
|
||||
if ! $(git add . && git diff-index HEAD --exit-code --quiet); then
|
||||
echo "go generated caused changes to the repository:"
|
||||
git status --short
|
||||
exit 1
|
||||
fi
|
||||
68
.github/workflows/go-test.yml
vendored
Normal file
68
.github/workflows/go-test.yml
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
# File managed by web3-bot. DO NOT EDIT.
|
||||
# See https://github.com/protocol/.github/ for details.
|
||||
|
||||
on: [push, pull_request]
|
||||
name: Go Test
|
||||
|
||||
jobs:
|
||||
unit:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ "ubuntu", "windows", "macos" ]
|
||||
go: [ "1.17.x", "1.18.x" ]
|
||||
env:
|
||||
COVERAGES: ""
|
||||
runs-on: ${{ format('{0}-latest', matrix.os) }}
|
||||
name: ${{ matrix.os }} (go ${{ matrix.go }})
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: recursive
|
||||
- uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: ${{ matrix.go }}
|
||||
- name: Go information
|
||||
run: |
|
||||
go version
|
||||
go env
|
||||
- name: Use msys2 on windows
|
||||
if: ${{ matrix.os == 'windows' }}
|
||||
shell: bash
|
||||
# The executable for msys2 is also called bash.cmd
|
||||
# https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md#shells
|
||||
# If we prepend its location to the PATH
|
||||
# subsequent 'shell: bash' steps will use msys2 instead of gitbash
|
||||
run: echo "C:/msys64/usr/bin" >> $GITHUB_PATH
|
||||
- name: Run repo-specific setup
|
||||
uses: ./.github/actions/go-test-setup
|
||||
if: hashFiles('./.github/actions/go-test-setup') != ''
|
||||
- name: Run tests
|
||||
uses: protocol/multiple-go-modules@v1.2
|
||||
with:
|
||||
# Use -coverpkg=./..., so that we include cross-package coverage.
|
||||
# If package ./A imports ./B, and ./A's tests also cover ./B,
|
||||
# this means ./B's coverage will be significantly higher than 0%.
|
||||
run: go test -v -coverprofile=module-coverage.txt -coverpkg=./... ./...
|
||||
- name: Run tests (32 bit)
|
||||
if: ${{ matrix.os != 'macos' }} # can't run 32 bit tests on OSX.
|
||||
uses: protocol/multiple-go-modules@v1.2
|
||||
env:
|
||||
GOARCH: 386
|
||||
with:
|
||||
run: |
|
||||
export "PATH=${{ env.PATH_386 }}:$PATH"
|
||||
go test -v ./...
|
||||
- name: Run tests with race detector
|
||||
if: ${{ matrix.os == 'ubuntu' }} # speed things up. Windows and OSX VMs are slow
|
||||
uses: protocol/multiple-go-modules@v1.2
|
||||
with:
|
||||
run: go test -v -race ./...
|
||||
- name: Collect coverage files
|
||||
shell: bash
|
||||
run: echo "COVERAGES=$(find . -type f -name 'module-coverage.txt' | tr -s '\n' ',' | sed 's/,$//')" >> $GITHUB_ENV
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@f32b3a3741e1053eb607407145bc9619351dc93b # v2.1.0
|
||||
with:
|
||||
files: '${{ env.COVERAGES }}'
|
||||
env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }}
|
||||
11
.github/workflows/release-check.yml
vendored
Normal file
11
.github/workflows/release-check.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# File managed by web3-bot. DO NOT EDIT.
|
||||
# See https://github.com/protocol/.github/ for details.
|
||||
|
||||
name: Release Checker
|
||||
on:
|
||||
pull_request:
|
||||
paths: [ 'version.json' ]
|
||||
|
||||
jobs:
|
||||
release-check:
|
||||
uses: protocol/.github/.github/workflows/release-check.yml@master
|
||||
11
.github/workflows/releaser.yml
vendored
Normal file
11
.github/workflows/releaser.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# File managed by web3-bot. DO NOT EDIT.
|
||||
# See https://github.com/protocol/.github/ for details.
|
||||
|
||||
name: Releaser
|
||||
on:
|
||||
push:
|
||||
paths: [ 'version.json' ]
|
||||
|
||||
jobs:
|
||||
releaser:
|
||||
uses: protocol/.github/.github/workflows/releaser.yml@master
|
||||
12
.github/workflows/tagpush.yml
vendored
Normal file
12
.github/workflows/tagpush.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
# File managed by web3-bot. DO NOT EDIT.
|
||||
# See https://github.com/protocol/.github/ for details.
|
||||
|
||||
name: Tag Push Checker
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- v*
|
||||
|
||||
jobs:
|
||||
releaser:
|
||||
uses: protocol/.github/.github/workflows/tagpush.yml@master
|
||||
30
.travis.yml
30
.travis.yml
@@ -1,30 +0,0 @@
|
||||
os:
|
||||
- linux
|
||||
|
||||
language: go
|
||||
|
||||
go:
|
||||
- 1.11.x
|
||||
|
||||
env:
|
||||
global:
|
||||
- GOTFLAGS="-race"
|
||||
matrix:
|
||||
- BUILD_DEPTYPE=gomod
|
||||
|
||||
|
||||
# disable travis install
|
||||
install:
|
||||
- true
|
||||
|
||||
script:
|
||||
- bash <(curl -s https://raw.githubusercontent.com/ipfs/ci-helpers/master/travis-ci/run-standard-tests.sh)
|
||||
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $GOPATH/pkg/mod
|
||||
- /home/travis/.cache/go-build
|
||||
|
||||
notifications:
|
||||
email: false
|
||||
94
base256emoji.go
Normal file
94
base256emoji.go
Normal file
@@ -0,0 +1,94 @@
|
||||
package multibase
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
var base256emojiTable = [256]rune{
|
||||
// Curated list, this is just a list of things that *somwhat* are related to our comunity
|
||||
'🚀', '🪐', '☄', '🛰', '🌌', // Space
|
||||
'🌑', '🌒', '🌓', '🌔', '🌕', '🌖', '🌗', '🌘', // Moon
|
||||
'🌍', '🌏', '🌎', // Our Home, for now (earth)
|
||||
'☉', '☀', // Our Garden, for now (sol)
|
||||
'💻', '🖥', '💾', '💿', // Computer
|
||||
// The rest is completed from https://home.unicode.org/emoji/emoji-frequency/ at the time of creation (december 2021) (the data is from 2019), most used first until we reach 256.
|
||||
// We exclude modifier based emojies (such as flags) as they are bigger than one single codepoint.
|
||||
// Some other emojies were removed adhoc for various reasons.
|
||||
'😂', '❤', '😍', '🤣', '😊', '🙏', '💕', '😭', '😘', '👍',
|
||||
'😅', '👏', '😁', '🔥', '🥰', '💔', '💖', '💙', '😢', '🤔',
|
||||
'😆', '🙄', '💪', '😉', '☺', '👌', '🤗', '💜', '😔', '😎',
|
||||
'😇', '🌹', '🤦', '🎉', '💞', '✌', '✨', '🤷', '😱', '😌',
|
||||
'🌸', '🙌', '😋', '💗', '💚', '😏', '💛', '🙂', '💓', '🤩',
|
||||
'😄', '😀', '🖤', '😃', '💯', '🙈', '👇', '🎶', '😒', '🤭',
|
||||
'❣', '😜', '💋', '👀', '😪', '😑', '💥', '🙋', '😞', '😩',
|
||||
'😡', '🤪', '👊', '🥳', '😥', '🤤', '👉', '💃', '😳', '✋',
|
||||
'😚', '😝', '😴', '🌟', '😬', '🙃', '🍀', '🌷', '😻', '😓',
|
||||
'⭐', '✅', '🥺', '🌈', '😈', '🤘', '💦', '✔', '😣', '🏃',
|
||||
'💐', '☹', '🎊', '💘', '😠', '☝', '😕', '🌺', '🎂', '🌻',
|
||||
'😐', '🖕', '💝', '🙊', '😹', '🗣', '💫', '💀', '👑', '🎵',
|
||||
'🤞', '😛', '🔴', '😤', '🌼', '😫', '⚽', '🤙', '☕', '🏆',
|
||||
'🤫', '👈', '😮', '🙆', '🍻', '🍃', '🐶', '💁', '😲', '🌿',
|
||||
'🧡', '🎁', '⚡', '🌞', '🎈', '❌', '✊', '👋', '😰', '🤨',
|
||||
'😶', '🤝', '🚶', '💰', '🍓', '💢', '🤟', '🙁', '🚨', '💨',
|
||||
'🤬', '✈', '🎀', '🍺', '🤓', '😙', '💟', '🌱', '😖', '👶',
|
||||
'🥴', '▶', '➡', '❓', '💎', '💸', '⬇', '😨', '🌚', '🦋',
|
||||
'😷', '🕺', '⚠', '🙅', '😟', '😵', '👎', '🤲', '🤠', '🤧',
|
||||
'📌', '🔵', '💅', '🧐', '🐾', '🍒', '😗', '🤑', '🌊', '🤯',
|
||||
'🐷', '☎', '💧', '😯', '💆', '👆', '🎤', '🙇', '🍑', '❄',
|
||||
'🌴', '💣', '🐸', '💌', '📍', '🥀', '🤢', '👅', '💡', '💩',
|
||||
'👐', '📸', '👻', '🤐', '🤮', '🎼', '🥵', '🚩', '🍎', '🍊',
|
||||
'👼', '💍', '📣', '🥂',
|
||||
}
|
||||
|
||||
var base256emojiReverseTable map[rune]byte
|
||||
|
||||
func init() {
|
||||
base256emojiReverseTable = make(map[rune]byte, len(base256emojiTable))
|
||||
for i, v := range base256emojiTable {
|
||||
base256emojiReverseTable[v] = byte(i)
|
||||
}
|
||||
}
|
||||
|
||||
func base256emojiEncode(in []byte) string {
|
||||
var l int
|
||||
for _, v := range in {
|
||||
l += utf8.RuneLen(base256emojiTable[v])
|
||||
}
|
||||
var out strings.Builder
|
||||
out.Grow(l)
|
||||
for _, v := range in {
|
||||
out.WriteRune(base256emojiTable[v])
|
||||
}
|
||||
return out.String()
|
||||
}
|
||||
|
||||
type base256emojiCorruptInputError struct {
|
||||
index int
|
||||
char rune
|
||||
}
|
||||
|
||||
func (e base256emojiCorruptInputError) Error() string {
|
||||
return "illegal base256emoji data at input byte " + strconv.FormatInt(int64(e.index), 10) + ", char: '" + string(e.char) + "'"
|
||||
}
|
||||
|
||||
func (e base256emojiCorruptInputError) String() string {
|
||||
return e.Error()
|
||||
}
|
||||
|
||||
func base256emojiDecode(in string) ([]byte, error) {
|
||||
out := make([]byte, utf8.RuneCountInString(in))
|
||||
var stri int
|
||||
for i := 0; len(in) > 0; i++ {
|
||||
r, n := utf8.DecodeRuneInString(in)
|
||||
in = in[n:]
|
||||
var ok bool
|
||||
out[i], ok = base256emojiReverseTable[r]
|
||||
if !ok {
|
||||
return nil, base256emojiCorruptInputError{stri, r}
|
||||
}
|
||||
stri += n
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
26
base256emoji_test.go
Normal file
26
base256emoji_test.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package multibase
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestBase256EmojiAlphabet(t *testing.T) {
|
||||
var c uint
|
||||
for _, v := range base256emojiTable {
|
||||
if v != rune(0) {
|
||||
c++
|
||||
}
|
||||
}
|
||||
if c != 256 {
|
||||
t.Errorf("Base256Emoji count is wrong, expected 256, got %d.", c)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBase256EmojiUniq(t *testing.T) {
|
||||
m := make(map[rune]struct{}, len(base256emojiTable))
|
||||
for i, v := range base256emojiTable {
|
||||
_, ok := m[v]
|
||||
if ok {
|
||||
t.Errorf("Base256Emoji duplicate %s at index %d.", string(v), i)
|
||||
}
|
||||
m[v] = struct{}{}
|
||||
}
|
||||
}
|
||||
14
encoder.go
14
encoder.go
@@ -2,6 +2,7 @@ package multibase
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// Encoder is a multibase encoding that is verified to be supported and
|
||||
@@ -14,7 +15,7 @@ type Encoder struct {
|
||||
func NewEncoder(base Encoding) (Encoder, error) {
|
||||
_, ok := EncodingToStr[base]
|
||||
if !ok {
|
||||
return Encoder{-1}, fmt.Errorf("Unsupported multibase encoding: %d", base)
|
||||
return Encoder{-1}, fmt.Errorf("unsupported multibase encoding: %d", base)
|
||||
}
|
||||
return Encoder{base}, nil
|
||||
}
|
||||
@@ -33,17 +34,18 @@ func MustNewEncoder(base Encoding) Encoder {
|
||||
// either be the multibase name or single character multibase prefix
|
||||
func EncoderByName(str string) (Encoder, error) {
|
||||
var base Encoding
|
||||
ok := true
|
||||
var ok bool
|
||||
if len(str) == 0 {
|
||||
return Encoder{-1}, fmt.Errorf("Empty multibase encoding")
|
||||
} else if len(str) == 1 {
|
||||
base = Encoding(str[0])
|
||||
return Encoder{-1}, fmt.Errorf("empty multibase encoding")
|
||||
} else if utf8.RuneCountInString(str) == 1 {
|
||||
r, _ := utf8.DecodeRuneInString(str)
|
||||
base = Encoding(r)
|
||||
_, ok = EncodingToStr[base]
|
||||
} else {
|
||||
base, ok = Encodings[str]
|
||||
}
|
||||
if !ok {
|
||||
return Encoder{-1}, fmt.Errorf("Unsupported multibase encoding: %s", str)
|
||||
return Encoder{-1}, fmt.Errorf("unsupported multibase encoding: %s", str)
|
||||
}
|
||||
return Encoder{base}, nil
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package multibase
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
func TestInvalidCode(t *testing.T) {
|
||||
@@ -43,9 +44,10 @@ func TestEncoder(t *testing.T) {
|
||||
}
|
||||
// Test that an encoder can be created from the single letter
|
||||
// prefix
|
||||
_, err = EncoderByName(str[0:1])
|
||||
r, _ := utf8.DecodeRuneInString(str)
|
||||
_, err = EncoderByName(string(r))
|
||||
if err != nil {
|
||||
t.Fatalf("EncoderByName(%s) failed: %v", str[0:1], err)
|
||||
t.Fatalf("EncoderByName(%s) failed: %v", string(r), err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
2
go.mod
2
go.mod
@@ -1,6 +1,6 @@
|
||||
module github.com/multiformats/go-multibase
|
||||
|
||||
go 1.11
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/mr-tron/base58 v1.1.0
|
||||
|
||||
13
multibase.go
13
multibase.go
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"unicode/utf8"
|
||||
|
||||
b58 "github.com/mr-tron/base58/base58"
|
||||
b32 "github.com/multiformats/go-base32"
|
||||
@@ -38,6 +39,7 @@ const (
|
||||
Base64url = 'u'
|
||||
Base64pad = 'M'
|
||||
Base64urlPad = 'U'
|
||||
Base256Emoji = '🚀'
|
||||
)
|
||||
|
||||
// EncodingToStr is a map of the supported encoding, unsupported encoding
|
||||
@@ -63,6 +65,7 @@ var EncodingToStr = map[Encoding]string{
|
||||
'u': "base64url",
|
||||
'M': "base64pad",
|
||||
'U': "base64urlpad",
|
||||
Base256Emoji: "base256emoji",
|
||||
}
|
||||
|
||||
var Encodings = map[string]Encoding{}
|
||||
@@ -84,7 +87,7 @@ func Encode(base Encoding, data []byte) (string, error) {
|
||||
switch base {
|
||||
case Identity:
|
||||
// 0x00 inside a string is OK in golang and causes no problems with the length calculation.
|
||||
return string(Identity) + string(data), nil
|
||||
return string(rune(Identity)) + string(data), nil
|
||||
case Base2:
|
||||
return string(Base2) + binaryEncodeToString(data), nil
|
||||
case Base16:
|
||||
@@ -123,6 +126,8 @@ func Encode(base Encoding, data []byte) (string, error) {
|
||||
return string(Base64url) + base64.RawURLEncoding.EncodeToString(data), nil
|
||||
case Base64:
|
||||
return string(Base64) + base64.RawStdEncoding.EncodeToString(data), nil
|
||||
case Base256Emoji:
|
||||
return string(Base256Emoji) + base256emojiEncode(data), nil
|
||||
default:
|
||||
return "", ErrUnsupportedEncoding
|
||||
}
|
||||
@@ -135,7 +140,8 @@ func Decode(data string) (Encoding, []byte, error) {
|
||||
return 0, nil, fmt.Errorf("cannot decode multibase for zero length string")
|
||||
}
|
||||
|
||||
enc := Encoding(data[0])
|
||||
r, _ := utf8.DecodeRuneInString(data)
|
||||
enc := Encoding(r)
|
||||
|
||||
switch enc {
|
||||
case Identity:
|
||||
@@ -179,6 +185,9 @@ func Decode(data string) (Encoding, []byte, error) {
|
||||
case Base64url:
|
||||
bytes, err := base64.RawURLEncoding.DecodeString(data[1:])
|
||||
return Base64url, bytes, err
|
||||
case Base256Emoji:
|
||||
bytes, err := base256emojiDecode(data[4:])
|
||||
return Base256Emoji, bytes, err
|
||||
default:
|
||||
return -1, nil, ErrUnsupportedEncoding
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ func TestMap(t *testing.T) {
|
||||
|
||||
var sampleBytes = []byte("Decentralize everything!!!")
|
||||
var encodedSamples = map[Encoding]string{
|
||||
Identity: string(0x00) + "Decentralize everything!!!",
|
||||
Identity: string(rune(0x00)) + "Decentralize everything!!!",
|
||||
Base2: "00100010001100101011000110110010101101110011101000111001001100001011011000110100101111010011001010010000001100101011101100110010101110010011110010111010001101000011010010110111001100111001000010010000100100001",
|
||||
Base16: "f446563656e7472616c697a652065766572797468696e67212121",
|
||||
Base16Upper: "F446563656E7472616C697A652065766572797468696E67212121",
|
||||
@@ -44,6 +44,7 @@ var encodedSamples = map[Encoding]string{
|
||||
Base64url: "uRGVjZW50cmFsaXplIGV2ZXJ5dGhpbmchISE",
|
||||
Base64pad: "MRGVjZW50cmFsaXplIGV2ZXJ5dGhpbmchISE=",
|
||||
Base64urlPad: "URGVjZW50cmFsaXplIGV2ZXJ5dGhpbmchISE=",
|
||||
Base256Emoji: "🚀💛✋💃✋😻😈🥺🤤🍀🌟💐✋😅✋💦✋🥺🏃😈😴🌟😻😝👏👏👏",
|
||||
}
|
||||
|
||||
func testEncode(t *testing.T, encoding Encoding, bytes []byte, expected string) {
|
||||
@@ -91,22 +92,22 @@ func TestRoundTrip(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
|
||||
_, _, err := Decode(string(base) + "\u00A0")
|
||||
_, _, err := Decode(string(rune(base)) + "\u00A0")
|
||||
if err == nil {
|
||||
t.Fatal(EncodingToStr[base] + " decode should fail on low-unicode")
|
||||
}
|
||||
|
||||
_, _, err = Decode(string(base) + "\u1F4A8")
|
||||
_, _, err = Decode(string(rune(base)) + "\u1F4A8")
|
||||
if err == nil {
|
||||
t.Fatal(EncodingToStr[base] + " decode should fail on emoji")
|
||||
}
|
||||
|
||||
_, _, err = Decode(string(base) + "!")
|
||||
_, _, err = Decode(string(rune(base)) + "!")
|
||||
if err == nil {
|
||||
t.Fatal(EncodingToStr[base] + " decode should fail on punctuation")
|
||||
}
|
||||
|
||||
_, _, err = Decode(string(base) + "\xA0")
|
||||
_, _, err = Decode(string(rune(base)) + "\xA0")
|
||||
if err == nil {
|
||||
t.Fatal(EncodingToStr[base] + " decode should fail on high-latin1")
|
||||
}
|
||||
|
||||
2
spec
2
spec
Submodule spec updated: 3806057e6f...cffd1aa308
@@ -66,7 +66,7 @@ func TestSpec(t *testing.T) {
|
||||
}
|
||||
}
|
||||
func TestSpecVectors(t *testing.T) {
|
||||
files, err := filepath.Glob("spec/tests/test[0-9]*.csv")
|
||||
files, err := filepath.Glob("spec/tests/*.csv")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
3
version.json
Normal file
3
version.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"version": "v0.1.0"
|
||||
}
|
||||
Reference in New Issue
Block a user