-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from xordataexchange/unencrypted
Unencrypted
- Loading branch information
Showing
6 changed files
with
197 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,30 @@ | ||
// Package standard implements base64 encoding in the following format: | ||
// | ||
// base64(data) | ||
// | ||
package standard | ||
|
||
import ( | ||
"bytes" | ||
"encoding/base64" | ||
"io/ioutil" | ||
) | ||
|
||
// Deocde decodes data using the standard codec. | ||
func Decode(data []byte) ([]byte, error) { | ||
decoder := base64.NewDecoder(base64.StdEncoding, bytes.NewBuffer(data)) | ||
bytes, err := ioutil.ReadAll(decoder) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return bytes, nil | ||
} | ||
|
||
// Encode encodes data to a base64 encoded using the standard codec. | ||
func Encode(data []byte) ([]byte, error) { | ||
buffer := new(bytes.Buffer) | ||
encoder := base64.NewEncoder(base64.StdEncoding, buffer) | ||
encoder.Write(data) | ||
encoder.Close() | ||
return buffer.Bytes(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,26 @@ | ||
package standard | ||
|
||
import "testing" | ||
|
||
var encodingTests = []struct { | ||
in, out string | ||
}{ | ||
{"opentext", "opentext"}, | ||
{"\nblue\t63", "\nblue\t63"}, | ||
} | ||
|
||
func TestEncoding(t *testing.T) { | ||
for _, tt := range encodingTests { | ||
encoded, err := Encode([]byte(tt.in)) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
decoded, err := Decode(encoded) | ||
if err != nil { | ||
t.Errorf(err.Error()) | ||
} | ||
if tt.out != string(decoded) { | ||
t.Errorf("want %s, got %s", tt.out, decoded) | ||
} | ||
} | ||
} |