From 11138924897e02e5c05803527352efca304affb9 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Tue, 9 Mar 2021 16:17:10 +0800 Subject: [PATCH] remove stray struct equality check This check was moved to qtls. --- internal/qtls/structs_equal.go | 19 --------- internal/qtls/structs_equal_test.go | 60 ----------------------------- 2 files changed, 79 deletions(-) delete mode 100644 internal/qtls/structs_equal.go delete mode 100644 internal/qtls/structs_equal_test.go diff --git a/internal/qtls/structs_equal.go b/internal/qtls/structs_equal.go deleted file mode 100644 index 7df0423ac..000000000 --- a/internal/qtls/structs_equal.go +++ /dev/null @@ -1,19 +0,0 @@ -package qtls - -import "reflect" - -func structsEqual(a, b interface{}) bool { - sa := reflect.ValueOf(a).Elem() - sb := reflect.ValueOf(b).Elem() - if sa.NumField() != sb.NumField() { - return false - } - for i := 0; i < sa.NumField(); i++ { - fa := sa.Type().Field(i) - fb := sb.Type().Field(i) - if !reflect.DeepEqual(fa.Index, fb.Index) || fa.Name != fb.Name || fa.Anonymous != fb.Anonymous || fa.Offset != fb.Offset || !reflect.DeepEqual(fa.Type, fb.Type) { - return false - } - } - return true -} diff --git a/internal/qtls/structs_equal_test.go b/internal/qtls/structs_equal_test.go deleted file mode 100644 index 2a2f46c22..000000000 --- a/internal/qtls/structs_equal_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package qtls - -import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -type target struct { - Name string - Version string - - callback func(label string, length int) error -} - -type renamedField struct { - NewName string - Version string - - callback func(label string, length int) error -} - -type renamedPrivateField struct { - Name string - Version string - - cb func(label string, length int) error -} - -type additionalField struct { - Name string - Version string - - callback func(label string, length int) error - secret []byte -} - -type interchangedFields struct { - Version string - Name string - - callback func(label string, length int) error -} - -type renamedCallbackFunctionParams struct { // should be equivalent - Name string - Version string - - callback func(newLabel string, length int) error -} - -var _ = Describe("Unsafe checks", func() { - It("detects if an unsafe conversion is safe", func() { - Expect(structsEqual(&target{}, &target{})).To(BeTrue()) - Expect(structsEqual(&target{}, &renamedField{})).To(BeFalse()) - Expect(structsEqual(&target{}, &renamedPrivateField{})).To(BeFalse()) - Expect(structsEqual(&target{}, &additionalField{})).To(BeFalse()) - Expect(structsEqual(&target{}, &interchangedFields{})).To(BeFalse()) - Expect(structsEqual(&target{}, &renamedCallbackFunctionParams{})).To(BeTrue()) - }) -})