chrly/internal/client/signer/local.go
2024-03-05 13:07:54 +01:00

35 lines
615 B
Go

package signer
import (
"context"
"io"
"strings"
)
type Signer interface {
Sign(data io.Reader) ([]byte, error)
GetPublicKey(format string) ([]byte, error)
}
type LocalSigner struct {
Signer
}
func (s *LocalSigner) Sign(ctx context.Context, data string) (string, error) {
signed, err := s.Signer.Sign(strings.NewReader(data))
if err != nil {
return "", err
}
return string(signed), nil
}
func (s *LocalSigner) GetPublicKey(ctx context.Context, format string) (string, error) {
publicKey, err := s.Signer.GetPublicKey(format)
if err != nil {
return "", err
}
return string(publicKey), nil
}