summaryrefslogtreecommitdiff
path: root/vendor/github.com/getlantern/hidden
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/getlantern/hidden')
-rw-r--r--vendor/github.com/getlantern/hidden/hidden.go66
-rw-r--r--vendor/github.com/getlantern/hidden/hidden_test.go33
2 files changed, 0 insertions, 99 deletions
diff --git a/vendor/github.com/getlantern/hidden/hidden.go b/vendor/github.com/getlantern/hidden/hidden.go
deleted file mode 100644
index 0c52b08..0000000
--- a/vendor/github.com/getlantern/hidden/hidden.go
+++ /dev/null
@@ -1,66 +0,0 @@
-// Package hidden provides the ability to "hide" binary data in a string using
-// a hex encoding with non-printing characters. Hidden data is demarcated with
-// a leading and trailing NUL character.
-package hidden
-
-import (
- "bytes"
- "fmt"
- "regexp"
-
- "github.com/getlantern/hex"
-)
-
-// 16 non-printing characters
-const hextable = "\x01\x02\x03\x04\x05\x06\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17"
-
-var (
- hexencoding = hex.NewEncoding(hextable)
-
- re *regexp.Regexp
-)
-
-func init() {
- var err error
- re, err = regexp.Compile(fmt.Sprintf("\x00[%v]+\x00", hextable))
- if err != nil {
- panic(err)
- }
-}
-
-// ToString encodes the given data as a hidden string, including leadnig and
-// trailing NULs.
-func ToString(data []byte) string {
- buf := bytes.NewBuffer(make([]byte, 0, 2+hex.EncodedLen(len(data))))
- // Leading NUL
- buf.WriteByte(0)
- buf.WriteString(hexencoding.EncodeToString(data))
- // Trailing NUL
- buf.WriteByte(0)
- return buf.String()
-}
-
-// FromString extracts the hidden data from a string, which is expected to
-// contain leading and trailing NULs.
-func FromString(str string) ([]byte, error) {
- return hexencoding.DecodeString(str[1 : len(str)-1])
-}
-
-// Extract extracts all hidden data from an arbitrary string.
-func Extract(str string) ([][]byte, error) {
- m := re.FindAllString(str, -1)
- result := make([][]byte, 0, len(m))
- for _, s := range m {
- b, err := FromString(s)
- if err != nil {
- return nil, err
- }
- result = append(result, b)
- }
- return result, nil
-}
-
-// Clean removes any hidden data from an arbitrary string.
-func Clean(str string) string {
- return re.ReplaceAllString(str, "")
-}
diff --git a/vendor/github.com/getlantern/hidden/hidden_test.go b/vendor/github.com/getlantern/hidden/hidden_test.go
deleted file mode 100644
index 420ce64..0000000
--- a/vendor/github.com/getlantern/hidden/hidden_test.go
+++ /dev/null
@@ -1,33 +0,0 @@
-package hidden
-
-import (
- "encoding/binary"
- "fmt"
- "testing"
-
- "github.com/stretchr/testify/assert"
-)
-
-func TestRoundTrip(t *testing.T) {
- str := "H"
- encoded := ToString([]byte(str))
- rt, err := FromString(encoded)
- if assert.NoError(t, err) {
- assert.Equal(t, str, string(rt))
- }
-}
-
-func TestExtract(t *testing.T) {
- a := []byte("Here is my string")
- b := make([]byte, 8)
- binary.BigEndian.PutUint64(b, 56)
- str := fmt.Sprintf("hidden%s data%s is fun", ToString(a), ToString(b))
- t.Log(str)
- out, err := Extract(str)
- if assert.NoError(t, err) {
- if assert.Len(t, out, 2) {
- assert.Equal(t, out, [][]byte{a, b})
- }
- }
- assert.Equal(t, "hidden data is fun", Clean(str))
-}