Skip to content

Commit

Permalink
Fix broken imports
Browse files Browse the repository at this point in the history
  • Loading branch information
masomel committed Nov 9, 2017
1 parent fdbc483 commit ba9b430
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 136 deletions.
8 changes: 4 additions & 4 deletions coniksauditor/config.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"`
}
Expand Down
18 changes: 9 additions & 9 deletions coniksauditor/encoding.go
Original file line number Diff line number Diff line change
@@ -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,
},
})
}
5 changes: 3 additions & 2 deletions coniksbots/twitterbot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions coniksclient/cli/internal/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion coniksserver/cli/internal/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion coniksserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
102 changes: 51 additions & 51 deletions utils/binutils/encoding.go
Original file line number Diff line number Diff line change
@@ -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")
}
}
Loading

0 comments on commit ba9b430

Please sign in to comment.