From 346e06d07d141629dc330fc404f6cde79e1666af Mon Sep 17 00:00:00 2001 From: Matthias Frei Date: Fri, 20 Jan 2023 10:15:55 +0100 Subject: [PATCH] pkg/private/common: remove NativeOrder and IsBigEndian No longer needed. Native byte order is not often needed, but will eventually show up in standard library anyway (golang/go#57237). --- pkg/private/common/BUILD.bazel | 1 - pkg/private/common/binary.go | 36 ---------------------------------- pkg/scrypto/rand.go | 3 ++- 3 files changed, 2 insertions(+), 38 deletions(-) delete mode 100644 pkg/private/common/binary.go diff --git a/pkg/private/common/BUILD.bazel b/pkg/private/common/BUILD.bazel index 1c39bcb1c6..36602cce10 100644 --- a/pkg/private/common/BUILD.bazel +++ b/pkg/private/common/BUILD.bazel @@ -3,7 +3,6 @@ load("//tools/lint:go.bzl", "go_library", "go_test") go_library( name = "go_default_library", srcs = [ - "binary.go", "defs.go", "errors.go", ], diff --git a/pkg/private/common/binary.go b/pkg/private/common/binary.go deleted file mode 100644 index 17fe910ff3..0000000000 --- a/pkg/private/common/binary.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2017 ETH Zurich -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package common - -import ( - "encoding/binary" - "unsafe" -) - -var ( - NativeOrder binary.ByteOrder - IsBigEndian bool -) - -func init() { - var v uint16 = 0x11FF - if (*[2]uint8)(unsafe.Pointer(&v))[0] == 0x11 { - IsBigEndian = true - NativeOrder = binary.BigEndian - } else { - IsBigEndian = false - NativeOrder = binary.LittleEndian - } -} diff --git a/pkg/scrypto/rand.go b/pkg/scrypto/rand.go index 74e57b9273..b998d73ab6 100644 --- a/pkg/scrypto/rand.go +++ b/pkg/scrypto/rand.go @@ -16,6 +16,7 @@ package scrypto import ( "crypto/rand" + "encoding/binary" mrand "math/rand" "github.com/scionproto/scion/pkg/private/common" @@ -38,7 +39,7 @@ func RandUint64() uint64 { // OS, and there's nothing we can do about it. panic("No random numbers available") } - return common.NativeOrder.Uint64(b) + return binary.LittleEndian.Uint64(b) } // RandInt64 returns a random int64 value. The returned value can be negative.