Debian Codegraph @

internal/third_party/go-securesystemslib/dsse/envelope.go

raw symbols SCIP
1 package dssescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/
2
3 import (
4 "encoding/base64scip-go gomod github.com/golang/go/src go1.26.0 `encoding/base64`/"
5 "fmtscip-go gomod github.com/golang/go/src go1.26.0 fmt/"
6
7 "google.golang.org/protobuf/types/known/structpbscip-go gomod google.golang.org/protobuf f2248ac996af `google.golang.org/protobuf/types/known/structpb`/"
8 )
9
10 /*
11 Envelope captures an envelope as described by the DSSE specification. See here:
12 https://github.com/secure-systems-lab/dsse/blob/master/envelope.md
13 */
14 type Envelopescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/Envelope# struct {
15 PayloadTypescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/Envelope#PayloadType. string `json:"payloadType"`
16 Payloadscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/Envelope#Payload. string `json:"payload"`
17 Signaturesscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/Envelope#Signatures. []Signaturescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/Signature# `json:"signatures"`
18 }
19
20 /*
21 DecodeB64Payload returns the serialized body, decoded from the envelope's
22 payload field. A flexible decoder is used, first trying standard base64, then
23 URL-encoded base64.
24 */
25 func (e *Envelopescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/Envelope#) DecodeB64Payloadscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/Envelope#DecodeB64Payload().() ([]byte, error) {
26 return b64Decodescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/b64Decode().(e.Payloadscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/Envelope#Payload.)
27 }
28
29 /*
30 Signature represents a generic in-toto signature that contains the identifier
31 of the key which was used to create the signature.
32 The used signature scheme has to be agreed upon by the signer and verifer
33 out of band.
34 The signature is a base64 encoding of the raw bytes from the signature
35 algorithm.
36 */
37 type Signaturescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/Signature# struct {
38 KeyIDscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/Signature#KeyID. string `json:"keyid"`
39 Sigscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/Signature#Sig. string `json:"sig"`
40 Extensionscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/Signature#Extension. *Extensionscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/Extension# `json:"extension,omitempty"`
41 }
42
43 type Extensionscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/Extension# struct {
44 Kindscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/Extension#Kind. string `json:"kind"`
45 Extscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/Extension#Ext. *structpbscip-go gomod google.golang.org/protobuf f2248ac996af `google.golang.org/protobuf/types/known/structpb`/.Structscip-go gomod google.golang.org/protobuf f2248ac996af `google.golang.org/protobuf/types/known/structpb`/Struct# `json:"ext"`
46 }
47
48 /*
49 PAE implementes the DSSE Pre-Authentic Encoding
50 https://github.com/secure-systems-lab/dsse/blob/master/protocol.md#signature-definition
51 */
52 func PAEscip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/PAE().(payloadType string, payload []byte) []byte {
53 return []byte(fmtscip-go gomod github.com/golang/go/src go1.26.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.26.0 fmt/Sprintf().("DSSEv1 %d %s %d %s",
54 len(payloadType), payloadType,
55 len(payload), payload))
56 }
57
58 /*
59 Both standard and url encoding are allowed:
60 https://github.com/secure-systems-lab/dsse/blob/master/envelope.md
61 */
62 func b64Decodescip-go gomod github.com/gittuf/gittuf . `github.com/gittuf/gittuf/internal/third_party/go-securesystemslib/dsse`/b64Decode().(s string) ([]byte, error) {
63 b, err := base64scip-go gomod github.com/golang/go/src go1.26.0 `encoding/base64`/.StdEncodingscip-go gomod github.com/golang/go/src go1.26.0 `encoding/base64`/StdEncoding..DecodeStringscip-go gomod github.com/golang/go/src go1.26.0 `encoding/base64`/Encoding#DecodeString().(s)
64 if err != nil {
65 b, err = base64scip-go gomod github.com/golang/go/src go1.26.0 `encoding/base64`/.URLEncodingscip-go gomod github.com/golang/go/src go1.26.0 `encoding/base64`/URLEncoding..DecodeStringscip-go gomod github.com/golang/go/src go1.26.0 `encoding/base64`/Encoding#DecodeString().(s)
66 if err != nil {
67 return nil, fmtscip-go gomod github.com/golang/go/src go1.26.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.26.0 fmt/Errorf().("unable to base64 decode payload (is payload in the right format?)")
68 }
69 }
70
71 return b, nil
72 }