| OLD | NEW |
| 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 #ifndef COMPONENTS_PROXIMITY_AUTH_WIRE_MESSAGE_H | 5 #ifndef COMPONENTS_PROXIMITY_AUTH_WIRE_MESSAGE_H |
| 6 #define COMPONENTS_PROXIMITY_AUTH_WIRE_MESSAGE_H | 6 #define COMPONENTS_PROXIMITY_AUTH_WIRE_MESSAGE_H |
| 7 | 7 |
| 8 #include <memory> |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 | 12 |
| 13 namespace proximity_auth { | 13 namespace proximity_auth { |
| 14 | 14 |
| 15 class WireMessage { | 15 class WireMessage { |
| 16 public: | 16 public: |
| 17 // Creates a WireMessage containing |payload|. | 17 // Creates a WireMessage containing |payload|. |
| 18 explicit WireMessage(const std::string& payload); | 18 explicit WireMessage(const std::string& payload); |
| 19 | 19 |
| 20 // Creates a WireMessage containing |payload| and |permit_id| in the metadata. | 20 // Creates a WireMessage containing |payload| and |permit_id| in the metadata. |
| 21 WireMessage(const std::string& payload, const std::string& permit_id); | 21 WireMessage(const std::string& payload, const std::string& permit_id); |
| 22 | 22 |
| 23 virtual ~WireMessage(); | 23 virtual ~WireMessage(); |
| 24 | 24 |
| 25 // Returns the deserialized message from |serialized_message|, or NULL if the | 25 // Returns the deserialized message from |serialized_message|, or NULL if the |
| 26 // message is malformed. Sets |is_incomplete_message| to true if the message | 26 // message is malformed. Sets |is_incomplete_message| to true if the message |
| 27 // does not have enough data to parse the header, or if the message length | 27 // does not have enough data to parse the header, or if the message length |
| 28 // encoded in the message header exceeds the size of the |serialized_message|. | 28 // encoded in the message header exceeds the size of the |serialized_message|. |
| 29 static scoped_ptr<WireMessage> Deserialize( | 29 static std::unique_ptr<WireMessage> Deserialize( |
| 30 const std::string& serialized_message, | 30 const std::string& serialized_message, |
| 31 bool* is_incomplete_message); | 31 bool* is_incomplete_message); |
| 32 | 32 |
| 33 // Returns a serialized representation of |this| message. | 33 // Returns a serialized representation of |this| message. |
| 34 virtual std::string Serialize() const; | 34 virtual std::string Serialize() const; |
| 35 | 35 |
| 36 const std::string& payload() const { return payload_; } | 36 const std::string& payload() const { return payload_; } |
| 37 const std::string& permit_id() const { return permit_id_; } | 37 const std::string& permit_id() const { return permit_id_; } |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 // The message payload. | 40 // The message payload. |
| 41 const std::string payload_; | 41 const std::string payload_; |
| 42 | 42 |
| 43 // Identifier of the permit being used. A permit contains the credentials used | 43 // Identifier of the permit being used. A permit contains the credentials used |
| 44 // to authenticate a device. For example, when sending a WireMessage to the | 44 // to authenticate a device. For example, when sending a WireMessage to the |
| 45 // remote device the |permit_id_| indexes a permit possibly containing the | 45 // remote device the |permit_id_| indexes a permit possibly containing the |
| 46 // public key | 46 // public key |
| 47 // of the local device or a symmetric key shared between the devices. | 47 // of the local device or a symmetric key shared between the devices. |
| 48 const std::string permit_id_; | 48 const std::string permit_id_; |
| 49 | 49 |
| 50 DISALLOW_COPY_AND_ASSIGN(WireMessage); | 50 DISALLOW_COPY_AND_ASSIGN(WireMessage); |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 } // namespace proximity_auth | 53 } // namespace proximity_auth |
| 54 | 54 |
| 55 #endif // COMPONENTS_PROXIMITY_AUTH_WIRE_MESSAGE_H | 55 #endif // COMPONENTS_PROXIMITY_AUTH_WIRE_MESSAGE_H |
| OLD | NEW |