container: Reader should keep around and expose the sealed bytes

This commit is contained in:
Michael Muré
2025-01-23 17:12:26 +01:00
parent e218b49577
commit 9d047f038d
6 changed files with 83 additions and 29 deletions

View File

@@ -217,6 +217,7 @@ func (g *generator) writeGoFile() error {
Println("import (")
Println("\t\"github.com/ipfs/go-cid\"")
Println()
Println("\t\"github.com/ucan-wg/go-ucan/token\"")
Println("\t\"github.com/ucan-wg/go-ucan/token/delegation\"")
Println(")")
@@ -242,7 +243,7 @@ func (g *generator) writeGoFile() error {
Println("}")
Println()
Println("var AllBundles = []*delegation.Bundle{")
Println("var AllBundles = []token.Bundle[*delegation.Token]{")
for _, d := range g.dlgs {
Printf("\t%sBundle,\n", d.name)
}

View File

@@ -8,6 +8,7 @@ import (
"github.com/ipfs/go-cid"
"github.com/ucan-wg/go-ucan/pkg/command"
"github.com/ucan-wg/go-ucan/token"
"github.com/ucan-wg/go-ucan/token/delegation"
)
@@ -38,7 +39,7 @@ var fs embed.FS
var _ delegation.Loader = (*DelegationLoader)(nil)
type DelegationLoader struct {
bundles map[cid.Cid]*delegation.Bundle
bundles map[cid.Cid]token.Bundle[*delegation.Token]
}
var (
@@ -75,7 +76,7 @@ func loadDelegations() (*DelegationLoader, error) {
return nil, err
}
bundles := make(map[cid.Cid]*delegation.Bundle, len(dirEntries))
bundles := make(map[cid.Cid]token.Bundle[*delegation.Token], len(dirEntries))
for _, dirEntry := range dirEntries {
data, err := fs.ReadFile(filepath.Join(TokenDir, dirEntry.Name()))
@@ -88,7 +89,7 @@ func loadDelegations() (*DelegationLoader, error) {
return nil, err
}
bundles[id] = &delegation.Bundle{Cid: id, Decoded: tkn, Sealed: data}
bundles[id] = token.Bundle[*delegation.Token]{Cid: id, Decoded: tkn, Sealed: data}
}
return &DelegationLoader{
@@ -106,7 +107,7 @@ func CidToName(id cid.Cid) string {
return cidToName[id]
}
func mustGetBundle(id cid.Cid) *delegation.Bundle {
func mustGetBundle(id cid.Cid) token.Bundle[*delegation.Token] {
bundle, ok := GetDelegationLoader().bundles[id]
if !ok {
panic(delegation.ErrDelegationNotFound)

View File

@@ -5,6 +5,7 @@ package delegationtest
import (
"github.com/ipfs/go-cid"
"github.com/ucan-wg/go-ucan/token"
"github.com/ucan-wg/go-ucan/token/delegation"
)
@@ -195,7 +196,7 @@ var AllTokens = []*delegation.Token{
TokenErinFrank_ValidExamplePolicy,
}
var AllBundles = []*delegation.Bundle{
var AllBundles = []token.Bundle[*delegation.Token]{
TokenAliceBobBundle,
TokenBobCarolBundle,
TokenCarolDanBundle,