diff --git a/byteslice.go b/byteslice.go index 04077c3..eefd8a9 100644 --- a/byteslice.go +++ b/byteslice.go @@ -121,17 +121,17 @@ func Set(data, setData []byte) ([]byte, error) { return result, nil } -// Toogle apply XOR operation on a byte slice with an "toogle" byte slice (must have the same size). -func Toogle(data, toogleData []byte) ([]byte, error) { +// Toggle apply XOR operation on a byte slice with an "toggle" byte slice (must have the same size). +func Toggle(data, toggleData []byte) ([]byte, error) { dataLength := len(data) - toogleDataLength := len(toogleData) - if dataLength != toogleDataLength { - return nil, errors.New("data and toogleData must have the same size") + toggleDataLength := len(toggleData) + if dataLength != toggleDataLength { + return nil, errors.New("data and toggleData must have the same size") } result := make([]byte, dataLength) for i := 0; i < dataLength; i++ { - result[i] = data[i] ^ toogleData[i] + result[i] = data[i] ^ toggleData[i] } return result, nil } diff --git a/byteslice_bigendian.go b/byteslice_bigendian.go index c695354..5d85632 100644 --- a/byteslice_bigendian.go +++ b/byteslice_bigendian.go @@ -32,17 +32,17 @@ func LSet(data, setData []byte) []byte { return result } -// LToogle apply XOR operation on a byte slice with an "toogle" byte slice using big endian order. -func LToogle(data, toogleData []byte) []byte { +// LToggle apply XOR operation on a byte slice with an "toggle" byte slice using big endian order. +func LToggle(data, toggleData []byte) []byte { dataLength := len(data) - toogleDataLength := len(toogleData) + toggleDataLength := len(toggleData) operationLength := dataLength - if toogleDataLength > dataLength { - operationLength = toogleDataLength + if toggleDataLength > dataLength { + operationLength = toggleDataLength } - result, _ := Toogle(RPad(data, operationLength, 0x00), RPad(toogleData, operationLength, 0x00)) + result, _ := Toggle(RPad(data, operationLength, 0x00), RPad(toggleData, operationLength, 0x00)) return result } diff --git a/byteslice_bigendian_test.go b/byteslice_bigendian_test.go index f3dd9bc..26ca110 100644 --- a/byteslice_bigendian_test.go +++ b/byteslice_bigendian_test.go @@ -85,28 +85,28 @@ func BenchmarkLSet(b *testing.B) { } } -var tcLToogle = []struct { +var tcLToggle = []struct { name string data []byte - toogleData []byte + toggleData []byte result []byte }{ {"equal length slices", []byte{0xDA, 0x99, 0xBA}, []byte{0xAD, 0x11, 0xAB}, []byte{0x77, 0x88, 0x11}}, {"data longer", []byte{0xAD, 0x11, 0xAB, 0x77, 0x88, 0x11}, []byte{0xDA, 0x99, 0xBA}, []byte{0x77, 0x88, 0x11, 0x77, 0x88, 0x11}}, - {"toogleData longer", []byte{0xDA, 0x99, 0xBA}, []byte{0xAD, 0x11, 0xAB, 0x77, 0x88, 0x11}, []byte{0x77, 0x88, 0x11, 0x77, 0x88, 0x11}}, + {"toggleData longer", []byte{0xDA, 0x99, 0xBA}, []byte{0xAD, 0x11, 0xAB, 0x77, 0x88, 0x11}, []byte{0x77, 0x88, 0x11, 0x77, 0x88, 0x11}}, {"data empty", []byte{}, []byte{0xAD, 0x11, 0xAB}, []byte{0xAD, 0x11, 0xAB}}, - {"toogleData empty", []byte{0xDA, 0x99, 0xBA}, []byte{}, []byte{0xDA, 0x99, 0xBA}}, + {"toggleData empty", []byte{0xDA, 0x99, 0xBA}, []byte{}, []byte{0xDA, 0x99, 0xBA}}, {"empty slices", []byte{}, []byte{}, []byte{}}, } -func TestLToogle(t *testing.T) { +func TestLToggle(t *testing.T) { var val []byte - for _, tc := range tcLToogle { + for _, tc := range tcLToggle { t.Run(tc.name, func(t *testing.T) { - val = LToogle(tc.data, tc.toogleData) + val = LToggle(tc.data, tc.toggleData) if !reflect.DeepEqual(val, tc.result) { - t.Errorf("LToogle(%x, %x) was %x, should be %x", - tc.data, tc.toogleData, + t.Errorf("LToggle(%x, %x) was %x, should be %x", + tc.data, tc.toggleData, val, tc.result) } @@ -114,12 +114,12 @@ func TestLToogle(t *testing.T) { } } -func BenchmarkLToogle(b *testing.B) { +func BenchmarkLToggle(b *testing.B) { var val []byte - for _, tc := range tcLToogle { + for _, tc := range tcLToggle { b.Run(tc.name, func(b *testing.B) { for i := 0; i < b.N; i++ { - val = LToogle(tc.data, tc.toogleData) + val = LToggle(tc.data, tc.toggleData) } }) } diff --git a/byteslice_littleendian.go b/byteslice_littleendian.go index 5f22004..7fb48f5 100644 --- a/byteslice_littleendian.go +++ b/byteslice_littleendian.go @@ -33,17 +33,17 @@ func RSet(data, setData []byte) []byte { return result } -// RToogle apply XOR operation on a byte slice with an "toogle" byte slice using little endian order. -func RToogle(data, toogleData []byte) []byte { +// RToggle apply XOR operation on a byte slice with an "toggle" byte slice using little endian order. +func RToggle(data, toggleData []byte) []byte { dataLength := len(data) - toogleDataLength := len(toogleData) + toggleDataLength := len(toggleData) operationLength := dataLength - if toogleDataLength > dataLength { - operationLength = toogleDataLength + if toggleDataLength > dataLength { + operationLength = toggleDataLength } - result, _ := Toogle(LPad(data, operationLength, 0x00), LPad(toogleData, operationLength, 0x00)) + result, _ := Toggle(LPad(data, operationLength, 0x00), LPad(toggleData, operationLength, 0x00)) return result } diff --git a/byteslice_littleendian_test.go b/byteslice_littleendian_test.go index 41eab16..bab6694 100644 --- a/byteslice_littleendian_test.go +++ b/byteslice_littleendian_test.go @@ -85,28 +85,28 @@ func BenchmarkRSet(b *testing.B) { } } -var tcRToogle = []struct { +var tcRToggle = []struct { name string data []byte - toogleData []byte + toggleData []byte result []byte }{ {"equal length slices", []byte{0xDA, 0x99, 0xBA}, []byte{0xAD, 0x11, 0xAB}, []byte{0x77, 0x88, 0x11}}, {"data longer", []byte{0x77, 0x88, 0x11, 0xAD, 0x11, 0xAB}, []byte{0xDA, 0x99, 0xBA}, []byte{0x77, 0x88, 0x11, 0x77, 0x88, 0x11}}, - {"toogleData longer", []byte{0xDA, 0x99, 0xBA}, []byte{0x77, 0x88, 0x11, 0xAD, 0x11, 0xAB}, []byte{0x77, 0x88, 0x11, 0x77, 0x88, 0x11}}, + {"toggleData longer", []byte{0xDA, 0x99, 0xBA}, []byte{0x77, 0x88, 0x11, 0xAD, 0x11, 0xAB}, []byte{0x77, 0x88, 0x11, 0x77, 0x88, 0x11}}, {"data empty", []byte{}, []byte{0xAD, 0x11, 0xAB}, []byte{0xAD, 0x11, 0xAB}}, - {"toogleData empty", []byte{0xDA, 0x99, 0xBA}, []byte{}, []byte{0xDA, 0x99, 0xBA}}, + {"toggleData empty", []byte{0xDA, 0x99, 0xBA}, []byte{}, []byte{0xDA, 0x99, 0xBA}}, {"empty slices", []byte{}, []byte{}, []byte{}}, } -func TestRToogle(t *testing.T) { +func TestRToggle(t *testing.T) { var val []byte - for _, tc := range tcRToogle { + for _, tc := range tcRToggle { t.Run(tc.name, func(t *testing.T) { - val = RToogle(tc.data, tc.toogleData) + val = RToggle(tc.data, tc.toggleData) if !reflect.DeepEqual(val, tc.result) { - t.Errorf("RToogle(%x, %x) was %x, should be %x", - tc.data, tc.toogleData, + t.Errorf("RToggle(%x, %x) was %x, should be %x", + tc.data, tc.toggleData, val, tc.result) } @@ -114,12 +114,12 @@ func TestRToogle(t *testing.T) { } } -func BenchmarkRToogle(b *testing.B) { +func BenchmarkRToggle(b *testing.B) { var val []byte - for _, tc := range tcRToogle { + for _, tc := range tcRToggle { b.Run(tc.name, func(b *testing.B) { for i := 0; i < b.N; i++ { - val = RToogle(tc.data, tc.toogleData) + val = RToggle(tc.data, tc.toggleData) } }) } diff --git a/byteslice_test.go b/byteslice_test.go index ee763d1..9eced30 100644 --- a/byteslice_test.go +++ b/byteslice_test.go @@ -214,10 +214,10 @@ func TestSetError(t *testing.T) { } } -func TestToogleError(t *testing.T) { - val, err := Toogle([]byte{0x00, 0x00}, []byte{0x00}) +func TestToggleError(t *testing.T) { + val, err := Toggle([]byte{0x00, 0x00}, []byte{0x00}) if err == nil || val != nil { - t.Errorf("Toogle with two byte slices of different size needs to return an error and no value") + t.Errorf("Toggle with two byte slices of different size needs to return an error and no value") } }