Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename ProtobufBundle to Bundle #251

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/conformance/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func main() {
log.Fatal(err)
}

bun, err := bundle.NewProtobufBundle(&pb)
bun, err := bundle.NewBundle(&pb)
if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion docs/verification.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ The verifier allows you to use the Sigstore Public Good TUF root or your own cus

This library includes a few abstractions to support different use cases, testing, and extensibility:

- `SignedEntity` - an interface type respresenting a signed message or attestation, with a signature and metadata, implemented by `ProtobufBundle`, a type which wraps the `Bundle` type from `protobuf-specs`.
- `SignedEntity` - an interface type respresenting a signed message or attestation, with a signature and metadata, implemented by `Bundle`, a type which wraps the `Bundle` type from `protobuf-specs`.
- `TrustedMaterial` - an interface type representing a trusted set of keys or certificates for verifying certificates, timestamps, and artifact transparency logs, implemented by `TrustedRoot`

## Verifier
Expand Down
8 changes: 4 additions & 4 deletions examples/oci-image-verification/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func main() {
}

func run() error {
var b *bundle.ProtobufBundle
var b *bundle.Bundle
var err error

if *ociImage != "" {
Expand Down Expand Up @@ -246,8 +246,8 @@ func trustedPublicKeyMaterial(pk crypto.PublicKey) *root.TrustedPublicKeyMateria
})
}

// bundleFromOCIImage returns a ProtobufBundle based on OCI image reference.
func bundleFromOCIImage(imageRef string) (*bundle.ProtobufBundle, *string, error) {
// bundleFromOCIImage returns a Bundle based on OCI image reference.
func bundleFromOCIImage(imageRef string) (*bundle.Bundle, *string, error) {
// 1. Get the simple signing layer
simpleSigning, err := simpleSigningLayerFromOCIImage(imageRef)
if err != nil {
Expand All @@ -273,7 +273,7 @@ func bundleFromOCIImage(imageRef string) (*bundle.ProtobufBundle, *string, error
VerificationMaterial: verificationMaterial,
Content: msgSignature,
}
bun, err := bundle.NewProtobufBundle(&pb)
bun, err := bundle.NewBundle(&pb)
if err != nil {
return nil, nil, fmt.Errorf("error creating bundle: %w", err)
}
Expand Down
32 changes: 16 additions & 16 deletions pkg/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ func ErrValidationError(err error) error {
return fmt.Errorf("%w: %w", ErrValidation, err)
}

type ProtobufBundle struct {
type Bundle struct {
*protobundle.Bundle
hasInclusionPromise bool
hasInclusionProof bool
}

func NewProtobufBundle(pbundle *protobundle.Bundle) (*ProtobufBundle, error) {
bundle := &ProtobufBundle{
func NewBundle(pbundle *protobundle.Bundle) (*Bundle, error) {
bundle := &Bundle{
Bundle: pbundle,
hasInclusionPromise: false,
hasInclusionProof: false,
Expand All @@ -69,7 +69,7 @@ func NewProtobufBundle(pbundle *protobundle.Bundle) (*ProtobufBundle, error) {
return bundle, nil
}

func (b *ProtobufBundle) validate() error {
func (b *Bundle) validate() error {
bundleVersion, err := getBundleVersion(b.Bundle.MediaType)
if err != nil {
return fmt.Errorf("error getting bundle version: %w", err)
Expand Down Expand Up @@ -194,8 +194,8 @@ func validateBundle(b *protobundle.Bundle) error {
return nil
}

func LoadJSONFromPath(path string) (*ProtobufBundle, error) {
var bundle ProtobufBundle
func LoadJSONFromPath(path string) (*Bundle, error) {
var bundle Bundle
bundle.Bundle = new(protobundle.Bundle)

contents, err := os.ReadFile(path)
Expand All @@ -211,11 +211,11 @@ func LoadJSONFromPath(path string) (*ProtobufBundle, error) {
return &bundle, nil
}

func (b *ProtobufBundle) MarshalJSON() ([]byte, error) {
func (b *Bundle) MarshalJSON() ([]byte, error) {
return protojson.Marshal(b.Bundle)
}

func (b *ProtobufBundle) UnmarshalJSON(data []byte) error {
func (b *Bundle) UnmarshalJSON(data []byte) error {
b.Bundle = new(protobundle.Bundle)
err := protojson.Unmarshal(data, b.Bundle)
if err != nil {
Expand All @@ -230,7 +230,7 @@ func (b *ProtobufBundle) UnmarshalJSON(data []byte) error {
return nil
}

func (b *ProtobufBundle) VerificationContent() (verify.VerificationContent, error) {
func (b *Bundle) VerificationContent() (verify.VerificationContent, error) {
if b.VerificationMaterial == nil {
return nil, ErrMissingVerificationMaterial
}
Expand Down Expand Up @@ -269,15 +269,15 @@ func (b *ProtobufBundle) VerificationContent() (verify.VerificationContent, erro
}
}

func (b *ProtobufBundle) HasInclusionPromise() bool {
func (b *Bundle) HasInclusionPromise() bool {
return b.hasInclusionPromise
}

func (b *ProtobufBundle) HasInclusionProof() bool {
func (b *Bundle) HasInclusionProof() bool {
return b.hasInclusionProof
}

func (b *ProtobufBundle) TlogEntries() ([]*tlog.Entry, error) {
func (b *Bundle) TlogEntries() ([]*tlog.Entry, error) {
if b.VerificationMaterial == nil {
return nil, nil
}
Expand All @@ -301,7 +301,7 @@ func (b *ProtobufBundle) TlogEntries() ([]*tlog.Entry, error) {
return tlogEntries, nil
}

func (b *ProtobufBundle) SignatureContent() (verify.SignatureContent, error) {
func (b *Bundle) SignatureContent() (verify.SignatureContent, error) {
switch content := b.Bundle.Content.(type) { //nolint:gocritic
case *protobundle.Bundle_DsseEnvelope:
envelope, err := parseEnvelope(content.DsseEnvelope)
Expand All @@ -319,7 +319,7 @@ func (b *ProtobufBundle) SignatureContent() (verify.SignatureContent, error) {
return nil, ErrMissingVerificationMaterial
}

func (b *ProtobufBundle) Envelope() (*Envelope, error) {
func (b *Bundle) Envelope() (*Envelope, error) {
switch content := b.Bundle.Content.(type) { //nolint:gocritic
case *protobundle.Bundle_DsseEnvelope:
envelope, err := parseEnvelope(content.DsseEnvelope)
Expand All @@ -331,7 +331,7 @@ func (b *ProtobufBundle) Envelope() (*Envelope, error) {
return nil, ErrMissingVerificationMaterial
}

func (b *ProtobufBundle) Timestamps() ([][]byte, error) {
func (b *Bundle) Timestamps() ([][]byte, error) {
if b.VerificationMaterial == nil {
return nil, ErrMissingVerificationMaterial
}
Expand All @@ -350,7 +350,7 @@ func (b *ProtobufBundle) Timestamps() ([][]byte, error) {
}

// MinVersion returns true if the bundle version is greater than or equal to the expected version.
func (b *ProtobufBundle) MinVersion(expectVersion string) bool {
func (b *Bundle) MinVersion(expectVersion string) bool {
version, err := getBundleVersion(b.Bundle.MediaType)
if err != nil {
return false
Expand Down
Loading
Loading