Compare commits

..

No commits in common. "master" and "v0.1.3" have entirely different histories.

28
sign.go
View File

@ -6,6 +6,7 @@ import (
"crypto/rand"
"encoding/base64"
"encoding/hex"
"encoding/json"
"errors"
"github.com/ugorji/go/codec"
"hash/crc64"
@ -21,11 +22,6 @@ type tokenData struct {
Payload []byte `codec:"p"`
}
type tokenPrint struct {
Signature string `codec:"signature"`
Payload interface{} `codec:"payload"`
}
type TokenCoder struct {
valid bool
privKey ed25519.PrivateKey
@ -56,7 +52,7 @@ func (tc TokenCoder) SeedHex() string {
}
func Format(token string) (txt string, err error) {
var tp tokenPrint
var payload interface{}
var data []byte
data, err = b64.DecodeString(strings.TrimFunc(token, trim))
if err != nil {
@ -64,14 +60,10 @@ func Format(token string) (txt string, err error) {
}
buf := bytes.NewBuffer(nil)
var cHandle codec.CborHandle
var jHandle codec.JsonHandle
jHandle.HTMLCharsAsIs = true
jHandle.MapKeyAsString = true
jHandle.Indent = 4
var handle codec.CborHandle
buf.Write(data)
dec := codec.NewDecoder(buf, &cHandle)
dec := codec.NewDecoder(buf, &handle)
var td tokenData
err = dec.Decode(&td)
@ -79,14 +71,18 @@ func Format(token string) (txt string, err error) {
return
}
tp.Signature = hex.EncodeToString(td.Signature)
buf.Reset()
buf.Write(td.Payload)
err = dec.Decode(&tp.Payload)
err = dec.Decode(&payload)
buf.Reset()
enc := codec.NewEncoder(buf, &jHandle)
err = enc.Encode(tp)
buf.Write([]byte("SIGNATURE=" + hex.EncodeToString(td.Signature) + "\n"))
enc := json.NewEncoder(buf)
enc.SetEscapeHTML(false)
enc.SetIndent("", "\t")
err = enc.Encode(payload)
txt = buf.String()
return
}