improve print

This commit is contained in:
Roy Olav Purser 2022-04-03 17:02:09 +02:00
parent e5e9cfd9f5
commit 74ffaa6d22
Signed by: roypur
GPG Key ID: E14D26A036F21656

15
sign.go
View File

@ -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
}