Apply gofmt

This commit is contained in:
Andrew Ayer 2017-01-08 10:17:00 -08:00
parent 9f3e9968ec
commit 2f0833ac9c
7 changed files with 44 additions and 44 deletions

View File

@ -137,7 +137,7 @@ type CollapsedMerkleTree struct {
size uint64
}
func calculateNumNodes (size uint64) int {
func calculateNumNodes(size uint64) int {
numNodes := 0
for size > 0 {
numNodes += int(size & 1)
@ -145,16 +145,16 @@ func calculateNumNodes (size uint64) int {
}
return numNodes
}
func EmptyCollapsedMerkleTree () *CollapsedMerkleTree {
func EmptyCollapsedMerkleTree() *CollapsedMerkleTree {
return &CollapsedMerkleTree{}
}
func NewCollapsedMerkleTree (nodes []ct.MerkleTreeNode, size uint64) (*CollapsedMerkleTree, error) {
func NewCollapsedMerkleTree(nodes []ct.MerkleTreeNode, size uint64) (*CollapsedMerkleTree, error) {
if len(nodes) != calculateNumNodes(size) {
return nil, errors.New("NewCollapsedMerkleTree: nodes has incorrect size")
}
return &CollapsedMerkleTree{nodes: nodes, size: size}, nil
}
func CloneCollapsedMerkleTree (source *CollapsedMerkleTree) *CollapsedMerkleTree {
func CloneCollapsedMerkleTree(source *CollapsedMerkleTree) *CollapsedMerkleTree {
nodes := make([]ct.MerkleTreeNode, len(source.nodes))
copy(nodes, source.nodes)
return &CollapsedMerkleTree{nodes: nodes, size: source.size}
@ -192,14 +192,14 @@ func (tree *CollapsedMerkleTree) GetSize() uint64 {
func (tree *CollapsedMerkleTree) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"nodes": tree.nodes,
"size": tree.size,
"size": tree.size,
})
}
func (tree *CollapsedMerkleTree) UnmarshalJSON(b []byte) error {
var rawTree struct {
Nodes []ct.MerkleTreeNode `json:"nodes"`
Size uint64 `json:"size"`
Size uint64 `json:"size"`
}
if err := json.Unmarshal(b, &rawTree); err != nil {
return errors.New("Failed to unmarshal CollapsedMerkleTree: " + err.Error())

View File

@ -80,7 +80,7 @@ func LogEntry(info *certspotter.EntryInfo) {
}
}
func loadLogList () ([]certspotter.LogInfo, error) {
func loadLogList() ([]certspotter.LogInfo, error) {
if *logsFilename != "" {
var logFileObj certspotter.LogInfoFile
if err := readJSONFile(*logsFilename, &logFileObj); err != nil {
@ -95,10 +95,10 @@ func loadLogList () ([]certspotter.LogInfo, error) {
}
type logHandle struct {
scanner *certspotter.Scanner
state *LogState
tree *certspotter.CollapsedMerkleTree
verifiedSTH *ct.SignedTreeHead
scanner *certspotter.Scanner
state *LogState
tree *certspotter.CollapsedMerkleTree
verifiedSTH *ct.SignedTreeHead
}
func makeLogHandle(logInfo *certspotter.LogInfo) (*logHandle, error) {
@ -128,7 +128,7 @@ func makeLogHandle(logInfo *certspotter.LogInfo) (*logHandle, error) {
}
if ctlog.tree == nil && ctlog.verifiedSTH == nil { // This branch can be removed eventually
legacySTH, err := state.GetLegacySTH(logInfo);
legacySTH, err := state.GetLegacySTH(logInfo)
if err != nil {
return nil, fmt.Errorf("Error loading legacy STH: %s", err)
}
@ -151,7 +151,7 @@ func makeLogHandle(logInfo *certspotter.LogInfo) (*logHandle, error) {
return ctlog, nil
}
func (ctlog *logHandle) refresh () error {
func (ctlog *logHandle) refresh() error {
if *verbose {
log.Printf("Retrieving latest STH from log")
}
@ -175,7 +175,7 @@ func (ctlog *logHandle) refresh () error {
return nil
}
func (ctlog *logHandle) audit () error {
func (ctlog *logHandle) audit() error {
sths, err := ctlog.state.GetUnverifiedSTHs()
if err != nil {
return fmt.Errorf("Error loading unverified STHs: %s", err)
@ -221,7 +221,7 @@ func (ctlog *logHandle) audit () error {
return nil
}
func (ctlog *logHandle) scan (processCallback certspotter.ProcessCallback) error {
func (ctlog *logHandle) scan(processCallback certspotter.ProcessCallback) error {
startIndex := int64(ctlog.tree.GetSize())
endIndex := int64(ctlog.verifiedSTH.TreeSize)
@ -246,7 +246,7 @@ func (ctlog *logHandle) scan (processCallback certspotter.ProcessCallback) error
return nil
}
func processLog(logInfo* certspotter.LogInfo, processCallback certspotter.ProcessCallback) int {
func processLog(logInfo *certspotter.LogInfo, processCallback certspotter.ProcessCallback) int {
log.SetPrefix(os.Args[0] + ": " + logInfo.Url + ": ")
ctlog, err := makeLogHandle(logInfo)

View File

@ -24,11 +24,11 @@ import (
)
type LogState struct {
path string
path string
}
// generate a filename that uniquely identifies the STH (within the context of a particular log)
func sthFilename (sth *ct.SignedTreeHead) string {
func sthFilename(sth *ct.SignedTreeHead) string {
hasher := sha256.New()
switch sth.Version {
case ct.V1:
@ -41,7 +41,7 @@ func sthFilename (sth *ct.SignedTreeHead) string {
return strconv.FormatUint(sth.TreeSize, 10) + "-" + base64.RawURLEncoding.EncodeToString(hasher.Sum(nil)) + ".json"
}
func makeLogStateDir (logStatePath string) error {
func makeLogStateDir(logStatePath string) error {
if err := os.Mkdir(logStatePath, 0777); err != nil && !os.IsExist(err) {
return fmt.Errorf("%s: %s", logStatePath, err)
}
@ -54,18 +54,18 @@ func makeLogStateDir (logStatePath string) error {
return nil
}
func OpenLogState (logStatePath string) (*LogState, error) {
func OpenLogState(logStatePath string) (*LogState, error) {
if err := makeLogStateDir(logStatePath); err != nil {
return nil, fmt.Errorf("Error creating log state directory: %s", err)
}
return &LogState{path: logStatePath}, nil
}
func (logState *LogState) VerifiedSTHFilename () string {
func (logState *LogState) VerifiedSTHFilename() string {
return filepath.Join(logState.path, "sth.json")
}
func (logState *LogState) GetVerifiedSTH () (*ct.SignedTreeHead, error) {
func (logState *LogState) GetVerifiedSTH() (*ct.SignedTreeHead, error) {
sth, err := readSTHFile(logState.VerifiedSTHFilename())
if err != nil {
if os.IsNotExist(err) {
@ -77,11 +77,11 @@ func (logState *LogState) GetVerifiedSTH () (*ct.SignedTreeHead, error) {
return sth, nil
}
func (logState *LogState) StoreVerifiedSTH (sth *ct.SignedTreeHead) error {
func (logState *LogState) StoreVerifiedSTH(sth *ct.SignedTreeHead) error {
return writeJSONFile(logState.VerifiedSTHFilename(), sth, 0666)
}
func (logState *LogState) GetUnverifiedSTHs () ([]*ct.SignedTreeHead, error) {
func (logState *LogState) GetUnverifiedSTHs() ([]*ct.SignedTreeHead, error) {
dir, err := os.Open(filepath.Join(logState.path, "unverified_sths"))
if err != nil {
if os.IsNotExist(err) {
@ -107,11 +107,11 @@ func (logState *LogState) GetUnverifiedSTHs () ([]*ct.SignedTreeHead, error) {
return sths, nil
}
func (logState *LogState) UnverifiedSTHFilename (sth *ct.SignedTreeHead) string {
func (logState *LogState) UnverifiedSTHFilename(sth *ct.SignedTreeHead) string {
return filepath.Join(logState.path, "unverified_sths", sthFilename(sth))
}
func (logState *LogState) StoreUnverifiedSTH (sth *ct.SignedTreeHead) error {
func (logState *LogState) StoreUnverifiedSTH(sth *ct.SignedTreeHead) error {
filename := logState.UnverifiedSTHFilename(sth)
if fileExists(filename) {
return nil
@ -119,7 +119,7 @@ func (logState *LogState) StoreUnverifiedSTH (sth *ct.SignedTreeHead) error {
return writeJSONFile(filename, sth, 0666)
}
func (logState *LogState) RemoveUnverifiedSTH (sth *ct.SignedTreeHead) error {
func (logState *LogState) RemoveUnverifiedSTH(sth *ct.SignedTreeHead) error {
filename := logState.UnverifiedSTHFilename(sth)
err := os.Remove(filepath.Join(filename))
if err != nil && !os.IsNotExist(err) {
@ -128,7 +128,7 @@ func (logState *LogState) RemoveUnverifiedSTH (sth *ct.SignedTreeHead) error {
return nil
}
func (logState *LogState) GetTree () (*certspotter.CollapsedMerkleTree, error) {
func (logState *LogState) GetTree() (*certspotter.CollapsedMerkleTree, error) {
tree := new(certspotter.CollapsedMerkleTree)
if err := readJSONFile(filepath.Join(logState.path, "tree.json"), tree); err != nil {
if os.IsNotExist(err) {
@ -140,6 +140,6 @@ func (logState *LogState) GetTree () (*certspotter.CollapsedMerkleTree, error) {
return tree, nil
}
func (logState *LogState) StoreTree (tree *certspotter.CollapsedMerkleTree) error {
func (logState *LogState) StoreTree(tree *certspotter.CollapsedMerkleTree) error {
return writeJSONFile(filepath.Join(logState.path, "tree.json"), tree, 0666)
}

View File

@ -14,8 +14,8 @@ import (
"encoding/base64"
"encoding/pem"
"fmt"
"log"
"io/ioutil"
"log"
"os"
"path/filepath"
"strconv"
@ -26,14 +26,14 @@ import (
)
type State struct {
path string
path string
}
func legacySTHFilename(logInfo *certspotter.LogInfo) string {
return strings.Replace(strings.Replace(logInfo.FullURI(), "://", "_", 1), "/", "_", -1)
}
func readVersionFile (statePath string) (int, error) {
func readVersionFile(statePath string) (int, error) {
versionFilePath := filepath.Join(statePath, "version")
versionBytes, err := ioutil.ReadFile(versionFilePath)
if err == nil {
@ -57,7 +57,7 @@ func readVersionFile (statePath string) (int, error) {
}
}
func writeVersionFile (statePath string) error {
func writeVersionFile(statePath string) error {
version := 1
versionString := fmt.Sprintf("%d\n", version)
versionFilePath := filepath.Join(statePath, "version")
@ -67,7 +67,7 @@ func writeVersionFile (statePath string) error {
return nil
}
func makeStateDir (statePath string) error {
func makeStateDir(statePath string) error {
if err := os.Mkdir(statePath, 0777); err != nil && !os.IsExist(err) {
return fmt.Errorf("%s: %s", statePath, err)
}
@ -80,7 +80,7 @@ func makeStateDir (statePath string) error {
return nil
}
func OpenState (statePath string) (*State, error) {
func OpenState(statePath string) (*State, error) {
version, err := readVersionFile(statePath)
if err != nil {
return nil, fmt.Errorf("Error reading version file: %s", err)

View File

@ -64,7 +64,7 @@ type getConsistencyProofResponse struct {
// getAuditProofResponse represents the JSON response to the CT get-proof-by-hash method
type getAuditProofResponse struct {
LeafIndex uint64 `json:"leaf_index"`
LeafIndex uint64 `json:"leaf_index"`
AuditPath [][]byte `json:"audit_path"`
}
@ -160,7 +160,7 @@ func (c *LogClient) GetEntries(start, end int64) ([]ct.LogEntry, error) {
for index, entry := range resp.Entries {
leaf, err := ct.ReadMerkleTreeLeaf(bytes.NewBuffer(entry.LeafInput))
if err != nil {
return nil, fmt.Errorf("Reading Merkle Tree Leaf at index %d failed: %s", start + int64(index), err)
return nil, fmt.Errorf("Reading Merkle Tree Leaf at index %d failed: %s", start+int64(index), err)
}
entries[index].LeafBytes = entry.LeafInput
entries[index].Leaf = *leaf
@ -174,10 +174,10 @@ func (c *LogClient) GetEntries(start, end int64) ([]ct.LogEntry, error) {
chain, err = ct.UnmarshalPrecertChainArray(entry.ExtraData)
default:
return nil, fmt.Errorf("Unknown entry type at index %d: %v", start + int64(index), leaf.TimestampedEntry.EntryType)
return nil, fmt.Errorf("Unknown entry type at index %d: %v", start+int64(index), leaf.TimestampedEntry.EntryType)
}
if err != nil {
return nil, fmt.Errorf("Parsing entry of type %d at index %d failed: %s", leaf.TimestampedEntry.EntryType, start + int64(index), err)
return nil, fmt.Errorf("Parsing entry of type %d at index %d failed: %s", leaf.TimestampedEntry.EntryType, start+int64(index), err)
}
entries[index].Chain = chain
entries[index].Index = start + int64(index)

View File

@ -80,7 +80,7 @@ func readVarBytes(r io.Reader, numLenBytes int) ([]byte, error) {
return nil, err
}
data := make([]byte, l)
if n, err := io.ReadFull(r, data); err != nil {
if n, err := io.ReadFull(r, data); err != nil {
if err == io.EOF || err == io.ErrUnexpectedEOF {
return nil, fmt.Errorf("short read: expected %d but got %d", l, n)
}

View File

@ -62,7 +62,7 @@ type Scanner struct {
// Public key of the log
publicKey crypto.PublicKey
LogId []byte
LogId []byte
// Client used to talk to the CT log instance
logClient *client.LogClient
@ -239,12 +239,12 @@ func (s *Scanner) MakeCollapsedMerkleTree(sth *ct.SignedTreeHead) (*CollapsedMer
return &CollapsedMerkleTree{}, nil
}
entries, err := s.logClient.GetEntries(int64(sth.TreeSize - 1), int64(sth.TreeSize - 1))
entries, err := s.logClient.GetEntries(int64(sth.TreeSize-1), int64(sth.TreeSize-1))
if err != nil {
return nil, err
}
if len(entries) == 0 {
return nil, fmt.Errorf("Log did not return entry %d", sth.TreeSize - 1)
return nil, fmt.Errorf("Log did not return entry %d", sth.TreeSize-1)
}
leafHash := hashLeaf(entries[0].LeafBytes)
@ -255,7 +255,7 @@ func (s *Scanner) MakeCollapsedMerkleTree(sth *ct.SignedTreeHead) (*CollapsedMer
return nil, err
}
reverseHashes(auditPath)
tree, err = NewCollapsedMerkleTree(auditPath, sth.TreeSize - 1)
tree, err = NewCollapsedMerkleTree(auditPath, sth.TreeSize-1)
if err != nil {
return nil, fmt.Errorf("Error returned bad audit proof for %x to %d", leafHash, sth.TreeSize)
}