trust

package
v0.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package trust provides integrity verification, signature handling, and trust policy enforcement for forge skills.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeChecksum

func ComputeChecksum(content []byte) string

ComputeChecksum returns the SHA-256 checksum of content as "sha256:<hex>".

func GenerateKeyPair

func GenerateKeyPair() (ed25519.PublicKey, ed25519.PrivateKey, error)

GenerateKeyPair creates a new Ed25519 key pair.

func MarshalManifest

func MarshalManifest(m *Manifest) ([]byte, error)

MarshalManifest serializes a manifest to JSON.

func Sign

func Sign(content []byte, privateKey ed25519.PrivateKey) []byte

Sign produces an Ed25519 signature of content.

func SignSkill

func SignSkill(skillContent []byte, privateKey ed25519.PrivateKey) ([]byte, error)

SignSkill produces a detached signature for skill content.

func Verify

func Verify(content []byte, signature []byte, publicKey ed25519.PublicKey) bool

Verify checks an Ed25519 signature of content.

func VerifyChecksum

func VerifyChecksum(content []byte, expected string) bool

VerifyChecksum checks whether content matches the expected checksum string.

func VerifySkill

func VerifySkill(skillContent, signature []byte, publicKey ed25519.PublicKey) bool

VerifySkill checks a detached signature for skill content.

Types

type IntegrityViolation

type IntegrityViolation struct {
	SkillName string `json:"skill_name"`
	Expected  string `json:"expected"`
	Actual    string `json:"actual"`
	Reason    string `json:"reason"` // "mismatch", "missing_in_manifest", "missing_in_registry"
}

IntegrityViolation describes a checksum mismatch or missing entry.

func VerifyManifest

func VerifyManifest(registry contract.SkillRegistry, manifest *Manifest) []IntegrityViolation

VerifyManifest checks all skills in the registry against the manifest. It returns a list of violations (empty if everything matches).

type Keyring

type Keyring struct {
	// contains filtered or unexported fields
}

Keyring manages a set of trusted Ed25519 public keys.

func DefaultKeyring

func DefaultKeyring() *Keyring

DefaultKeyring loads trusted keys from ~/.forge/trusted-keys/.

func NewKeyring

func NewKeyring() *Keyring

NewKeyring creates an empty keyring.

func (*Keyring) Add

func (k *Keyring) Add(keyID string, pubKey ed25519.PublicKey)

Add registers a public key with the given ID.

func (*Keyring) Get

func (k *Keyring) Get(keyID string) ed25519.PublicKey

Get returns the public key for the given ID, or nil if not found.

func (*Keyring) List

func (k *Keyring) List() []string

List returns all key IDs in the keyring.

func (*Keyring) LoadFromDir

func (k *Keyring) LoadFromDir(dir string) error

LoadFromDir reads all *.pub files from a directory and adds them to the keyring. Each file should contain a base64-encoded Ed25519 public key. The key ID is derived from the filename (without .pub extension).

func (*Keyring) Verify

func (k *Keyring) Verify(content, signature []byte) (keyID string, ok bool)

Verify tries all keys in the keyring against the content and signature. Returns the matching key ID and true if verified, or empty string and false.

type Manifest

type Manifest struct {
	Version   string            `json:"version"`
	Checksums map[string]string `json:"checksums"` // skill name -> "sha256:<hex>"
}

Manifest stores checksums for all skills in a registry.

func GenerateManifest

func GenerateManifest(registry contract.SkillRegistry) (*Manifest, error)

GenerateManifest creates a Manifest from all skills in the registry.

func UnmarshalManifest

func UnmarshalManifest(data []byte) (*Manifest, error)

UnmarshalManifest deserializes a manifest from JSON.

type TrustPolicy

type TrustPolicy struct {
	MinTrustLevel    contract.TrustLevel `yaml:"min_trust_level" json:"min_trust_level"`
	RequireChecksum  bool                `yaml:"require_checksum" json:"require_checksum"`
	RequireSignature bool                `yaml:"require_signature" json:"require_signature"`
}

TrustPolicy defines minimum trust requirements for skill loading.

func DefaultTrustPolicy

func DefaultTrustPolicy() TrustPolicy

DefaultTrustPolicy returns a policy that accepts local skills without signatures.

func (TrustPolicy) Accepts

func (p TrustPolicy) Accepts(level contract.TrustLevel) bool

Accepts reports whether the given trust level satisfies the policy.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL