Blame SOURCES/skopeo-go142.patch

2aec97
diff --git a/signature/json.go b/signature/json.go
2aec97
index a612db0..48f3a5c 100644
2aec97
--- a/signature/json.go
2aec97
+++ b/signature/json.go
2aec97
@@ -1,10 +1,8 @@
2aec97
 package signature
2aec97
 
2aec97
 import (
2aec97
-	"bytes"
2aec97
 	"encoding/json"
2aec97
 	"fmt"
2aec97
-	"io"
2aec97
 )
2aec97
 
2aec97
 // jsonFormatError is returned when JSON does not match expected format.
2aec97
@@ -64,28 +62,14 @@ func stringField(m map[string]interface{}, fieldName string) (string, error) {
2aec97
 func paranoidUnmarshalJSONObject(data []byte, fieldResolver func(string) interface{}) error {
2aec97
 	seenKeys := map[string]struct{}{}
2aec97
 
2aec97
-	dec := json.NewDecoder(bytes.NewReader(data))
2aec97
-	t, err := dec.Token()
2aec97
-	if err != nil {
2aec97
+	// NOTE: This is a go 1.4 implementation, very much non-paranoid! The json.Unmarshal below
2aec97
+	// already throws out duplicate keys.
2aec97
+	var obj map[string]json.RawMessage
2aec97
+	if err := json.Unmarshal(data, &obj); err != nil {
2aec97
 		return jsonFormatError(err.Error())
2aec97
 	}
2aec97
-	if t != json.Delim('{') {
2aec97
-		return jsonFormatError(fmt.Sprintf("JSON object expected, got \"%s\"", t))
2aec97
-	}
2aec97
-	for {
2aec97
-		t, err := dec.Token()
2aec97
-		if err != nil {
2aec97
-			return jsonFormatError(err.Error())
2aec97
-		}
2aec97
-		if t == json.Delim('}') {
2aec97
-			break
2aec97
-		}
2aec97
 
2aec97
-		key, ok := t.(string)
2aec97
-		if !ok {
2aec97
-			// Coverage: This should never happen, dec.Token() rejects non-string-literals in this state.
2aec97
-			return jsonFormatError(fmt.Sprintf("Key string literal expected, got \"%s\"", t))
2aec97
-		}
2aec97
+	for key, valueJSON := range obj {
2aec97
 		if _, ok := seenKeys[key]; ok {
2aec97
 			return jsonFormatError(fmt.Sprintf("Duplicate key \"%s\"", key))
2aec97
 		}
2aec97
@@ -95,13 +79,9 @@ func paranoidUnmarshalJSONObject(data []byte, fieldResolver func(string) interfa
2aec97
 		if valuePtr == nil {
2aec97
 			return jsonFormatError(fmt.Sprintf("Unknown key \"%s\"", key))
2aec97
 		}
2aec97
-		// This works like json.Unmarshal, in particular it allows us to implement UnmarshalJSON to implement strict parsing of the field value.
2aec97
-		if err := dec.Decode(valuePtr); err != nil {
2aec97
+		if err := json.Unmarshal(valueJSON, valuePtr); err != nil {
2aec97
 			return jsonFormatError(err.Error())
2aec97
 		}
2aec97
 	}
2aec97
-	if _, err := dec.Token(); err != io.EOF {
2aec97
-		return jsonFormatError("Unexpected data after JSON object")
2aec97
-	}
2aec97
 	return nil
2aec97
 }
2aec97
diff --git a/signature/json_test.go b/signature/json_test.go
2aec97
index 8d0f63c..80719e0 100644
2aec97
--- a/signature/json_test.go
2aec97
+++ b/signature/json_test.go
2aec97
@@ -131,12 +131,12 @@ func TestParanoidUnmarshalJSONObject(t *testing.T) {
2aec97
 
2aec97
 	// Various kinds of invalid input
2aec97
 	for _, input := range []string{
2aec97
-		``,                       // Empty input
2aec97
-		`&`,                      // Entirely invalid JSON
2aec97
-		`1`,                      // Not an object
2aec97
-		`{&}`,                    // Invalid key JSON
2aec97
-		`{1:1}`,                  // Key not a string
2aec97
-		`{"b":1, "b":1}`,         // Duplicate key
2aec97
+		``,      // Empty input
2aec97
+		`&`,     // Entirely invalid JSON
2aec97
+		`1`,     // Not an object
2aec97
+		`{&}`,   // Invalid key JSON
2aec97
+		`{1:1}`, // Key not a string
2aec97
+		//		`{"b":1, "b":1}`,         // Duplicate key
2aec97
 		`{"thisdoesnotexist":1}`, // Key rejected by resolver
2aec97
 		`{"a":&}`,                // Invalid value JSON
2aec97
 		`{"a":1}`,                // Type mismatch
2aec97
@@ -144,6 +144,6 @@ func TestParanoidUnmarshalJSONObject(t *testing.T) {
2aec97
 	} {
2aec97
 		ts = testStruct{}
2aec97
 		err := paranoidUnmarshalJSONObject([]byte(input), tsResolver)
2aec97
-		assert.Error(t, err)
2aec97
+		assert.Error(t, err, input)
2aec97
 	}
2aec97
 }
2aec97
diff --git a/signature/policy_config_test.go b/signature/policy_config_test.go
2aec97
index 63fd8c7..579aa5f 100644
2aec97
--- a/signature/policy_config_test.go
2aec97
+++ b/signature/policy_config_test.go
2aec97
@@ -203,7 +203,7 @@ func TestPolicyUnmarshalJSON(t *testing.T) {
2aec97
 	}
2aec97
 
2aec97
 	// Duplicated fields
2aec97
-	for _, field := range []string{"default", "specific"} {
2aec97
+	for _, field := range []string{ /*"default", "specific"*/ } {
2aec97
 		var tmp mSI
2aec97
 		err := json.Unmarshal(validJSON, &tmp)
2aec97
 		require.NoError(t, err)
2aec97
@@ -367,7 +367,7 @@ func TestPRInsecureAcceptAnythingUnmarshalJSON(t *testing.T) {
2aec97
 	}
2aec97
 
2aec97
 	// Duplicated fields
2aec97
-	for _, field := range []string{"type"} {
2aec97
+	for _, field := range []string{ /*"type"*/ } {
2aec97
 		var tmp mSI
2aec97
 		err := json.Unmarshal(validJSON, &tmp)
2aec97
 		require.NoError(t, err)
2aec97
@@ -438,7 +438,7 @@ func TestPRRejectUnmarshalJSON(t *testing.T) {
2aec97
 	}
2aec97
 
2aec97
 	// Duplicated fields
2aec97
-	for _, field := range []string{"type"} {
2aec97
+	for _, field := range []string{ /*"type"*/ } {
2aec97
 		var tmp mSI
2aec97
 		err := json.Unmarshal(validJSON, &tmp)
2aec97
 		require.NoError(t, err)
2aec97
@@ -601,7 +601,7 @@ func TestPRSignedByUnmarshalJSON(t *testing.T) {
2aec97
 	}
2aec97
 
2aec97
 	// Duplicated fields
2aec97
-	for _, field := range []string{"type", "keyType", "keyData", "signedIdentity"} {
2aec97
+	for _, field := range []string{ /*"type", "keyType", "keyData", "signedIdentity"*/ } {
2aec97
 		var tmp mSI
2aec97
 		err := json.Unmarshal(validJSON, &tmp)
2aec97
 		require.NoError(t, err)
2aec97
@@ -613,14 +613,14 @@ func TestPRSignedByUnmarshalJSON(t *testing.T) {
2aec97
 		assert.Error(t, err)
2aec97
 	}
2aec97
 	// Handle "keyPath", which is not in validJSON, specially
2aec97
-	pathPR, err := NewPRSignedByKeyPath(SBKeyTypeGPGKeys, "/foo/bar", NewPRMMatchExact())
2aec97
-	require.NoError(t, err)
2aec97
-	testJSON, err = json.Marshal(pathPR)
2aec97
-	require.NoError(t, err)
2aec97
-	testJSON = addExtraJSONMember(t, testJSON, "keyPath", pr.KeyPath)
2aec97
-	pr = prSignedBy{}
2aec97
-	err = json.Unmarshal(testJSON, &pr)
2aec97
-	assert.Error(t, err)
2aec97
+	// pathPR, err := NewPRSignedByKeyPath(SBKeyTypeGPGKeys, "/foo/bar", NewPRMMatchExact())
2aec97
+	// require.NoError(t, err)
2aec97
+	// testJSON, err = json.Marshal(pathPR)
2aec97
+	// require.NoError(t, err)
2aec97
+	// testJSON = addExtraJSONMember(t, testJSON, "keyPath", pr.KeyPath)
2aec97
+	// pr = prSignedBy{}
2aec97
+	// err = json.Unmarshal(testJSON, &pr)
2aec97
+	// assert.Error(t, err)
2aec97
 
2aec97
 	// Various allowed modifications to the requirement
2aec97
 	allowedModificationFns := []func(mSI){
2aec97
@@ -779,7 +779,7 @@ func TestPRSignedBaseLayerUnmarshalJSON(t *testing.T) {
2aec97
 	}
2aec97
 
2aec97
 	// Duplicated fields
2aec97
-	for _, field := range []string{"type", "baseLayerIdentity"} {
2aec97
+	for _, field := range []string{ /*"type", "baseLayerIdentity"*/ } {
2aec97
 		var tmp mSI
2aec97
 		err := json.Unmarshal(validJSON, &tmp)
2aec97
 		require.NoError(t, err)
2aec97
@@ -881,7 +881,7 @@ func TestPRMMatchExactUnmarshalJSON(t *testing.T) {
2aec97
 	}
2aec97
 
2aec97
 	// Duplicated fields
2aec97
-	for _, field := range []string{"type"} {
2aec97
+	for _, field := range []string{ /*"type"*/ } {
2aec97
 		var tmp mSI
2aec97
 		err := json.Unmarshal(validJSON, &tmp)
2aec97
 		require.NoError(t, err)
2aec97
@@ -952,7 +952,7 @@ func TestPRMMatchRepositoryUnmarshalJSON(t *testing.T) {
2aec97
 	}
2aec97
 
2aec97
 	// Duplicated fields
2aec97
-	for _, field := range []string{"type"} {
2aec97
+	for _, field := range []string{ /*"type"*/ } {
2aec97
 		var tmp mSI
2aec97
 		err := json.Unmarshal(validJSON, &tmp)
2aec97
 		require.NoError(t, err)
2aec97
@@ -1059,7 +1059,7 @@ func TestPRMExactReferenceUnmarshalJSON(t *testing.T) {
2aec97
 	}
2aec97
 
2aec97
 	// Duplicated fields
2aec97
-	for _, field := range []string{"type", "baseLayerIdentity"} {
2aec97
+	for _, field := range []string{ /*"type", "baseLayerIdentity"*/ } {
2aec97
 		var tmp mSI
2aec97
 		err := json.Unmarshal(validJSON, &tmp)
2aec97
 		require.NoError(t, err)
2aec97
@@ -1163,7 +1163,7 @@ func TestPRMExactRepositoryUnmarshalJSON(t *testing.T) {
2aec97
 	}
2aec97
 
2aec97
 	// Duplicated fields
2aec97
-	for _, field := range []string{"type", "baseLayerIdentity"} {
2aec97
+	for _, field := range []string{ /*"type", "baseLayerIdentity"*/ } {
2aec97
 		var tmp mSI
2aec97
 		err := json.Unmarshal(validJSON, &tmp)
2aec97
 		require.NoError(t, err)