From ba9b430deafb7ff933790b796633f1179ecc0eb0 Mon Sep 17 00:00:00 2001 From: Marcela M Date: Thu, 9 Nov 2017 11:53:55 -0500 Subject: [PATCH] Fix broken imports --- coniksauditor/config.go | 8 +- coniksauditor/encoding.go | 18 ++-- coniksbots/twitterbot.go | 5 +- coniksclient/cli/internal/cmd/run.go | 6 +- coniksserver/cli/internal/cmd/init.go | 3 +- coniksserver/server.go | 2 +- utils/binutils/encoding.go | 102 ++++++++++---------- utils/binutils/encoding_test.go | 130 +++++++++++++------------- 8 files changed, 138 insertions(+), 136 deletions(-) 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/coniksbots/twitterbot.go b/coniksbots/twitterbot.go index 57e7287..b75c1fc 100644 --- a/coniksbots/twitterbot.go +++ b/coniksbots/twitterbot.go @@ -13,6 +13,7 @@ import ( "github.com/BurntSushi/toml" "github.com/coniks-sys/coniks-go/coniksserver" "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" ) @@ -180,7 +181,7 @@ func (bot *TwitterBot) HandleRegistration(username string, msg []byte) string { } if invalid { log.Println("[registration bot] Malformed client request") - res, err := coniksserver.MarshalResponse( + res, err := binutils.MarshalResponse( protocol.NewErrorResponse(protocol.ErrMalformedMessage)) if err != nil { panic(err) @@ -192,7 +193,7 @@ func (bot *TwitterBot) HandleRegistration(username string, msg []byte) string { res, err := SendRequestToCONIKS(bot.coniksAddress, msg) if err != nil { log.Println("[registration bot] " + err.Error()) - res, err := coniksserver.MarshalResponse( + res, err := binutils.MarshalResponse( protocol.NewErrorResponse(protocol.ErrDirectory)) if err != nil { panic(err) diff --git a/coniksclient/cli/internal/cmd/run.go b/coniksclient/cli/internal/cmd/run.go index 91ed77e..0268519 100644 --- a/coniksclient/cli/internal/cmd/run.go +++ b/coniksclient/cli/internal/cmd/run.go @@ -11,7 +11,7 @@ import ( "github.com/coniks-sys/coniks-go/coniksserver/testutil" "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" ) @@ -139,7 +139,7 @@ func register(cc *client.ConsistencyChecks, conf *coniksclient.Config, name stri return ("Invalid config!") } - response := utils.UnmarshalResponse(protocol.RegistrationType, res) + response := binutils.UnmarshalResponse(protocol.RegistrationType, res) err = cc.HandleResponse(protocol.RegistrationType, response, name, []byte(key)) switch err { case protocol.CheckBadSTR: @@ -192,7 +192,7 @@ func keyLookup(cc *client.ConsistencyChecks, conf *coniksclient.Config, name str return ("Invalid config!") } - response := coniksclient.UnmarshalResponse(protocol.KeyLookupType, res) + response := binutils.UnmarshalResponse(protocol.KeyLookupType, res) if key, ok := cc.Bindings[name]; ok { err = cc.HandleResponse(protocol.KeyLookupType, response, name, []byte(key)) } else { diff --git a/coniksserver/cli/internal/cmd/init.go b/coniksserver/cli/internal/cmd/init.go index ef763bf..e2539b9 100644 --- a/coniksserver/cli/internal/cmd/init.go +++ b/coniksserver/cli/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" ) @@ -60,7 +61,7 @@ func mkConfig(dir string) { VRFKeyPath: "vrf.priv", SignKeyPath: "sign.priv", }, - Logger: &utils.LoggerConfig{ + Logger: &binutils.LoggerConfig{ EnableStacktrace: true, Environment: "development", Path: "coniksserver.log", diff --git a/coniksserver/server.go b/coniksserver/server.go index 9544a66..5797daa 100644 --- a/coniksserver/server.go +++ b/coniksserver/server.go @@ -31,7 +31,7 @@ type ServerConfig struct { // Policies contains the server's CONIKS policies configuration. Policies *ServerPolicies `toml:"policies"` // Addresses contains the server's connections configuration. - Addresses []*Address `toml:"addresses"` + Addresses []*Address `toml:"addresses"` Logger *binutils.LoggerConfig `toml:"logger"` configFilePath string } 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") + } }