This file is indexed.

/usr/share/gocode/src/github.com/stevvooe/resumable/sha512/sha512resume_test.go is in golang-github-stevvooe-resumable-dev 0.0~git20150521.0.51ad441-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package sha512

import (
	"bytes"
	"crypto"
	"crypto/rand" // To register the stdlib sha224 and sha256 algs.
	"crypto/sha512"
	"hash"
	"io"
	"testing"

	"github.com/stevvooe/resumable"
)

func compareResumableHash(t *testing.T, newResumable func() hash.Hash, newStdlib func() hash.Hash) {
	// Read 3 Kilobytes of random data into a buffer.
	buf := make([]byte, 3*1024)
	if _, err := io.ReadFull(rand.Reader, buf); err != nil {
		t.Fatalf("unable to load random data: %s", err)
	}

	// Use two Hash objects to consume prefixes of the data. One will be
	// snapshotted and resumed with each additional byte, then both will write
	// that byte. The digests should be equal after each byte is digested.
	resumableHasher := newResumable().(resumable.Hash)
	stdlibHasher := newStdlib()

	// First, assert that the initial distest is the same.
	if !bytes.Equal(resumableHasher.Sum(nil), stdlibHasher.Sum(nil)) {
		t.Fatalf("initial digests do not match: got %x, expected %x", resumableHasher.Sum(nil), stdlibHasher.Sum(nil))
	}

	multiWriter := io.MultiWriter(resumableHasher, stdlibHasher)

	for i := 1; i <= len(buf); i++ {

		// Write the next byte.
		multiWriter.Write(buf[i-1 : i])

		if !bytes.Equal(resumableHasher.Sum(nil), stdlibHasher.Sum(nil)) {
			t.Fatalf("digests do not match: got %x, expected %x", resumableHasher.Sum(nil), stdlibHasher.Sum(nil))
		}

		// Snapshot, reset, and restore the chunk hasher.
		hashState, err := resumableHasher.State()
		if err != nil {
			t.Fatalf("unable to get state of hash function: %s", err)
		}
		resumableHasher.Reset()
		if err := resumableHasher.Restore(hashState); err != nil {
			t.Fatalf("unable to restorte state of hash function: %s", err)
		}
	}
}

func TestResumable(t *testing.T) {
	compareResumableHash(t, New384, sha512.New384)
	compareResumableHash(t, New, sha512.New)
}

func TestResumableRegistered(t *testing.T) {

	for _, hf := range []crypto.Hash{crypto.SHA384, crypto.SHA512} {
		// make sure that the hash gets the resumable version from the global
		// registry in crypto library.
		h := hf.New()

		if rh, ok := h.(resumable.Hash); !ok {
			t.Fatalf("non-resumable hash function registered: %#v %#v", rh, crypto.SHA256)
		}

	}

}