gofmt cleanups.
This commit is contained in:
parent
cb16cfa183
commit
832475db56
|
@ -56,7 +56,7 @@ var sliceFunctions = map[string]func([]byte) []byte{
|
||||||
type Hash struct {
|
type Hash struct {
|
||||||
hash.Hash
|
hash.Hash
|
||||||
secure bool
|
secure bool
|
||||||
algo string
|
algo string
|
||||||
}
|
}
|
||||||
|
|
||||||
// HashAlgo returns the name of the underlying hash algorithm.
|
// HashAlgo returns the name of the underlying hash algorithm.
|
||||||
|
@ -127,19 +127,19 @@ var secureHashes = map[string]func() hash.Hash{
|
||||||
"blake2b-512": blakeFunc(blake2b.New512),
|
"blake2b-512": blakeFunc(blake2b.New512),
|
||||||
}
|
}
|
||||||
|
|
||||||
func newHash32(f func () hash.Hash32) func () hash.Hash {
|
func newHash32(f func() hash.Hash32) func() hash.Hash {
|
||||||
return func() hash.Hash {
|
return func() hash.Hash {
|
||||||
return f()
|
return f()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newHash64(f func () hash.Hash64) func () hash.Hash {
|
func newHash64(f func() hash.Hash64) func() hash.Hash {
|
||||||
return func() hash.Hash {
|
return func() hash.Hash {
|
||||||
return f()
|
return f()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCRC64(tab uint64) func () hash.Hash {
|
func newCRC64(tab uint64) func() hash.Hash {
|
||||||
return newHash64(
|
return newHash64(
|
||||||
func() hash.Hash64 {
|
func() hash.Hash64 {
|
||||||
return crc64.New(crc64.MakeTable(tab))
|
return crc64.New(crc64.MakeTable(tab))
|
||||||
|
|
|
@ -12,11 +12,11 @@ func TestSecureHash(t *testing.T) {
|
||||||
algo := "sha256"
|
algo := "sha256"
|
||||||
h, err := New(algo)
|
h, err := New(algo)
|
||||||
assert.NoErrorT(t, err)
|
assert.NoErrorT(t, err)
|
||||||
assert.BoolT(t, h.IsSecure(), algo + " should be a secure hash")
|
assert.BoolT(t, h.IsSecure(), algo+" should be a secure hash")
|
||||||
assert.BoolT(t, h.HashAlgo() == algo, "hash returned the wrong HashAlgo")
|
assert.BoolT(t, h.HashAlgo() == algo, "hash returned the wrong HashAlgo")
|
||||||
assert.BoolT(t, !h.IsHash32(), algo + " isn't actually a 32-bit hash")
|
assert.BoolT(t, !h.IsHash32(), algo+" isn't actually a 32-bit hash")
|
||||||
assert.BoolT(t, !h.IsHash64(), algo + " isn't actually a 64-bit hash")
|
assert.BoolT(t, !h.IsHash64(), algo+" isn't actually a 64-bit hash")
|
||||||
|
|
||||||
var data []byte
|
var data []byte
|
||||||
var expected = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
var expected = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||||
sum, err := Sum(algo, data)
|
sum, err := Sum(algo, data)
|
||||||
|
@ -29,7 +29,7 @@ func TestSecureHash(t *testing.T) {
|
||||||
sum, err = SumReader(algo, buf)
|
sum, err = SumReader(algo, buf)
|
||||||
assert.NoErrorT(t, err)
|
assert.NoErrorT(t, err)
|
||||||
assert.BoolT(t, fmt.Sprintf("%x", sum) == expected, fmt.Sprintf("expected hash %s but have %x", expected, sum))
|
assert.BoolT(t, fmt.Sprintf("%x", sum) == expected, fmt.Sprintf("expected hash %s but have %x", expected, sum))
|
||||||
|
|
||||||
data = []byte("hello world")
|
data = []byte("hello world")
|
||||||
_, err = h.Write(data)
|
_, err = h.Write(data)
|
||||||
assert.NoErrorT(t, err)
|
assert.NoErrorT(t, err)
|
||||||
|
@ -42,10 +42,10 @@ func TestInsecureHash(t *testing.T) {
|
||||||
algo := "md5"
|
algo := "md5"
|
||||||
h, err := New(algo)
|
h, err := New(algo)
|
||||||
assert.NoErrorT(t, err)
|
assert.NoErrorT(t, err)
|
||||||
assert.BoolT(t, !h.IsSecure(), algo + " shouldn't be a secure hash")
|
assert.BoolT(t, !h.IsSecure(), algo+" shouldn't be a secure hash")
|
||||||
assert.BoolT(t, h.HashAlgo() == algo, "hash returned the wrong HashAlgo")
|
assert.BoolT(t, h.HashAlgo() == algo, "hash returned the wrong HashAlgo")
|
||||||
assert.BoolT(t, !h.IsHash32(), algo + " isn't actually a 32-bit hash")
|
assert.BoolT(t, !h.IsHash32(), algo+" isn't actually a 32-bit hash")
|
||||||
assert.BoolT(t, !h.IsHash64(), algo + " isn't actually a 64-bit hash")
|
assert.BoolT(t, !h.IsHash64(), algo+" isn't actually a 64-bit hash")
|
||||||
|
|
||||||
var data []byte
|
var data []byte
|
||||||
var expected = "d41d8cd98f00b204e9800998ecf8427e"
|
var expected = "d41d8cd98f00b204e9800998ecf8427e"
|
||||||
|
@ -59,7 +59,7 @@ func TestInsecureHash(t *testing.T) {
|
||||||
sum, err = SumReader(algo, buf)
|
sum, err = SumReader(algo, buf)
|
||||||
assert.NoErrorT(t, err)
|
assert.NoErrorT(t, err)
|
||||||
assert.BoolT(t, fmt.Sprintf("%x", sum) == expected, fmt.Sprintf("expected hash %s but have %x", expected, sum))
|
assert.BoolT(t, fmt.Sprintf("%x", sum) == expected, fmt.Sprintf("expected hash %s but have %x", expected, sum))
|
||||||
|
|
||||||
data = []byte("hello world")
|
data = []byte("hello world")
|
||||||
_, err = h.Write(data)
|
_, err = h.Write(data)
|
||||||
assert.NoErrorT(t, err)
|
assert.NoErrorT(t, err)
|
||||||
|
@ -72,31 +72,31 @@ func TestHash32(t *testing.T) {
|
||||||
algo := "crc32-ieee"
|
algo := "crc32-ieee"
|
||||||
h, err := New(algo)
|
h, err := New(algo)
|
||||||
assert.NoErrorT(t, err)
|
assert.NoErrorT(t, err)
|
||||||
assert.BoolT(t, !h.IsSecure(), algo + " shouldn't be a secure hash")
|
assert.BoolT(t, !h.IsSecure(), algo+" shouldn't be a secure hash")
|
||||||
assert.BoolT(t, h.HashAlgo() == algo, "hash returned the wrong HashAlgo")
|
assert.BoolT(t, h.HashAlgo() == algo, "hash returned the wrong HashAlgo")
|
||||||
assert.BoolT(t, h.IsHash32(), algo + " is actually a 32-bit hash")
|
assert.BoolT(t, h.IsHash32(), algo+" is actually a 32-bit hash")
|
||||||
assert.BoolT(t, !h.IsHash64(), algo + " isn't actually a 64-bit hash")
|
assert.BoolT(t, !h.IsHash64(), algo+" isn't actually a 64-bit hash")
|
||||||
|
|
||||||
var data []byte
|
var data []byte
|
||||||
var expected uint32
|
var expected uint32
|
||||||
|
|
||||||
h.Write(data)
|
h.Write(data)
|
||||||
sum, ok := h.Sum32()
|
sum, ok := h.Sum32()
|
||||||
assert.BoolT(t, ok, algo + " should be able to return a Sum32")
|
assert.BoolT(t, ok, algo+" should be able to return a Sum32")
|
||||||
assert.BoolT(t, expected == sum, fmt.Sprintf("%s returned the %d but expected %d", algo, sum, expected))
|
assert.BoolT(t, expected == sum, fmt.Sprintf("%s returned the %d but expected %d", algo, sum, expected))
|
||||||
|
|
||||||
data = []byte("hello, world")
|
data = []byte("hello, world")
|
||||||
expected = 0xffab723a
|
expected = 0xffab723a
|
||||||
h.Write(data)
|
h.Write(data)
|
||||||
sum, ok = h.Sum32()
|
sum, ok = h.Sum32()
|
||||||
assert.BoolT(t, ok, algo + " should be able to return a Sum32")
|
assert.BoolT(t, ok, algo+" should be able to return a Sum32")
|
||||||
assert.BoolT(t, expected == sum, fmt.Sprintf("%s returned the %d but expected %d", algo, sum, expected))
|
assert.BoolT(t, expected == sum, fmt.Sprintf("%s returned the %d but expected %d", algo, sum, expected))
|
||||||
|
|
||||||
h.Reset()
|
h.Reset()
|
||||||
data = []byte("hello world")
|
data = []byte("hello world")
|
||||||
h.Write(data)
|
h.Write(data)
|
||||||
sum, ok = h.Sum32()
|
sum, ok = h.Sum32()
|
||||||
assert.BoolT(t, ok, algo + " should be able to return a Sum32")
|
assert.BoolT(t, ok, algo+" should be able to return a Sum32")
|
||||||
assert.BoolT(t, expected != sum, fmt.Sprintf("%s returned %d but shouldn't have", algo, sum, expected))
|
assert.BoolT(t, expected != sum, fmt.Sprintf("%s returned %d but shouldn't have", algo, sum, expected))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,31 +104,31 @@ func TestHash64(t *testing.T) {
|
||||||
algo := "crc64"
|
algo := "crc64"
|
||||||
h, err := New(algo)
|
h, err := New(algo)
|
||||||
assert.NoErrorT(t, err)
|
assert.NoErrorT(t, err)
|
||||||
assert.BoolT(t, !h.IsSecure(), algo + " shouldn't be a secure hash")
|
assert.BoolT(t, !h.IsSecure(), algo+" shouldn't be a secure hash")
|
||||||
assert.BoolT(t, h.HashAlgo() == algo, "hash returned the wrong HashAlgo")
|
assert.BoolT(t, h.HashAlgo() == algo, "hash returned the wrong HashAlgo")
|
||||||
assert.BoolT(t, h.IsHash64(), algo + " is actually a 64-bit hash")
|
assert.BoolT(t, h.IsHash64(), algo+" is actually a 64-bit hash")
|
||||||
assert.BoolT(t, !h.IsHash32(), algo + " isn't actually a 32-bit hash")
|
assert.BoolT(t, !h.IsHash32(), algo+" isn't actually a 32-bit hash")
|
||||||
|
|
||||||
var data []byte
|
var data []byte
|
||||||
var expected uint64
|
var expected uint64
|
||||||
|
|
||||||
h.Write(data)
|
h.Write(data)
|
||||||
sum, ok := h.Sum64()
|
sum, ok := h.Sum64()
|
||||||
assert.BoolT(t, ok, algo + " should be able to return a Sum64")
|
assert.BoolT(t, ok, algo+" should be able to return a Sum64")
|
||||||
assert.BoolT(t, expected == sum, fmt.Sprintf("%s returned the %d but expected %d", algo, sum, expected))
|
assert.BoolT(t, expected == sum, fmt.Sprintf("%s returned the %d but expected %d", algo, sum, expected))
|
||||||
|
|
||||||
data = []byte("hello, world")
|
data = []byte("hello, world")
|
||||||
expected = 0x16c45c0eb1d9c2ec
|
expected = 0x16c45c0eb1d9c2ec
|
||||||
h.Write(data)
|
h.Write(data)
|
||||||
sum, ok = h.Sum64()
|
sum, ok = h.Sum64()
|
||||||
assert.BoolT(t, ok, algo + " should be able to return a Sum64")
|
assert.BoolT(t, ok, algo+" should be able to return a Sum64")
|
||||||
assert.BoolT(t, expected == sum, fmt.Sprintf("%s returned the %d but expected %d", algo, sum, expected))
|
assert.BoolT(t, expected == sum, fmt.Sprintf("%s returned the %d but expected %d", algo, sum, expected))
|
||||||
|
|
||||||
h.Reset()
|
h.Reset()
|
||||||
data = []byte("hello world")
|
data = []byte("hello world")
|
||||||
h.Write(data)
|
h.Write(data)
|
||||||
sum, ok = h.Sum64()
|
sum, ok = h.Sum64()
|
||||||
assert.BoolT(t, ok, algo + " should be able to return a Sum64")
|
assert.BoolT(t, ok, algo+" should be able to return a Sum64")
|
||||||
assert.BoolT(t, expected != sum, fmt.Sprintf("%s returned %d but shouldn't have", algo, sum, expected))
|
assert.BoolT(t, expected != sum, fmt.Sprintf("%s returned %d but shouldn't have", algo, sum, expected))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,6 +136,6 @@ func TestListLengthSanity(t *testing.T) {
|
||||||
all := HashList()
|
all := HashList()
|
||||||
secure := SecureHashList()
|
secure := SecureHashList()
|
||||||
insecure := InsecureHashList()
|
insecure := InsecureHashList()
|
||||||
|
|
||||||
assert.BoolT(t, len(all) == len(secure) + len(insecure))
|
assert.BoolT(t, len(all) == len(secure)+len(insecure))
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,8 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
preserveOwners bool
|
preserveOwners bool
|
||||||
preserveMode bool
|
preserveMode bool
|
||||||
verbose bool
|
verbose bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func setupFile(hdr *tar.Header, file *os.File) error {
|
func setupFile(hdr *tar.Header, file *os.File) error {
|
||||||
|
@ -30,7 +30,7 @@ func setupFile(hdr *tar.Header, file *os.File) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if preserveOwners {
|
if preserveOwners {
|
||||||
fmt.Printf("\tchown %d:%d\n", hdr.Uid, hdr.Gid)
|
fmt.Printf("\tchown %d:%d\n", hdr.Uid, hdr.Gid)
|
||||||
err := file.Chown(hdr.Uid, hdr.Gid)
|
err := file.Chown(hdr.Uid, hdr.Gid)
|
||||||
|
@ -227,7 +227,7 @@ func main() {
|
||||||
usage(os.Stdout)
|
usage(os.Stdout)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
if archive {
|
if archive {
|
||||||
preserveMode = true
|
preserveMode = true
|
||||||
preserveOwners = true
|
preserveOwners = true
|
||||||
|
|
|
@ -92,7 +92,7 @@ Options:
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.Usage = func () { usage(os.Stdout) }
|
flag.Usage = func() { usage(os.Stdout) }
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -54,7 +54,7 @@ func main() {
|
||||||
flag.BoolVar(&help, "h", false, "print a help message")
|
flag.BoolVar(&help, "h", false, "print a help message")
|
||||||
flag.StringVar(&list, "l", "", "list known hash algorithms (one of all, secure, insecure)")
|
flag.StringVar(&list, "l", "", "list known hash algorithms (one of all, secure, insecure)")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if help {
|
if help {
|
||||||
usage(os.Stdout)
|
usage(os.Stdout)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/kisom/goutils/testio"
|
|
||||||
"github.com/kisom/goutils/assert"
|
"github.com/kisom/goutils/assert"
|
||||||
|
"github.com/kisom/goutils/testio"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMWC(t *testing.T) {
|
func TestMWC(t *testing.T) {
|
||||||
|
@ -39,7 +39,7 @@ func TestMWCShort(t *testing.T) {
|
||||||
|
|
||||||
mwc = MultiWriteCloser(buf1, buf2, buf4)
|
mwc = MultiWriteCloser(buf1, buf2, buf4)
|
||||||
_, err = mwc.Write([]byte("hello, world"))
|
_, err = mwc.Write([]byte("hello, world"))
|
||||||
assert.ErrorT(t, err, "expected a short write error", "but no error occurred")
|
assert.ErrorT(t, err, "expected a short write error", "but no error occurred")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMWCClose(t *testing.T) {
|
func TestMWCClose(t *testing.T) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
// Tee emulates the Unix tee(1) command.
|
// Tee emulates the Unix tee(1) command.
|
||||||
type Tee struct {
|
type Tee struct {
|
||||||
f *os.File
|
f *os.File
|
||||||
Verbose bool
|
Verbose bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,13 +36,12 @@ func NewOut(logFile string) (*Tee, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := os.Create(logFile)
|
f, err := os.Create(logFile)
|
||||||
if err !=nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &Tee{f: f}, nil
|
return &Tee{f: f}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Printf formats according to a format specifier and writes to the
|
// Printf formats according to a format specifier and writes to the
|
||||||
// tee instance.
|
// tee instance.
|
||||||
func (t *Tee) Printf(format string, args ...interface{}) (int, error) {
|
func (t *Tee) Printf(format string, args ...interface{}) (int, error) {
|
||||||
|
@ -51,7 +50,7 @@ func (t *Tee) Printf(format string, args ...interface{}) (int, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.f == nil {
|
if t.f == nil {
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
@ -73,7 +72,7 @@ var globalTee = &Tee{}
|
||||||
// Open will attempt to open the logFile for the global tee instance.
|
// Open will attempt to open the logFile for the global tee instance.
|
||||||
func Open(logFile string) error {
|
func Open(logFile string) error {
|
||||||
f, err := os.Create(logFile)
|
f, err := os.Create(logFile)
|
||||||
if err !=nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
globalTee.f = f
|
globalTee.f = f
|
||||||
|
|
Loading…
Reference in New Issue