From 0d764a51b7a875ad50d007a26c6f5542c29b92d0 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 9 Mar 2022 17:01:50 +0300 Subject: [PATCH] *: rename `ByteArray` to `Bytes` Signed-off-by: Evgenii Stratonikov --- gf127/gf127.go | 10 +++++----- gf127/gf127x2.go | 9 ++++----- tz/digest.go | 14 +++++--------- tz/hash_test.go | 2 +- tz/sl2.go | 12 ++++++------ 5 files changed, 21 insertions(+), 26 deletions(-) diff --git a/gf127/gf127.go b/gf127/gf127.go index 414f795..fea6312 100644 --- a/gf127/gf127.go +++ b/gf127/gf127.go @@ -142,7 +142,7 @@ func Random() *GF127 { // String returns hex-encoded representation, starting with MSB. func (c *GF127) String() string { - buf := c.ByteArray() + buf := c.Bytes() return hex.EncodeToString(buf[:]) } @@ -151,9 +151,9 @@ func (c *GF127) Equals(b *GF127) bool { return c[0] == b[0] && c[1] == b[1] } -// ByteArray represents element of GF(2^127) as byte array of length 16. -func (c *GF127) ByteArray() []byte { - buf := make([]byte, 16) +// Bytes represents element of GF(2^127) as byte array of length 16. +func (c *GF127) Bytes() [16]byte { + var buf [16]byte binary.BigEndian.PutUint64(buf[:8], c[1]) binary.BigEndian.PutUint64(buf[8:], c[0]) return buf @@ -161,7 +161,7 @@ func (c *GF127) ByteArray() []byte { // MarshalBinary implements encoding.BinaryMarshaler. func (c *GF127) MarshalBinary() (data []byte, err error) { - buf := c.ByteArray() + buf := c.Bytes() return buf[:], nil } diff --git a/gf127/gf127x2.go b/gf127/gf127x2.go index 12d5cef..c3c4dd4 100644 --- a/gf127/gf127x2.go +++ b/gf127/gf127x2.go @@ -37,14 +37,13 @@ func (a *GF127x2) Equal(b *GF127x2) bool { // String returns hex-encoded representation, starting with MSB. // Elements of pair are separated by comma. func (a *GF127x2) String() string { - b := a.ByteArray() + b := a.Bytes() return hex.EncodeToString(b[:16]) + " , " + hex.EncodeToString(b[16:]) } -// ByteArray represents element of GF(2^127) as byte array of length 32. -func (a *GF127x2) ByteArray() (buf []byte) { - buf = make([]byte, 32) - binary.BigEndian.PutUint64(buf, a[0][1]) +// Bytes represents element of GF(2^127) as byte array of length 32. +func (a *GF127x2) Bytes() (buf [32]byte) { + binary.BigEndian.PutUint64(buf[:], a[0][1]) binary.BigEndian.PutUint64(buf[8:], a[0][0]) binary.BigEndian.PutUint64(buf[16:], a[1][1]) binary.BigEndian.PutUint64(buf[24:], a[1][0]) diff --git a/tz/digest.go b/tz/digest.go index 7ba074d..e930386 100644 --- a/tz/digest.go +++ b/tz/digest.go @@ -40,21 +40,17 @@ func (d *digest) Sum(in []byte) []byte { return append(in, h[:]...) } -func (d *digest) checkSum() [Size]byte { - return d.byteArray() -} - -func (d *digest) byteArray() (b [Size]byte) { - t := d.x[0].ByteArray() +func (d *digest) checkSum() (b [Size]byte) { + t := d.x[0].Bytes() copy(b[:], t[:]) - t = d.x[2].ByteArray() + t = d.x[2].Bytes() copy(b[16:], t[:]) - t = d.x[1].ByteArray() + t = d.x[1].Bytes() copy(b[32:], t[:]) - t = d.x[3].ByteArray() + t = d.x[3].Bytes() copy(b[48:], t[:]) return diff --git a/tz/hash_test.go b/tz/hash_test.go index 539b8f1..39fcfe6 100644 --- a/tz/hash_test.go +++ b/tz/hash_test.go @@ -160,7 +160,7 @@ func TestHomomorphism(t *testing.T) { require.NoError(t, err) c1.Mul(&c1, &c2) - require.Equal(t, h, c1.ByteArray()) + require.Equal(t, h, c1.Bytes()) } var testCasesConcat = []struct { diff --git a/tz/sl2.go b/tz/sl2.go index cc45281..7852eb1 100644 --- a/tz/sl2.go +++ b/tz/sl2.go @@ -19,7 +19,7 @@ var id = sl2{ // MarshalBinary implements encoding.BinaryMarshaler. func (c *sl2) MarshalBinary() (data []byte, err error) { - s := c.ByteArray() + s := c.Bytes() return s[:], nil } @@ -159,17 +159,17 @@ func (c *sl2) String() string { c[1][0].String() + c[1][1].String() } -func (c *sl2) ByteArray() (b [Size]byte) { - t := c[0][0].ByteArray() +func (c *sl2) Bytes() (b [Size]byte) { + t := c[0][0].Bytes() copy(b[:], t[:]) - t = c[0][1].ByteArray() + t = c[0][1].Bytes() copy(b[16:], t[:]) - t = c[1][0].ByteArray() + t = c[1][0].Bytes() copy(b[32:], t[:]) - t = c[1][1].ByteArray() + t = c[1][1].Bytes() copy(b[48:], t[:]) return