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

Side by Side Diff: net/quic/crypto/crypto_protocol.h

Issue 12806002: Land Recent QUIC Changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor comment fix Created 7 years, 9 months 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/crypto/crypto_handshake.cc ('k') | net/quic/crypto/crypto_protocol.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_PROTOCOL_H_ 5 #ifndef NET_QUIC_CRYPTO_CRYPTO_PROTOCOL_H_
6 #define NET_QUIC_CRYPTO_CRYPTO_PROTOCOL_H_ 6 #define NET_QUIC_CRYPTO_CRYPTO_PROTOCOL_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "net/base/net_export.h" 14 #include "net/base/net_export.h"
15 #include "net/quic/quic_protocol.h" 15 #include "net/quic/quic_protocol.h"
16 #include "net/quic/quic_time.h" 16 #include "net/quic/quic_time.h"
17 17
18 namespace net { 18 namespace net {
19 19
20 // CryptoTag is the type of a tag in the wire protocol. 20 // CryptoTag is the type of a tag in the wire protocol.
21 typedef uint32 CryptoTag; 21 typedef uint32 CryptoTag;
22 typedef std::string ServerConfigID; 22 typedef std::string ServerConfigID;
23 typedef std::map<CryptoTag, std::string> CryptoTagValueMap; 23 typedef std::map<CryptoTag, std::string> CryptoTagValueMap;
24 typedef std::vector<CryptoTag> CryptoTagVector; 24 typedef std::vector<CryptoTag> CryptoTagVector;
25 // An intermediate format of a handshake message that's convenient for a
26 // CryptoFramer to serialize from or parse into.
27 struct NET_EXPORT_PRIVATE CryptoHandshakeMessage {
28 CryptoHandshakeMessage();
29 ~CryptoHandshakeMessage();
30
31 // SetValue sets an element with the given tag to the raw, memory contents of
32 // |v|.
33 template<class T> void SetValue(CryptoTag tag, const T& v) {
34 tag_value_map[tag] = std::string(reinterpret_cast<const char*>(&v),
35 sizeof(v));
36 }
37
38 // SetVector sets an element with the given tag to the raw contents of an
39 // array of elements in |v|.
40 template<class T> void SetVector(CryptoTag tag, const std::vector<T>& v) {
41 if (v.empty()) {
42 tag_value_map[tag] = std::string();
43 } else {
44 tag_value_map[tag] = std::string(reinterpret_cast<const char*>(&v[0]),
45 v.size() * sizeof(T));
46 }
47 }
48
49 // SetTaglist sets an element with the given tag to contain a list of tags,
50 // passed as varargs. The argument list must be terminated with a 0 element.
51 void SetTaglist(CryptoTag tag, ...);
52
53 // GetTaglist finds an element with the given tag containing zero or more
54 // tags. If such a tag doesn't exist, it returns false. Otherwise it sets
55 // |out_tags| and |out_len| to point to the array of tags and returns true.
56 // The array points into the CryptoHandshakeMessage and is valid only for as
57 // long as the CryptoHandshakeMessage exists and is not modified.
58 QuicErrorCode GetTaglist(CryptoTag tag, const CryptoTag** out_tags,
59 size_t* out_len) const;
60
61 bool GetStringPiece(CryptoTag tag, base::StringPiece* out) const;
62
63 // GetNthValue16 interprets the value with the given tag to be a series of
64 // 16-bit length prefixed values and it returns the subvalue with the given
65 // index.
66 QuicErrorCode GetNthValue16(CryptoTag tag,
67 unsigned index,
68 base::StringPiece* out) const;
69 bool GetString(CryptoTag tag, std::string* out) const;
70 QuicErrorCode GetUint16(CryptoTag tag, uint16* out) const;
71 QuicErrorCode GetUint32(CryptoTag tag, uint32* out) const;
72
73 CryptoTag tag;
74 CryptoTagValueMap tag_value_map;
75
76 private:
77 // GetPOD is a utility function for extracting a plain-old-data value. If
78 // |tag| exists in the message, and has a value of exactly |len| bytes then
79 // it copies |len| bytes of data into |out|. Otherwise |len| bytes at |out|
80 // are zeroed out.
81 //
82 // If used to copy integers then this assumes that the machine is
83 // little-endian.
84 QuicErrorCode GetPOD(CryptoTag tag, void* out, size_t len) const;
85 };
86 25
87 const CryptoTag kCHLO = MAKE_TAG('C', 'H', 'L', 'O'); // Client hello 26 const CryptoTag kCHLO = MAKE_TAG('C', 'H', 'L', 'O'); // Client hello
88 const CryptoTag kSHLO = MAKE_TAG('S', 'H', 'L', 'O'); // Server hello 27 const CryptoTag kSHLO = MAKE_TAG('S', 'H', 'L', 'O'); // Server hello
89 const CryptoTag kSCFG = MAKE_TAG('S', 'H', 'L', 'O'); // Server config 28 const CryptoTag kSCFG = MAKE_TAG('S', 'H', 'L', 'O'); // Server config
90 const CryptoTag kREJ = MAKE_TAG('R', 'E', 'J', '\0'); // Reject 29 const CryptoTag kREJ = MAKE_TAG('R', 'E', 'J', '\0'); // Reject
91 30
92 // Key exchange methods 31 // Key exchange methods
93 const CryptoTag kP256 = MAKE_TAG('P', '2', '5', '6'); // ECDH, Curve P-256 32 const CryptoTag kP256 = MAKE_TAG('P', '2', '5', '6'); // ECDH, Curve P-256
94 const CryptoTag kC255 = MAKE_TAG('C', '2', '5', '5'); // ECDH, Curve25519 33 const CryptoTag kC255 = MAKE_TAG('C', '2', '5', '5'); // ECDH, Curve25519
95 34
(...skipping 22 matching lines...) Expand all
118 const CryptoTag kPUBS = MAKE_TAG('P', 'U', 'B', 'S'); // Public key values 57 const CryptoTag kPUBS = MAKE_TAG('P', 'U', 'B', 'S'); // Public key values
119 const CryptoTag kSCID = MAKE_TAG('S', 'C', 'I', 'D'); // Server config id 58 const CryptoTag kSCID = MAKE_TAG('S', 'C', 'I', 'D'); // Server config id
120 59
121 const size_t kMaxEntries = 16; // Max number of entries in a message. 60 const size_t kMaxEntries = 16; // Max number of entries in a message.
122 61
123 const size_t kNonceSize = 32; // Size in bytes of the connection nonce. 62 const size_t kNonceSize = 32; // Size in bytes of the connection nonce.
124 63
125 } // namespace net 64 } // namespace net
126 65
127 #endif // NET_QUIC_CRYPTO_CRYPTO_PROTOCOL_H_ 66 #endif // NET_QUIC_CRYPTO_CRYPTO_PROTOCOL_H_
OLDNEW
« no previous file with comments | « net/quic/crypto/crypto_handshake.cc ('k') | net/quic/crypto/crypto_protocol.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698