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 <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
| 11 #include <memory> |
11 #include <string> | 12 #include <string> |
12 #include <vector> | 13 #include <vector> |
13 | 14 |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
15 #include "base/macros.h" | 16 #include "base/macros.h" |
16 #include "base/stl_util.h" | 17 #include "base/memory/ptr_util.h" |
17 #include "base/strings/string_piece.h" | 18 #include "base/strings/string_piece.h" |
18 #include "net/base/net_export.h" | 19 #include "net/base/net_export.h" |
19 #include "net/quic/core/crypto/crypto_protocol.h" | 20 #include "net/quic/core/crypto/crypto_protocol.h" |
20 | 21 |
21 namespace net { | 22 namespace net { |
22 | 23 |
23 // QuicServerConfigProtobuf contains QUIC server config block and the private | 24 // QuicServerConfigProtobuf contains QUIC server config block and the private |
24 // keys needed to prove ownership. | 25 // keys needed to prove ownership. |
25 // TODO(rch): sync with server more rationally. | 26 // TODO(rch): sync with server more rationally. |
26 class NET_EXPORT_PRIVATE QuicServerConfigProtobuf { | 27 class NET_EXPORT_PRIVATE QuicServerConfigProtobuf { |
(...skipping 13 matching lines...) Expand all Loading... |
40 std::string private_key_; | 41 std::string private_key_; |
41 }; | 42 }; |
42 | 43 |
43 QuicServerConfigProtobuf(); | 44 QuicServerConfigProtobuf(); |
44 ~QuicServerConfigProtobuf(); | 45 ~QuicServerConfigProtobuf(); |
45 | 46 |
46 size_t key_size() const { return keys_.size(); } | 47 size_t key_size() const { return keys_.size(); } |
47 | 48 |
48 const PrivateKey& key(size_t i) const { | 49 const PrivateKey& key(size_t i) const { |
49 DCHECK_GT(keys_.size(), i); | 50 DCHECK_GT(keys_.size(), i); |
50 return *keys_[i]; | 51 return *keys_[i].get(); |
51 } | 52 } |
52 | 53 |
53 std::string config() const { return config_; } | 54 std::string config() const { return config_; } |
54 | 55 |
55 void set_config(base::StringPiece config) { config.CopyToString(&config_); } | 56 void set_config(base::StringPiece config) { config.CopyToString(&config_); } |
56 | 57 |
57 QuicServerConfigProtobuf::PrivateKey* add_key() { | 58 QuicServerConfigProtobuf::PrivateKey* add_key() { |
58 keys_.push_back(new PrivateKey); | 59 keys_.push_back(base::MakeUnique<PrivateKey>()); |
59 return keys_.back(); | 60 return keys_.back().get(); |
60 } | 61 } |
61 | 62 |
62 void clear_key() { base::STLDeleteElements(&keys_); } | 63 void clear_key() { keys_.clear(); } |
63 | 64 |
64 bool has_primary_time() const { return primary_time_ > 0; } | 65 bool has_primary_time() const { return primary_time_ > 0; } |
65 | 66 |
66 int64_t primary_time() const { return primary_time_; } | 67 int64_t primary_time() const { return primary_time_; } |
67 | 68 |
68 void set_primary_time(int64_t primary_time) { primary_time_ = primary_time; } | 69 void set_primary_time(int64_t primary_time) { primary_time_ = primary_time; } |
69 | 70 |
70 bool has_priority() const { return priority_ > 0; } | 71 bool has_priority() const { return priority_ > 0; } |
71 | 72 |
72 uint64_t priority() const { return priority_; } | 73 uint64_t priority() const { return priority_; } |
73 | 74 |
74 void set_priority(int64_t priority) { priority_ = priority; } | 75 void set_priority(int64_t priority) { priority_ = priority; } |
75 | 76 |
76 bool has_source_address_token_secret_override() const { | 77 bool has_source_address_token_secret_override() const { |
77 return !source_address_token_secret_override_.empty(); | 78 return !source_address_token_secret_override_.empty(); |
78 } | 79 } |
79 | 80 |
80 std::string source_address_token_secret_override() const { | 81 std::string source_address_token_secret_override() const { |
81 return source_address_token_secret_override_; | 82 return source_address_token_secret_override_; |
82 } | 83 } |
83 | 84 |
84 void set_source_address_token_secret_override( | 85 void set_source_address_token_secret_override( |
85 base::StringPiece source_address_token_secret_override) { | 86 base::StringPiece source_address_token_secret_override) { |
86 source_address_token_secret_override.CopyToString( | 87 source_address_token_secret_override.CopyToString( |
87 &source_address_token_secret_override_); | 88 &source_address_token_secret_override_); |
88 } | 89 } |
89 | 90 |
90 private: | 91 private: |
91 std::vector<PrivateKey*> keys_; | 92 std::vector<std::unique_ptr<PrivateKey>> keys_; |
92 | 93 |
93 // config_ is a serialised config in QUIC wire format. | 94 // config_ is a serialised config in QUIC wire format. |
94 std::string config_; | 95 std::string config_; |
95 | 96 |
96 // primary_time_ contains a UNIX epoch seconds value that indicates when this | 97 // primary_time_ contains a UNIX epoch seconds value that indicates when this |
97 // config should become primary. | 98 // config should become primary. |
98 int64_t primary_time_; | 99 int64_t primary_time_; |
99 | 100 |
100 // Relative priority of this config vs other configs with the same | 101 // Relative priority of this config vs other configs with the same |
101 // primary time. For use as a secondary sort key when selecting the | 102 // primary time. For use as a secondary sort key when selecting the |
102 // primary config. | 103 // primary config. |
103 uint64_t priority_; | 104 uint64_t priority_; |
104 | 105 |
105 // Optional override to the secret used to box/unbox source address | 106 // Optional override to the secret used to box/unbox source address |
106 // tokens when talking to clients that select this server config. | 107 // tokens when talking to clients that select this server config. |
107 // It can be of any length as it is fed into a KDF before use. | 108 // It can be of any length as it is fed into a KDF before use. |
108 std::string source_address_token_secret_override_; | 109 std::string source_address_token_secret_override_; |
109 | 110 |
110 DISALLOW_COPY_AND_ASSIGN(QuicServerConfigProtobuf); | 111 DISALLOW_COPY_AND_ASSIGN(QuicServerConfigProtobuf); |
111 }; | 112 }; |
112 | 113 |
113 } // namespace net | 114 } // namespace net |
114 | 115 |
115 #endif // NET_QUIC_CRYPTO_CRYPTO_SERVER_CONFIG_PROTOBUF_H_ | 116 #endif // NET_QUIC_CRYPTO_CRYPTO_SERVER_CONFIG_PROTOBUF_H_ |
OLD | NEW |