improve print
This commit is contained in:
parent
e5e9cfd9f5
commit
74ffaa6d22
15
sign.go
15
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user