Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decode msgpack and json consistently #566

Merged
merged 4 commits into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion sphinx/source/schemas/getQuotes_result.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
"type": "number"
},
"raw": {
"type": "string"
"items": {
"maximum": 255,
"minimum": 0,
"type": "number"
},
"type": "array"
}
},
"required": [
Expand Down
2 changes: 1 addition & 1 deletion src/node/nodestate.h
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ namespace ccf
{
GetQuotes::Quote quote;
quote.node_id = nid;
quote.raw = std::string(ni.quote.begin(), ni.quote.end());
quote.raw = ni.quote;

#ifdef GET_QUOTE
oe_report_t parsed_quote = {0};
Expand Down
4 changes: 2 additions & 2 deletions src/node/rpc/nodecalltypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ namespace ccf
struct Quote
{
NodeId node_id = {};
std::string raw = {};
std::vector<uint8_t> raw = {};

std::string error = {};
std::string mrenclave = {};
std::string mrenclave = {}; // < Hex-encoded
};

struct Out
Expand Down
2 changes: 1 addition & 1 deletion tests/governance.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def run(args):
assert len(quotes) == len(hosts)
primary_quote = quotes[0]
assert primary_quote["node_id"] == 0
mrenclave = primary_quote["mrenclave"].decode()
mrenclave = primary_quote["mrenclave"]

oed = subprocess.run(
[args.oesign, "dump", "-e", f"{args.package}.so.signed"],
Expand Down
19 changes: 3 additions & 16 deletions tests/infra/jsonrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,14 @@ def to_dict(self):
return d

def _from_parsed(self, parsed):
def decode(sl, is_key=False):
if is_key and hasattr(sl, "decode"):
return sl.decode()
if hasattr(sl, "items"):
return {decode(k, is_key=True): decode(v) for k, v in sl.items()}
elif isinstance(sl, list):
return [decode(e) for e in sl]
else:
return sl

parsed_s = {
decode(attr, is_key=True): decode(value) for attr, value in parsed.items()
}
unexpected = parsed_s.keys() - self._attrs
unexpected = parsed.keys() - self._attrs
if unexpected:
raise ValueError("Unexpected keys in response: {}".format(unexpected))
for attr, value in parsed_s.items():
for attr, value in parsed.items():
setattr(self, attr, value)

def from_msgpack(self, data):
parsed = msgpack.unpackb(data)
parsed = msgpack.unpackb(data, raw=False)
self._from_parsed(parsed)

def from_json(self, data):
Expand Down