From dd36f26adbb4c6007fbffbeaeae3eae0be521b32 Mon Sep 17 00:00:00 2001 From: Marcela M Date: Thu, 9 Nov 2017 11:53:55 -0500 Subject: [PATCH] Fix broken imports --- application/bots/twitterbot.go | 1 + cli/coniksclient/internal/cmd/run.go | 2 +- cli/coniksserver/internal/cmd/init.go | 2 +- coniksauditor/config.go | 8 +- coniksauditor/encoding.go | 18 ++-- utils/binutils/encoding.go | 102 ++++++++++---------- utils/binutils/encoding_test.go | 130 +++++++++++++------------- 7 files changed, 132 insertions(+), 131 deletions(-) diff --git a/application/bots/twitterbot.go b/application/bots/twitterbot.go index 7d433c4..95fdd72 100644 --- a/application/bots/twitterbot.go +++ b/application/bots/twitterbot.go @@ -12,6 +12,7 @@ import ( "github.com/coniks-sys/coniks-go/application" "github.com/coniks-sys/coniks-go/protocol" + "github.com/coniks-sys/coniks-go/utils/binutils" "github.com/dghubble/go-twitter/twitter" "github.com/dghubble/oauth1" ) diff --git a/cli/coniksclient/internal/cmd/run.go b/cli/coniksclient/internal/cmd/run.go index 750706f..ee85315 100644 --- a/cli/coniksclient/internal/cmd/run.go +++ b/cli/coniksclient/internal/cmd/run.go @@ -13,7 +13,7 @@ import ( "github.com/coniks-sys/coniks-go/cli" "github.com/coniks-sys/coniks-go/protocol" "github.com/coniks-sys/coniks-go/protocol/client" - "github.com/coniks-sys/coniks-go/utils" + "github.com/coniks-sys/coniks-go/utils/binutils" "github.com/spf13/cobra" "golang.org/x/crypto/ssh/terminal" ) diff --git a/cli/coniksserver/internal/cmd/init.go b/cli/coniksserver/internal/cmd/init.go index e9b3903..585c42d 100644 --- a/cli/coniksserver/internal/cmd/init.go +++ b/cli/coniksserver/internal/cmd/init.go @@ -12,6 +12,7 @@ import ( "github.com/coniks-sys/coniks-go/crypto/sign" "github.com/coniks-sys/coniks-go/crypto/vrf" "github.com/coniks-sys/coniks-go/utils" + "github.com/coniks-sys/coniks-go/utils/binutils" "github.com/spf13/cobra" ) @@ -53,7 +54,6 @@ func mkConfig(dir string) { }, }, } - logger := &application.LoggerConfig{ EnableStacktrace: true, Environment: "development", diff --git a/coniksauditor/config.go b/coniksauditor/config.go index b66bb82..d6c9804 100644 --- a/coniksauditor/config.go +++ b/coniksauditor/config.go @@ -1,14 +1,14 @@ package coniksauditor import ( + "encoding/json" "fmt" "io/ioutil" - "encoding/json" "github.com/BurntSushi/toml" "github.com/coniks-sys/coniks-go/crypto/sign" - "github.com/coniks-sys/coniks-go/utils" "github.com/coniks-sys/coniks-go/protocol" + "github.com/coniks-sys/coniks-go/utils" ) // DirectoryConfig contains the auditor's configuration needed to send a @@ -18,10 +18,10 @@ import ( // the server's address for receiving STR history requests. type DirectoryConfig struct { SignPubkeyPath string `toml:"sign_pubkey_path"` - SigningPubKey sign.PublicKey + SigningPubKey sign.PublicKey InitSTRPath string `toml:"init_str_path"` - InitSTR *protocol.DirSTR + InitSTR *protocol.DirSTR Address string `toml:"address"` } diff --git a/coniksauditor/encoding.go b/coniksauditor/encoding.go index dafd980..9f0de79 100644 --- a/coniksauditor/encoding.go +++ b/coniksauditor/encoding.go @@ -1,20 +1,20 @@ package coniksauditor import ( - "encoding/json" + "encoding/json" - "github.com/coniks-sys/coniks-go/protocol" + "github.com/coniks-sys/coniks-go/protocol" ) // CreateSTRRequestMsg returns a JSON encoding of // a protocol.STRHistoryRequest for the given (start, end) epoch // range. func CreateSTRRequestMsg(start, end uint64) ([]byte, error) { - return json.Marshal(&protocol.Request{ - Type: protocol.STRType, - Request: &protocol.STRHistoryRequest{ - StartEpoch: start, - EndEpoch: end, - }, - }) + return json.Marshal(&protocol.Request{ + Type: protocol.STRType, + Request: &protocol.STRHistoryRequest{ + StartEpoch: start, + EndEpoch: end, + }, + }) } diff --git a/utils/binutils/encoding.go b/utils/binutils/encoding.go index ffd8ba5..d85aa32 100644 --- a/utils/binutils/encoding.go +++ b/utils/binutils/encoding.go @@ -1,68 +1,68 @@ package binutils import ( - "encoding/json" + "encoding/json" - "github.com/coniks-sys/coniks-go/protocol" + "github.com/coniks-sys/coniks-go/protocol" ) // MarshalResponse returns a JSON encoding of the server's response. func MarshalResponse(response *protocol.Response) ([]byte, error) { - return json.Marshal(response) + return json.Marshal(response) } // UnmarshalResponse decodes the given message into a protocol.Response // according to the given request type t. The request types are integer // constants defined in the protocol package. func UnmarshalResponse(t int, msg []byte) *protocol.Response { - type Response struct { - Error protocol.ErrorCode - DirectoryResponse json.RawMessage - } - var res Response - if err := json.Unmarshal(msg, &res); err != nil { - return &protocol.Response{ - Error: protocol.ErrMalformedMessage, - } - } + type Response struct { + Error protocol.ErrorCode + DirectoryResponse json.RawMessage + } + var res Response + if err := json.Unmarshal(msg, &res); err != nil { + return &protocol.Response{ + Error: protocol.ErrMalformedMessage, + } + } - // DirectoryResponse is omitempty for the places - // where Error is in Errors - if res.DirectoryResponse == nil { - if !protocol.Errors[res.Error] { - return &protocol.Response{ - Error: protocol.ErrMalformedMessage, - } - } - return &protocol.Response{ - Error: res.Error, - } - } + // DirectoryResponse is omitempty for the places + // where Error is in Errors + if res.DirectoryResponse == nil { + if !protocol.Errors[res.Error] { + return &protocol.Response{ + Error: protocol.ErrMalformedMessage, + } + } + return &protocol.Response{ + Error: res.Error, + } + } - switch t { - case protocol.RegistrationType, protocol.KeyLookupType, protocol.KeyLookupInEpochType, protocol.MonitoringType: - response := new(protocol.DirectoryProof) - if err := json.Unmarshal(res.DirectoryResponse, &response); err != nil { - return &protocol.Response{ - Error: protocol.ErrMalformedMessage, - } - } - return &protocol.Response{ - Error: res.Error, - DirectoryResponse: response, - } - case protocol.AuditType, protocol.STRType: - response := new(protocol.STRHistoryRange) - if err := json.Unmarshal(res.DirectoryResponse, &response); err != nil { - return &protocol.Response{ - Error: protocol.ErrMalformedMessage, - } - } - return &protocol.Response{ - Error: res.Error, - DirectoryResponse: response, - } - default: - panic("Unknown request type") - } + switch t { + case protocol.RegistrationType, protocol.KeyLookupType, protocol.KeyLookupInEpochType, protocol.MonitoringType: + response := new(protocol.DirectoryProof) + if err := json.Unmarshal(res.DirectoryResponse, &response); err != nil { + return &protocol.Response{ + Error: protocol.ErrMalformedMessage, + } + } + return &protocol.Response{ + Error: res.Error, + DirectoryResponse: response, + } + case protocol.AuditType, protocol.STRType: + response := new(protocol.STRHistoryRange) + if err := json.Unmarshal(res.DirectoryResponse, &response); err != nil { + return &protocol.Response{ + Error: protocol.ErrMalformedMessage, + } + } + return &protocol.Response{ + Error: res.Error, + DirectoryResponse: response, + } + default: + panic("Unknown request type") + } } diff --git a/utils/binutils/encoding_test.go b/utils/binutils/encoding_test.go index 0a98b61..fb3c562 100644 --- a/utils/binutils/encoding_test.go +++ b/utils/binutils/encoding_test.go @@ -1,88 +1,88 @@ package binutils import ( - "bytes" - "encoding/json" - "testing" + "bytes" + "encoding/json" + "testing" - "github.com/coniks-sys/coniks-go/protocol" - "github.com/coniks-sys/coniks-go/protocol/directory" + "github.com/coniks-sys/coniks-go/protocol" + "github.com/coniks-sys/coniks-go/protocol/directory" ) func TestUnmarshalErrorResponse(t *testing.T) { - errResponse := protocol.NewErrorResponse(protocol.ErrMalformedMessage) - msg, err := json.Marshal(errResponse) - if err != nil { - t.Fatal(err) - } - res := UnmarshalResponse(protocol.RegistrationType, msg) - if res.Error != protocol.ErrMalformedMessage { - t.Error("Expect error", protocol.ErrMalformedMessage, - "got", res.Error) - } + errResponse := protocol.NewErrorResponse(protocol.ErrMalformedMessage) + msg, err := json.Marshal(errResponse) + if err != nil { + t.Fatal(err) + } + res := UnmarshalResponse(protocol.RegistrationType, msg) + if res.Error != protocol.ErrMalformedMessage { + t.Error("Expect error", protocol.ErrMalformedMessage, + "got", res.Error) + } } func TestUnmarshalErrorSTRHistoryResponse(t *testing.T) { - errResponse := protocol.NewErrorResponse(protocol.ErrAuditLog) - msg, err := json.Marshal(errResponse) - if err != nil { - t.Fatal(err) - } - res := UnmarshalResponse(protocol.AuditType, msg) - if res.Error != protocol.ErrAuditLog { - t.Error("Expect error", protocol.ErrAuditLog, - "got", res.Error) - } + errResponse := protocol.NewErrorResponse(protocol.ErrAuditLog) + msg, err := json.Marshal(errResponse) + if err != nil { + t.Fatal(err) + } + res := UnmarshalResponse(protocol.AuditType, msg) + if res.Error != protocol.ErrAuditLog { + t.Error("Expect error", protocol.ErrAuditLog, + "got", res.Error) + } } func TestUnmarshalMalformedDirectoryProof(t *testing.T) { - errResponse := protocol.NewErrorResponse(protocol.ReqNameNotFound) - msg, err := json.Marshal(errResponse) - if err != nil { - t.Fatal(err) - } - res := UnmarshalResponse(protocol.RegistrationType, msg) - if res.Error != protocol.ErrMalformedMessage { - t.Error("Expect error", protocol.ErrMalformedMessage, - "got", res.Error) - } + errResponse := protocol.NewErrorResponse(protocol.ReqNameNotFound) + msg, err := json.Marshal(errResponse) + if err != nil { + t.Fatal(err) + } + res := UnmarshalResponse(protocol.RegistrationType, msg) + if res.Error != protocol.ErrMalformedMessage { + t.Error("Expect error", protocol.ErrMalformedMessage, + "got", res.Error) + } } func TestUnmarshalMalformedSTRHistoryRange(t *testing.T) { - errResponse := protocol.NewErrorResponse(protocol.ReqNameNotFound) - msg, err := json.Marshal(errResponse) - if err != nil { - t.Fatal(err) - } - res := UnmarshalResponse(protocol.STRType, msg) - if res.Error != protocol.ErrMalformedMessage { - t.Error("Expect error", protocol.ErrMalformedMessage, - "got", res.Error) - } + errResponse := protocol.NewErrorResponse(protocol.ReqNameNotFound) + msg, err := json.Marshal(errResponse) + if err != nil { + t.Fatal(err) + } + res := UnmarshalResponse(protocol.STRType, msg) + if res.Error != protocol.ErrMalformedMessage { + t.Error("Expect error", protocol.ErrMalformedMessage, + "got", res.Error) + } } func TestUnmarshalSampleClientMessage(t *testing.T) { - d, _ := directory.NewTestDirectory(t, true) - res := d.Register(&protocol.RegistrationRequest{ - Username: "alice", - Key: []byte("key")}) - msg, _ := MarshalResponse(res) - response := UnmarshalResponse(protocol.RegistrationType, []byte(msg)) - str := response.DirectoryResponse.(*protocol.DirectoryProof).STR[0] - if !bytes.Equal(d.LatestSTR().Serialize(), str.Serialize()) { - t.Error("Cannot unmarshal Associate Data properly") - } + d, _ := directory.NewTestDirectory(t, true) + res := d.Register(&protocol.RegistrationRequest{ + Username: "alice", + Key: []byte("key")}) + msg, _ := MarshalResponse(res) + response := UnmarshalResponse(protocol.RegistrationType, []byte(msg)) + str := response.DirectoryResponse.(*protocol.DirectoryProof).STR[0] + if !bytes.Equal(d.LatestSTR().Serialize(), str.Serialize()) { + t.Error("Cannot unmarshal Associate Data properly") + } } func TestUnmarshalSampleAuditorMessage(t *testing.T) { - d, _ := directory.NewTestDirectory(t, true) - res := d.GetSTRHistory(&protocol.STRHistoryRequest{ - StartEpoch: uint64(0), - EndEpoch: uint64(1)}) - msg, _ := MarshalResponse(res) - response := UnmarshalResponse(protocol.STRType, []byte(msg)) - str := response.DirectoryResponse.(*protocol.STRHistoryRange).STR[0] - if !bytes.Equal(d.LatestSTR().Serialize(), str.Serialize()) { - t.Error("Cannot unmarshal Associate Data properly") - } + d, _ := directory.NewTestDirectory(t, true) + res := d.GetSTRHistory(&protocol.STRHistoryRequest{ + StartEpoch: uint64(0), + EndEpoch: uint64(1)}) + msg, _ := MarshalResponse(res) + response := UnmarshalResponse(protocol.STRType, []byte(msg)) + str := response.DirectoryResponse.(*protocol.STRHistoryRange).STR[0] + if !bytes.Equal(d.LatestSTR().Serialize(), str.Serialize()) { + t.Error("Cannot unmarshal Associate Data properly") + } }