36 lines
618 B
Go
36 lines
618 B
Go
|
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
||
|
|
||
|
package folio
|
||
|
|
||
|
import (
|
||
|
"decl/internal/data"
|
||
|
"decl/internal/signature"
|
||
|
"errors"
|
||
|
"encoding/hex"
|
||
|
)
|
||
|
|
||
|
|
||
|
var (
|
||
|
ErrInvalidSignature error = errors.New("Invalid signature")
|
||
|
)
|
||
|
|
||
|
type Signature []byte
|
||
|
|
||
|
func (s Signature) Verify(res data.ContentHasher) error {
|
||
|
i := &signature.Ident{}
|
||
|
return i.VerifySum(res.Hash(), s)
|
||
|
}
|
||
|
|
||
|
func (s *Signature) SetHexString(sig string) error {
|
||
|
if v, e := hex.DecodeString(sig); e == nil {
|
||
|
*s = v
|
||
|
} else {
|
||
|
return e
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (s *Signature) String() string {
|
||
|
return hex.EncodeToString(*s)
|
||
|
}
|