Skip to content

Commit

Permalink
Fix broken imports
Browse files Browse the repository at this point in the history
  • Loading branch information
masomel committed Dec 20, 2017
1 parent 5e39cbb commit dd36f26
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 131 deletions.
1 change: 1 addition & 0 deletions application/bots/twitterbot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion cli/coniksclient/internal/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion cli/coniksserver/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 @@ -53,7 +54,6 @@ func mkConfig(dir string) {
},
},
}

logger := &application.LoggerConfig{
EnableStacktrace: true,
Environment: "development",
Expand Down
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,
},
})
}
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")
}
}
130 changes: 65 additions & 65 deletions utils/binutils/encoding_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
}

0 comments on commit dd36f26

Please sign in to comment.