Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: components/cryptauth/wire_message.cc

Issue 2561203002: Migrate weave-related classes from proximity_auth/ble to cryptauth/ble. (Closed)
Patch Set: Rebase. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/proximity_auth/wire_message.h" 5 #include "components/cryptauth/wire_message.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <limits> 10 #include <limits>
11 11
12 #include "base/base64url.h" 12 #include "base/base64url.h"
13 #include "base/json/json_reader.h" 13 #include "base/json/json_reader.h"
14 #include "base/json/json_writer.h" 14 #include "base/json/json_writer.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "components/proximity_auth/logging/logging.h" 18 #include "components/proximity_auth/logging/logging.h"
19 19
20 // The wire messages have a simple format: 20 // The wire messages have a simple format:
21 // [ message version ] [ body length ] [ JSON body ] 21 // [ message version ] [ body length ] [ JSON body ]
22 // 1 byte 2 bytes body length 22 // 1 byte 2 bytes body length
23 // The JSON body contains two fields: an optional permit_id field and a required 23 // The JSON body contains two fields: an optional permit_id field and a required
24 // data field. 24 // data field.
25 25
26 namespace proximity_auth { 26 namespace cryptauth {
27 namespace { 27 namespace {
28 28
29 // The length of the message header, in bytes. 29 // The length of the message header, in bytes.
30 const size_t kHeaderLength = 3; 30 const size_t kHeaderLength = 3;
31 31
32 // The protocol version of the message format. 32 // The protocol version of the message format.
33 const int kMessageFormatVersionThree = 3; 33 const int kMessageFormatVersionThree = 3;
34 34
35 const char kPayloadKey[] = "payload"; 35 const char kPayloadKey[] = "payload";
36 const char kPermitIdKey[] = "permit_id"; 36 const char kPermitIdKey[] = "permit_id";
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 << serialized_message.size() << ", expected " 69 << serialized_message.size() << ", expected "
70 << expected_message_length; 70 << expected_message_length;
71 return false; 71 return false;
72 } 72 }
73 73
74 return true; 74 return true;
75 } 75 }
76 76
77 } // namespace 77 } // namespace
78 78
79 WireMessage::~WireMessage() { 79 WireMessage::~WireMessage() {}
80 }
81 80
82 // static 81 // static
83 std::unique_ptr<WireMessage> WireMessage::Deserialize( 82 std::unique_ptr<WireMessage> WireMessage::Deserialize(
84 const std::string& serialized_message, 83 const std::string& serialized_message,
85 bool* is_incomplete_message) { 84 bool* is_incomplete_message) {
86 if (!ParseHeader(serialized_message, is_incomplete_message)) 85 if (!ParseHeader(serialized_message, is_incomplete_message))
87 return std::unique_ptr<WireMessage>(); 86 return std::unique_ptr<WireMessage>();
88 87
89 std::unique_ptr<base::Value> body_value = 88 std::unique_ptr<base::Value> body_value =
90 base::JSONReader::Read(serialized_message.substr(kHeaderLength)); 89 base::JSONReader::Read(serialized_message.substr(kHeaderLength));
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 return header_string + json_body; 161 return header_string + json_body;
163 } 162 }
164 163
165 WireMessage::WireMessage(const std::string& payload) 164 WireMessage::WireMessage(const std::string& payload)
166 : WireMessage(payload, std::string()) {} 165 : WireMessage(payload, std::string()) {}
167 166
168 WireMessage::WireMessage(const std::string& payload, 167 WireMessage::WireMessage(const std::string& payload,
169 const std::string& permit_id) 168 const std::string& permit_id)
170 : payload_(payload), permit_id_(permit_id) {} 169 : payload_(payload), permit_id_(permit_id) {}
171 170
172 } // namespace proximity_auth 171 } // namespace cryptauth
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698