Debian Codegraph @

signature/internal/rekor_api_types.go

raw
1 package internal
2
3 import (
4 "bytes"
5 "encoding/json"
6 "fmt"
7 )
8
9 const rekorHashedrekordKind = "hashedrekord"
10
11 type RekorHashedrekord struct {
12 APIVersion *string `json:"apiVersion"`
13 Spec json.RawMessage `json:"spec"`
14 }
15
16 func (m *RekorHashedrekord) Kind() string {
17 return rekorHashedrekordKind
18 }
19
20 func (m *RekorHashedrekord) SetKind(val string) {
21 }
22
23 func (m *RekorHashedrekord) UnmarshalJSON(raw []byte) error {
24 var base struct {
25 Kind string `json:"kind"`
26 }
27 dec := json.NewDecoder(bytes.NewReader(raw))
28 dec.UseNumber()
29 if err := dec.Decode(&base); err != nil {
30 return err
31 }
32
33 switch base.Kind {
34 case rekorHashedrekordKind:
35 var data struct { // We can’t use RekorHashedRekord directly, because that would be an infinite recursion.
36 APIVersion *string `json:"apiVersion"`
37 Spec json.RawMessage `json:"spec"`
38 }
39 dec = json.NewDecoder(bytes.NewReader(raw))
40 dec.UseNumber()
41 if err := dec.Decode(&data); err != nil {
42 return err
43 }
44 res := RekorHashedrekord{
45 APIVersion: data.APIVersion,
46 Spec: data.Spec,
47 }
48 *m = res
49 return nil
50
51 default:
52 return fmt.Errorf("invalid kind value: %q", base.Kind)
53 }
54 }
55
56 func (m RekorHashedrekord) MarshalJSON() ([]byte, error) {
57 return json.Marshal(struct {
58 Kind string `json:"kind"`
59 APIVersion *string `json:"apiVersion"`
60 Spec json.RawMessage `json:"spec"`
61 }{
62 Kind: m.Kind(),
63 APIVersion: m.APIVersion,
64 Spec: m.Spec,
65 })
66 }
67
68 type RekorHashedrekordV001Schema struct {
69 Data *RekorHashedrekordV001SchemaData `json:"data"`
70 Signature *RekorHashedrekordV001SchemaSignature `json:"signature"`
71 }
72
73 type RekorHashedrekordV001SchemaData struct {
74 Hash *RekorHashedrekordV001SchemaDataHash `json:"hash,omitempty"`
75 }
76
77 type RekorHashedrekordV001SchemaDataHash struct {
78 Algorithm *string `json:"algorithm"`
79 Value *string `json:"value"`
80 }
81
82 const (
83 RekorHashedrekordV001SchemaDataHashAlgorithmSha256 string = "sha256"
84 RekorHashedrekordV001SchemaDataHashAlgorithmSha384 string = "sha384"
85 RekorHashedrekordV001SchemaDataHashAlgorithmSha512 string = "sha512"
86 )
87
88 type RekorHashedrekordV001SchemaSignature struct {
89 Content []byte `json:"content,omitempty"`
90 PublicKey *RekorHashedrekordV001SchemaSignaturePublicKey `json:"publicKey,omitempty"`
91 }
92
93 type RekorHashedrekordV001SchemaSignaturePublicKey struct {
94 Content []byte `json:"content,omitempty"`
95 }