OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 NET_QUIC_CRYPTO_CRYPTO_SERVER_CONFIG_PROTOBUF_H_ | 5 #ifndef NET_QUIC_CRYPTO_CRYPTO_SERVER_CONFIG_PROTOBUF_H_ |
6 #define NET_QUIC_CRYPTO_CRYPTO_SERVER_CONFIG_PROTOBUF_H_ | 6 #define NET_QUIC_CRYPTO_CRYPTO_SERVER_CONFIG_PROTOBUF_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
14 #include "net/base/net_export.h" | 14 #include "net/base/net_export.h" |
15 #include "net/quic/crypto/crypto_protocol.h" | 15 #include "net/quic/crypto/crypto_protocol.h" |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 | 18 |
19 // QuicServerConfigProtobuf contains QUIC server config block and the private | 19 // QuicServerConfigProtobuf contains QUIC server config block and the private |
20 // keys needed to prove ownership. | 20 // keys needed to prove ownership. |
21 // TODO(rch): sync with server more rationally. | 21 // TODO(rch): sync with server more rationally. |
22 class NET_EXPORT_PRIVATE QuicServerConfigProtobuf { | 22 class NET_EXPORT_PRIVATE QuicServerConfigProtobuf { |
23 public: | 23 public: |
24 // PrivateKey contains a QUIC tag of a key exchange algorithm and a | 24 // PrivateKey contains a QUIC tag of a key exchange algorithm and a |
25 // serialised private key for that algorithm. The format of the serialised | 25 // serialised private key for that algorithm. The format of the serialised |
26 // private key is specific to the algorithm in question. | 26 // private key is specific to the algorithm in question. |
27 class NET_EXPORT_PRIVATE PrivateKey { | 27 class NET_EXPORT_PRIVATE PrivateKey { |
28 public: | 28 public: |
29 QuicTag tag() const { | 29 QuicTag tag() const { return tag_; } |
30 return tag_; | 30 void set_tag(QuicTag tag) { tag_ = tag; } |
31 } | 31 std::string private_key() const { return private_key_; } |
32 void set_tag(QuicTag tag) { | 32 void set_private_key(std::string key) { private_key_ = key; } |
33 tag_ = tag; | |
34 } | |
35 std::string private_key() const { | |
36 return private_key_; | |
37 } | |
38 void set_private_key(std::string key) { | |
39 private_key_ = key; | |
40 } | |
41 | 33 |
42 private: | 34 private: |
43 QuicTag tag_; | 35 QuicTag tag_; |
44 std::string private_key_; | 36 std::string private_key_; |
45 }; | 37 }; |
46 | 38 |
47 QuicServerConfigProtobuf(); | 39 QuicServerConfigProtobuf(); |
48 ~QuicServerConfigProtobuf(); | 40 ~QuicServerConfigProtobuf(); |
49 | 41 |
50 size_t key_size() const { | 42 size_t key_size() const { return keys_.size(); } |
51 return keys_.size(); | |
52 } | |
53 | 43 |
54 const PrivateKey& key(size_t i) const { | 44 const PrivateKey& key(size_t i) const { |
55 DCHECK_GT(keys_.size(), i); | 45 DCHECK_GT(keys_.size(), i); |
56 return *keys_[i]; | 46 return *keys_[i]; |
57 } | 47 } |
58 | 48 |
59 std::string config() const { | 49 std::string config() const { return config_; } |
60 return config_; | |
61 } | |
62 | 50 |
63 void set_config(base::StringPiece config) { | 51 void set_config(base::StringPiece config) { config.CopyToString(&config_); } |
64 config.CopyToString(&config_); | |
65 } | |
66 | 52 |
67 QuicServerConfigProtobuf::PrivateKey* add_key() { | 53 QuicServerConfigProtobuf::PrivateKey* add_key() { |
68 keys_.push_back(new PrivateKey); | 54 keys_.push_back(new PrivateKey); |
69 return keys_.back(); | 55 return keys_.back(); |
70 } | 56 } |
71 | 57 |
72 void clear_key() { | 58 void clear_key() { STLDeleteElements(&keys_); } |
73 STLDeleteElements(&keys_); | |
74 } | |
75 | 59 |
76 bool has_primary_time() const { | 60 bool has_primary_time() const { return primary_time_ > 0; } |
77 return primary_time_ > 0; | |
78 } | |
79 | 61 |
80 int64 primary_time() const { | 62 int64 primary_time() const { return primary_time_; } |
81 return primary_time_; | |
82 } | |
83 | 63 |
84 void set_primary_time(int64 primary_time) { | 64 void set_primary_time(int64 primary_time) { primary_time_ = primary_time; } |
85 primary_time_ = primary_time; | |
86 } | |
87 | 65 |
88 bool has_priority() const { | 66 bool has_priority() const { return priority_ > 0; } |
89 return priority_ > 0; | |
90 } | |
91 | 67 |
92 uint64 priority() const { | 68 uint64 priority() const { return priority_; } |
93 return priority_; | |
94 } | |
95 | 69 |
96 void set_priority(int64 priority) { | 70 void set_priority(int64 priority) { priority_ = priority; } |
97 priority_ = priority; | |
98 } | |
99 | 71 |
100 bool has_source_address_token_secret_override() const { | 72 bool has_source_address_token_secret_override() const { |
101 return !source_address_token_secret_override_.empty(); | 73 return !source_address_token_secret_override_.empty(); |
102 } | 74 } |
103 | 75 |
104 std::string source_address_token_secret_override() const { | 76 std::string source_address_token_secret_override() const { |
105 return source_address_token_secret_override_; | 77 return source_address_token_secret_override_; |
106 } | 78 } |
107 | 79 |
108 void set_source_address_token_secret_override( | 80 void set_source_address_token_secret_override( |
(...skipping 21 matching lines...) Expand all Loading... |
130 // tokens when talking to clients that select this server config. | 102 // tokens when talking to clients that select this server config. |
131 // It can be of any length as it is fed into a KDF before use. | 103 // It can be of any length as it is fed into a KDF before use. |
132 std::string source_address_token_secret_override_; | 104 std::string source_address_token_secret_override_; |
133 | 105 |
134 DISALLOW_COPY_AND_ASSIGN(QuicServerConfigProtobuf); | 106 DISALLOW_COPY_AND_ASSIGN(QuicServerConfigProtobuf); |
135 }; | 107 }; |
136 | 108 |
137 } // namespace net | 109 } // namespace net |
138 | 110 |
139 #endif // NET_QUIC_CRYPTO_CRYPTO_SERVER_CONFIG_PROTOBUF_H_ | 111 #endif // NET_QUIC_CRYPTO_CRYPTO_SERVER_CONFIG_PROTOBUF_H_ |
OLD | NEW |