ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / net / quic / quic_crypto_stream.cc
blob6d9358d3cd4ff7938206cdde23f01d1e29899598
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
3 // found in the LICENSE file.
5 #include "net/quic/quic_crypto_stream.h"
7 #include <string>
9 #include "base/strings/string_piece.h"
10 #include "net/quic/crypto/crypto_handshake.h"
11 #include "net/quic/crypto/crypto_utils.h"
12 #include "net/quic/quic_connection.h"
13 #include "net/quic/quic_session.h"
14 #include "net/quic/quic_utils.h"
16 using std::string;
17 using base::StringPiece;
19 namespace net {
21 #define ENDPOINT (session()->is_server() ? "Server: " : " Client: ")
23 QuicCryptoStream::QuicCryptoStream(QuicSession* session)
24 : ReliableQuicStream(kCryptoStreamId, session),
25 encryption_established_(false),
26 handshake_confirmed_(false) {
27 crypto_framer_.set_visitor(this);
28 // The crypto stream is exempt from connection level flow control.
29 DisableConnectionFlowControlForThisStream();
32 void QuicCryptoStream::OnError(CryptoFramer* framer) {
33 DLOG(WARNING) << "Error processing crypto data: "
34 << QuicUtils::ErrorToString(framer->error());
37 void QuicCryptoStream::OnHandshakeMessage(
38 const CryptoHandshakeMessage& message) {
39 DVLOG(1) << ENDPOINT << "Received " << message.DebugString();
40 session()->OnCryptoHandshakeMessageReceived(message);
43 uint32 QuicCryptoStream::ProcessRawData(const char* data,
44 uint32 data_len) {
45 if (!crypto_framer_.ProcessInput(StringPiece(data, data_len))) {
46 CloseConnection(crypto_framer_.error());
47 return 0;
49 return data_len;
52 QuicPriority QuicCryptoStream::EffectivePriority() const {
53 return QuicUtils::HighestPriority();
56 void QuicCryptoStream::SendHandshakeMessage(
57 const CryptoHandshakeMessage& message) {
58 SendHandshakeMessage(message, nullptr);
61 void QuicCryptoStream::SendHandshakeMessage(
62 const CryptoHandshakeMessage& message,
63 QuicAckNotifier::DelegateInterface* delegate) {
64 DVLOG(1) << ENDPOINT << "Sending " << message.DebugString();
65 session()->OnCryptoHandshakeMessageSent(message);
66 const QuicData& data = message.GetSerialized();
67 // TODO(wtc): check the return value.
68 WriteOrBufferData(string(data.data(), data.length()), false, delegate);
71 bool QuicCryptoStream::ExportKeyingMaterial(
72 StringPiece label,
73 StringPiece context,
74 size_t result_len,
75 string* result) const {
76 if (!handshake_confirmed()) {
77 DLOG(ERROR) << "ExportKeyingMaterial was called before forward-secure"
78 << "encryption was established.";
79 return false;
81 return CryptoUtils::ExportKeyingMaterial(
82 crypto_negotiated_params_.subkey_secret,
83 label,
84 context,
85 result_len,
86 result);
89 const QuicCryptoNegotiatedParameters&
90 QuicCryptoStream::crypto_negotiated_params() const {
91 return crypto_negotiated_params_;
94 } // namespace net