-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
138 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
Oops, something went wrong.