22 lines
645 B
Go
22 lines
645 B
Go
package bloat
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"aead.dev/minisign"
|
|
)
|
|
|
|
// Verify checks the minisign signature and returns the body if valid.
|
|
func (b *Bloat[T]) verify(message []byte) ([]byte, bool, error) {
|
|
// signature is last 4 lines:
|
|
separated := bytes.Split(message, []byte("\n"))
|
|
signature := bytes.Join(separated[len(separated)-5:len(separated)], []byte("\n"))
|
|
body := bytes.Join(separated[:len(separated)-5], []byte("\n"))
|
|
// fmt.Println("signature:", string(signature))
|
|
// fmt.Println("body:", string(body))
|
|
// fmt.Println("end")
|
|
if !minisign.Verify(b.SignPub, body, signature) {
|
|
return []byte(""), false, nil
|
|
}
|
|
return body, true, nil
|
|
}
|