Skip to content

Commit 11edfab

Browse files
authored
fix unmarshalling sth (sigstore#409)
Signed-off-by: Asra Ali <asraa@google.com>
1 parent ce09d54 commit 11edfab

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

pkg/util/checkpoint.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (c Checkpoint) String() string {
4949
}
5050

5151
// MarshalText returns the common format representation of this Checkpoint.
52-
func (c Checkpoint) MarshalText() ([]byte, error) {
52+
func (c Checkpoint) MarshalCheckpoint() ([]byte, error) {
5353
return []byte(c.String()), nil
5454
}
5555

@@ -65,7 +65,7 @@ func (c Checkpoint) MarshalText() ([]byte, error) {
6565
// <optional non-empty line of other content>...
6666
//
6767
// This will discard any content found after the checkpoint (including signatures)
68-
func (c *Checkpoint) UnmarshalText(data []byte) error {
68+
func (c *Checkpoint) UnmarshalCheckpoint(data []byte) error {
6969
l := bytes.Split(data, []byte("\n"))
7070
if len(l) < 4 {
7171
return errors.New("invalid checkpoint - too few newlines")
@@ -104,7 +104,7 @@ type SignedCheckpoint struct {
104104
}
105105

106106
func CreateSignedCheckpoint(c Checkpoint) (*SignedCheckpoint, error) {
107-
text, err := c.MarshalText()
107+
text, err := c.MarshalCheckpoint()
108108
if err != nil {
109109
return nil, err
110110
}
@@ -120,12 +120,12 @@ func SignedCheckpointValidator(strToValidate string) bool {
120120
return false
121121
}
122122
c := &Checkpoint{}
123-
return c.UnmarshalText([]byte(s.Note)) == nil
123+
return c.UnmarshalCheckpoint([]byte(s.Note)) == nil
124124
}
125125

126126
func CheckpointValidator(strToValidate string) bool {
127127
c := &Checkpoint{}
128-
return c.UnmarshalText([]byte(strToValidate)) == nil
128+
return c.UnmarshalCheckpoint([]byte(strToValidate)) == nil
129129
}
130130

131131
func (r *SignedCheckpoint) UnmarshalText(data []byte) error {
@@ -134,7 +134,7 @@ func (r *SignedCheckpoint) UnmarshalText(data []byte) error {
134134
return errors.Wrap(err, "unmarshalling signed note")
135135
}
136136
c := Checkpoint{}
137-
if err := c.UnmarshalText([]byte(s.Note)); err != nil {
137+
if err := c.UnmarshalCheckpoint([]byte(s.Note)); err != nil {
138138
return errors.Wrap(err, "unmarshalling checkpoint")
139139
}
140140
*r = SignedCheckpoint{Checkpoint: c, SignedNote: s}

pkg/util/checkpoint_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestMarshalCheckpoint(t *testing.T) {
6262
},
6363
} {
6464
t.Run(string(test.c.Hash), func(t *testing.T) {
65-
got, err := test.c.MarshalText()
65+
got, err := test.c.MarshalCheckpoint()
6666
if err != nil {
6767
t.Fatalf("unexpected error marshalling: %v", err)
6868
}
@@ -155,7 +155,7 @@ func TestUnmarshalCheckpoint(t *testing.T) {
155155
t.Run(string(test.desc), func(t *testing.T) {
156156
var got Checkpoint
157157
var gotErr error
158-
if gotErr = got.UnmarshalText([]byte(test.m)); (gotErr != nil) != test.wantErr {
158+
if gotErr = got.UnmarshalCheckpoint([]byte(test.m)); (gotErr != nil) != test.wantErr {
159159
t.Fatalf("Unmarshal = %q, wantErr: %T", gotErr, test.wantErr)
160160
}
161161
if diff := cmp.Diff(test.want, got); len(diff) != 0 {
@@ -274,7 +274,7 @@ func TestSigningRoundtripCheckpoint(t *testing.T) {
274274
},
275275
} {
276276
t.Run(string(test.c.Ecosystem), func(t *testing.T) {
277-
text, _ := test.c.MarshalText()
277+
text, _ := test.c.MarshalCheckpoint()
278278
sc := &SignedNote{
279279
Note: string(text),
280280
}
@@ -307,7 +307,7 @@ func TestSigningRoundtripCheckpoint(t *testing.T) {
307307
if err != nil {
308308
t.Fatalf("error during marshalling: %v", err)
309309
}
310-
text, _ = test.c.MarshalText()
310+
text, _ = test.c.MarshalCheckpoint()
311311
sc2 := &SignedNote{
312312
Note: string(text),
313313
}
@@ -375,7 +375,7 @@ func TestInvalidSigVerification(t *testing.T) {
375375
},
376376
} {
377377
t.Run(string(test.checkpoint.Ecosystem), func(t *testing.T) {
378-
text, _ := test.checkpoint.MarshalText()
378+
text, _ := test.checkpoint.MarshalCheckpoint()
379379
sc := SignedNote{
380380
Note: string(text),
381381
Signatures: test.s,

0 commit comments

Comments
 (0)