4d56716fe8
--- type: change message: |- Give the project a proper root, dehub.dev/src/dehub.git "dehub" was being used as a placeholder up till this point, but now that the project has matured enough to have a home, and people will want to be installing the binary, it's time to give it a proper import root. change_hash: ADTjLNnPARatUjx6HDo7m3O+0KUcWvcMJq1kNrj9++PU credentials: - type: pgp_signature pub_key_id: 95C46FA6A41148AC body: iQIzBAABAgAdFiEEJ6tQKp6olvZKJ0lwlcRvpqQRSKwFAl6BECkACgkQlcRvpqQRSKyeJBAAocdHTs8AB2u9kZmMcJNf136Cq8KWjglvhuH49Nj9ILkeGOBF7+fIHBRSYxBQm4IIDWsjaQaRRhESJxKrkHUd7BG/z5iVsCfjYTyY7LPgv0oYJKEGbPOF2LDK2fuLLpRlA5v1fwamTdFYxs5j7yxW7weWiiKEgjMGjOiWQCWuqhw8rwOG6vjvYttQ5pekI7GvkdqWe+qODKmIF9xFFuhz7BMsFUAAwLz97W1wZkHA+O1BXGTe9hGwH88RY9IGJZftA6wuGes/SqwWJk+hpb89KV1yR0woMrwz7ITZZeNBboXO7KyxUXrfiLtxeRD4t15tJkdRY0FbIZvNCktviTqjPXOtoVh7c3m3p/LR5vcbgYDxaZKk51DYruovfaRI96Q9CYCK2kVb2PIJ4BJhlsUPzw8AWNVxXFECYZNEZly10hqNh4Xophr/x7PWOmoPoKL2PvXLtOHzk0r4Tw6JqUaC+7/08U/+lhlSKFKLdCj7Xru57qB7gxgd+P3g4rfqjIHqiB4tlViqR5RV7V8Z/goBMJg2uOJXIJGvwEZF9nj+QDgaofImMiQmcLrE6IBCYEELYz274w/6ugSCcdwVIC/n3VHuNY4zJDKN7Q/FgI9/GBS7UoNhTaHF2JmSKR9ErMKpm3PYPZr/VnsaXjfCBO5bVquvWLzfJ9aQ4t+tsRkuAvQ= account: mediocregopher
72 lines
2.4 KiB
Go
72 lines
2.4 KiB
Go
package sigcred
|
|
|
|
import (
|
|
"dehub.dev/src/dehub.git/fs"
|
|
"dehub.dev/src/dehub.git/typeobj"
|
|
)
|
|
|
|
// Signifier reprsents a single signing method being defined in the Config. Only
|
|
// one field should be set on each Signifier.
|
|
type Signifier struct {
|
|
PGPPublicKey *SignifierPGP `type:"pgp_public_key"`
|
|
PGPPublicKeyFile *SignifierPGPFile `type:"pgp_public_key_file"`
|
|
}
|
|
|
|
// MarshalYAML implements the yaml.Marshaler interface.
|
|
func (s Signifier) MarshalYAML() (interface{}, error) {
|
|
return typeobj.MarshalYAML(s)
|
|
}
|
|
|
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
|
func (s *Signifier) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
return typeobj.UnmarshalYAML(s, unmarshal)
|
|
}
|
|
|
|
// Interface returns the SignifierInterface instance encapsulated by this
|
|
// Signifier object.
|
|
//
|
|
// accountID is given so as to automatically fill the AccountID field of
|
|
// Credentials returned from Sign, since the underlying implementation doesn't
|
|
// know what account it's signing for.
|
|
func (s Signifier) Interface(accountID string) (SignifierInterface, error) {
|
|
el, _, err := typeobj.Element(s)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return accountSignifier{accountID, el.(SignifierInterface)}, nil
|
|
}
|
|
|
|
// SignifierInterface describes the methods that all Signifiers must implement.
|
|
type SignifierInterface interface {
|
|
// Sign returns a Credential containing a signature of the given data.
|
|
//
|
|
// tree can be used to find the Signifier at a particular snapshot.
|
|
Sign(fs fs.FS, data []byte) (Credential, error)
|
|
|
|
// Signed returns true if the Signifier was used to sign the Credential.
|
|
Signed(fs fs.FS, cred Credential) (bool, error)
|
|
|
|
// Verify asserts that the Signifier produced the given Credential for the
|
|
// given data set, or returns an error.
|
|
//
|
|
// tree can be used to find the Signifier at a particular snapshot.
|
|
Verify(fs fs.FS, data []byte, cred Credential) error
|
|
}
|
|
|
|
// accountSignifier wraps a SignifierInterface to always set the accountID field
|
|
// on Credentials it produces via the Sign method.
|
|
//
|
|
// TODO accountSignifier shouldn't be necessary, it's very ugly. Which indicates
|
|
// that Credential probably shouldn't have AccountID on it, which makes sense.
|
|
// Some refactoring is required here.
|
|
type accountSignifier struct {
|
|
accountID string
|
|
SignifierInterface
|
|
}
|
|
|
|
func (as accountSignifier) Sign(fs fs.FS, data []byte) (Credential, error) {
|
|
cred, err := as.SignifierInterface.Sign(fs, data)
|
|
cred.AccountID = as.accountID
|
|
return cred, err
|
|
}
|