mirror of
https://github.com/zap-proto/go.git
synced 2026-10-30 15:05:00 +00:00
Track zap-spec v1.1.0's widening of the Capability.Sig footer from sig96 (96 B) to sig3408 (3408 B). SigSize is now 3408; the capabilityViewSize is 3572 (was 260) and revocationViewSize is 3448 (was 136). Field offsets are unchanged. What changed: - cap/capabilities_zap.go regenerated via `zapgen -single -type-suffix=View`. - cap/cap.go: SigSize = 3408; new AlgTagOffset = SigSize-1; new typed Scheme enum (SchemeReserved/Secp256k1/Ed25519/MLDSA65/Hybrid) matching capabilities_kinds.md "Wire schemes" table; new sentinel ErrUnhandledScheme. - cap/signer.go: Ed25519Signer.Sign writes byte(SchemeEd25519) at AlgTagOffset so verifiers can dispatch. - cap/verify.go: Verifier gains SchemeVerify hook for consumers to plug in PQ primitives (ML-DSA-65 lives in github.com/hanzoai/iam/ capauth, not here, so this package stays dep-free); falls back to ed25519 when SchemeVerify is nil or returns ErrUnhandledScheme. - cap/cap_test.go: three new tests freeze the v1.1 invariants (SigSize=3408, AlgTagOffset=SigSize-1, capabilityViewSize=3572; Ed25519Signer writes the tag byte; the tag round-trips through Issue→Bytes→Wrap→Signature()). All existing 21 tests + 3 new tests pass. The eight pre-existing cap test functions that flip signature bytes still work — they target sig[len-SigSize], which is now the leading byte of the real signature on the wire. Wire-incompatible with cap v1.0 / zap-proto/go v1.0.0-rc1. Per the "no backwards compatibility, only forwards perfection" rule, no compat layer ships.
239 lines
7.2 KiB
Go
239 lines
7.2 KiB
Go
// Code generated by zapgen; DO NOT EDIT.
|
|
// source: capabilities.zap
|
|
|
|
package cap
|
|
|
|
import (
|
|
zap "github.com/zap-proto/go"
|
|
)
|
|
|
|
const (
|
|
capabilityViewKindOff = 0
|
|
capabilityViewTargetOff = 4
|
|
capabilityViewHolderOff = 36
|
|
capabilityViewIssuerOff = 68
|
|
capabilityViewPermissionsOff = 100
|
|
capabilityViewParentOff = 108
|
|
capabilityViewIssuedAtOff = 140
|
|
capabilityViewExpiresAtOff = 148
|
|
capabilityViewCaveatsOff = 156
|
|
capabilityViewSigOff = 164
|
|
capabilityViewSize = 3572
|
|
)
|
|
|
|
// CapabilityView is a zero-copy view into a ZAP-encoded CapabilityView message.
|
|
type CapabilityView struct{ o zap.Object }
|
|
|
|
// WrapCapabilityView parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapCapabilityView(b []byte) (CapabilityView, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return CapabilityView{}, err
|
|
}
|
|
return CapabilityView{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t CapabilityView) Kind() uint32 { return t.o.Uint32(capabilityViewKindOff) }
|
|
func (t CapabilityView) Target() [32]byte {
|
|
var out [32]byte
|
|
copy(out[:], t.o.BytesFixed(capabilityViewTargetOff, 32))
|
|
return out
|
|
}
|
|
func (t CapabilityView) Holder() [32]byte {
|
|
var out [32]byte
|
|
copy(out[:], t.o.BytesFixed(capabilityViewHolderOff, 32))
|
|
return out
|
|
}
|
|
func (t CapabilityView) Issuer() [32]byte {
|
|
var out [32]byte
|
|
copy(out[:], t.o.BytesFixed(capabilityViewIssuerOff, 32))
|
|
return out
|
|
}
|
|
func (t CapabilityView) Permissions() uint64 { return t.o.Uint64(capabilityViewPermissionsOff) }
|
|
func (t CapabilityView) Parent() [32]byte {
|
|
var out [32]byte
|
|
copy(out[:], t.o.BytesFixed(capabilityViewParentOff, 32))
|
|
return out
|
|
}
|
|
func (t CapabilityView) IssuedAt() uint64 { return t.o.Uint64(capabilityViewIssuedAtOff) }
|
|
func (t CapabilityView) ExpiresAt() uint64 { return t.o.Uint64(capabilityViewExpiresAtOff) }
|
|
func (t CapabilityView) Caveats() zap.List { return t.o.List(capabilityViewCaveatsOff) }
|
|
func (t CapabilityView) Sig() [3408]byte {
|
|
var out [3408]byte
|
|
copy(out[:], t.o.BytesFixed(capabilityViewSigOff, 3408))
|
|
return out
|
|
}
|
|
|
|
// CapabilityViewInput collects the field values for NewCapabilityView.
|
|
type CapabilityViewInput struct {
|
|
Kind uint32
|
|
Target [32]byte
|
|
Holder [32]byte
|
|
Issuer [32]byte
|
|
Permissions uint64
|
|
Parent [32]byte
|
|
IssuedAt uint64
|
|
ExpiresAt uint64
|
|
Caveats [][]byte
|
|
Sig [3408]byte
|
|
}
|
|
|
|
// NewCapabilityView builds a ZAP-encoded CapabilityView message from in and returns the bytes.
|
|
func NewCapabilityView(in CapabilityViewInput) []byte {
|
|
b := zap.NewBuilder(256)
|
|
ob := b.StartObject(capabilityViewSize)
|
|
ob.SetUint32(capabilityViewKindOff, in.Kind)
|
|
ob.SetBytesFixed(capabilityViewTargetOff, in.Target[:])
|
|
ob.SetBytesFixed(capabilityViewHolderOff, in.Holder[:])
|
|
ob.SetBytesFixed(capabilityViewIssuerOff, in.Issuer[:])
|
|
ob.SetUint64(capabilityViewPermissionsOff, in.Permissions)
|
|
ob.SetBytesFixed(capabilityViewParentOff, in.Parent[:])
|
|
ob.SetUint64(capabilityViewIssuedAtOff, in.IssuedAt)
|
|
ob.SetUint64(capabilityViewExpiresAtOff, in.ExpiresAt)
|
|
caveatsLB := b.StartList(0)
|
|
for _, elem := range in.Caveats {
|
|
caveatsLB.AddObjectBytes(elem)
|
|
}
|
|
ob.SetList(capabilityViewCaveatsOff, caveatsLB.FinishOffset(), len(in.Caveats))
|
|
ob.SetBytesFixed(capabilityViewSigOff, in.Sig[:])
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|
|
|
|
const (
|
|
caveatViewKindOff = 0
|
|
caveatViewValueOff = 4
|
|
caveatViewSize = 12
|
|
)
|
|
|
|
// CaveatView is a zero-copy view into a ZAP-encoded CaveatView message.
|
|
type CaveatView struct{ o zap.Object }
|
|
|
|
// WrapCaveatView parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapCaveatView(b []byte) (CaveatView, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return CaveatView{}, err
|
|
}
|
|
return CaveatView{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t CaveatView) Kind() uint32 { return t.o.Uint32(caveatViewKindOff) }
|
|
func (t CaveatView) Value() []byte { return t.o.Bytes(caveatViewValueOff) }
|
|
|
|
// CaveatViewInput collects the field values for NewCaveatView.
|
|
type CaveatViewInput struct {
|
|
Kind uint32
|
|
Value []byte
|
|
}
|
|
|
|
// NewCaveatView builds a ZAP-encoded CaveatView message from in and returns the bytes.
|
|
func NewCaveatView(in CaveatViewInput) []byte {
|
|
b := zap.NewBuilder(256)
|
|
ob := b.StartObject(caveatViewSize)
|
|
ob.SetUint32(caveatViewKindOff, in.Kind)
|
|
ob.SetBytes(caveatViewValueOff, in.Value)
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|
|
|
|
const (
|
|
revocationViewCapIDOff = 0
|
|
revocationViewRevokedAtOff = 32
|
|
revocationViewRevokerSigOff = 40
|
|
revocationViewSize = 3448
|
|
)
|
|
|
|
// RevocationView is a zero-copy view into a ZAP-encoded RevocationView message.
|
|
type RevocationView struct{ o zap.Object }
|
|
|
|
// WrapRevocationView parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapRevocationView(b []byte) (RevocationView, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return RevocationView{}, err
|
|
}
|
|
return RevocationView{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t RevocationView) CapID() [32]byte {
|
|
var out [32]byte
|
|
copy(out[:], t.o.BytesFixed(revocationViewCapIDOff, 32))
|
|
return out
|
|
}
|
|
func (t RevocationView) RevokedAt() uint64 { return t.o.Uint64(revocationViewRevokedAtOff) }
|
|
func (t RevocationView) RevokerSig() [3408]byte {
|
|
var out [3408]byte
|
|
copy(out[:], t.o.BytesFixed(revocationViewRevokerSigOff, 3408))
|
|
return out
|
|
}
|
|
|
|
// RevocationViewInput collects the field values for NewRevocationView.
|
|
type RevocationViewInput struct {
|
|
CapID [32]byte
|
|
RevokedAt uint64
|
|
RevokerSig [3408]byte
|
|
}
|
|
|
|
// NewRevocationView builds a ZAP-encoded RevocationView message from in and returns the bytes.
|
|
func NewRevocationView(in RevocationViewInput) []byte {
|
|
b := zap.NewBuilder(256)
|
|
ob := b.StartObject(revocationViewSize)
|
|
ob.SetBytesFixed(revocationViewCapIDOff, in.CapID[:])
|
|
ob.SetUint64(revocationViewRevokedAtOff, in.RevokedAt)
|
|
ob.SetBytesFixed(revocationViewRevokerSigOff, in.RevokerSig[:])
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|
|
|
|
const (
|
|
capProofViewLeafOff = 0
|
|
capProofViewChainOff = 4
|
|
capProofViewSize = 12
|
|
)
|
|
|
|
// CapProofView is a zero-copy view into a ZAP-encoded CapProofView message.
|
|
type CapProofView struct{ o zap.Object }
|
|
|
|
// WrapCapProofView parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapCapProofView(b []byte) (CapProofView, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return CapProofView{}, err
|
|
}
|
|
return CapProofView{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t CapProofView) Leaf() CapabilityView {
|
|
return CapabilityView{o: t.o.Object(capProofViewLeafOff)}
|
|
}
|
|
func (t CapProofView) Chain() zap.List { return t.o.List(capProofViewChainOff) }
|
|
|
|
// CapProofViewInput collects the field values for NewCapProofView.
|
|
type CapProofViewInput struct {
|
|
Leaf []byte
|
|
Chain [][]byte
|
|
}
|
|
|
|
// NewCapProofView builds a ZAP-encoded CapProofView message from in and returns the bytes.
|
|
func NewCapProofView(in CapProofViewInput) []byte {
|
|
b := zap.NewBuilder(256)
|
|
ob := b.StartObject(capProofViewSize)
|
|
if len(in.Leaf) > 0 {
|
|
nested := b.StartObject(len(in.Leaf))
|
|
nested.SetBytesFixed(0, in.Leaf)
|
|
ob.SetObject(capProofViewLeafOff, nested.Finish())
|
|
}
|
|
chainLB := b.StartList(0)
|
|
for _, elem := range in.Chain {
|
|
chainLB.AddObjectBytes(elem)
|
|
}
|
|
ob.SetList(capProofViewChainOff, chainLB.FinishOffset(), len(in.Chain))
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|