From 74ffaa6d22c0e66f9b54aeb69ade227cf64872a3 Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Sun, 3 Apr 2022 17:02:09 +0200 Subject: [PATCH] improve print --- sign.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/sign.go b/sign.go index 4b572c1..65b88a9 100644 --- a/sign.go +++ b/sign.go @@ -21,6 +21,11 @@ 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 @@ -51,7 +56,7 @@ func (tc TokenCoder) SeedHex() string { } func Format(token string) (txt string, err error) { - var payload interface{} + var tp tokenPrint var data []byte data, err = b64.DecodeString(strings.TrimFunc(token, trim)) if err != nil { @@ -74,16 +79,14 @@ func Format(token string) (txt string, err error) { return } + tp.Signature = hex.EncodeToString(td.Signature) buf.Reset() buf.Write(td.Payload) - err = dec.Decode(&payload) - + err = dec.Decode(&tp.Payload) buf.Reset() - buf.Write([]byte("SIGNATURE=" + hex.EncodeToString(td.Signature) + "\n")) - enc := codec.NewEncoder(buf, &jHandle) - err = enc.Encode(payload) + err = enc.Encode(tp) txt = buf.String() return }