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

Side by Side Diff: lib/src/channel.dart

Issue 1823123003: Add support for crypto 1.0.0.. (Closed) Base URL: git@github.com:dart-lang/web_socket_channel.git@master
Patch Set: Created 4 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
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:async/async.dart'; 7 import 'package:async/async.dart';
8 import 'package:crypto/crypto.dart'; 8 import 'package:crypto/crypto.dart';
9 import 'package:stream_channel/stream_channel.dart'; 9 import 'package:stream_channel/stream_channel.dart';
10 10
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 WebSocketSink get sink => new WebSocketSink._(_webSocket); 55 WebSocketSink get sink => new WebSocketSink._(_webSocket);
56 56
57 /// Signs a `Sec-WebSocket-Key` header sent by a WebSocket client as part of 57 /// Signs a `Sec-WebSocket-Key` header sent by a WebSocket client as part of
58 /// the [initial handshake][]. 58 /// the [initial handshake][].
59 /// 59 ///
60 /// The return value should be sent back to the client in a 60 /// The return value should be sent back to the client in a
61 /// `Sec-WebSocket-Accept` header. 61 /// `Sec-WebSocket-Accept` header.
62 /// 62 ///
63 /// [initial handshake]: https://tools.ietf.org/html/rfc6455#section-4.2.2 63 /// [initial handshake]: https://tools.ietf.org/html/rfc6455#section-4.2.2
64 static String signKey(String key) { 64 static String signKey(String key) {
65 var hash = new SHA1();
66 // We use [codeUnits] here rather than UTF-8-decoding the string because 65 // We use [codeUnits] here rather than UTF-8-decoding the string because
67 // [key] is expected to be base64 encoded, and so will be pure ASCII. 66 // [key] is expected to be base64 encoded, and so will be pure ASCII.
68 hash.add((key + webSocketGUID).codeUnits); 67 return BASE64.encode(sha1.convert((key + webSocketGUID).codeUnits).bytes);
69 return CryptoUtils.bytesToBase64(hash.close());
70 } 68 }
71 69
72 /// Creates a new WebSocket handling messaging across an existing [channel]. 70 /// Creates a new WebSocket handling messaging across an existing [channel].
73 /// 71 ///
74 /// This is a cross-platform constructor; it doesn't use either `dart:io` or 72 /// This is a cross-platform constructor; it doesn't use either `dart:io` or
75 /// `dart:html`. It's also HTTP-API-agnostic, which means that the initial 73 /// `dart:html`. It's also HTTP-API-agnostic, which means that the initial
76 /// [WebSocket handshake][] must have already been completed on the socket 74 /// [WebSocket handshake][] must have already been completed on the socket
77 /// before this is called. 75 /// before this is called.
78 /// 76 ///
79 /// [protocol] should be the protocol negotiated by this handshake, if any. 77 /// [protocol] should be the protocol negotiated by this handshake, if any.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 /// 109 ///
112 /// [closeCode] and [closeReason] are the [close code][] and [reason][] sent 110 /// [closeCode] and [closeReason] are the [close code][] and [reason][] sent
113 /// to the remote peer, respectively. If they are omitted, the peer will see 111 /// to the remote peer, respectively. If they are omitted, the peer will see
114 /// a "no status received" code with no reason. 112 /// a "no status received" code with no reason.
115 /// 113 ///
116 /// [close code]: https://tools.ietf.org/html/rfc6455#section-7.1.5 114 /// [close code]: https://tools.ietf.org/html/rfc6455#section-7.1.5
117 /// [reason]: https://tools.ietf.org/html/rfc6455#section-7.1.6 115 /// [reason]: https://tools.ietf.org/html/rfc6455#section-7.1.6
118 Future close([int closeCode, String closeReason]) => 116 Future close([int closeCode, String closeReason]) =>
119 _webSocket.close(closeCode, closeReason); 117 _webSocket.close(closeCode, closeReason);
120 } 118 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698