| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 import 'dart:convert'; |
| 6 | 7 |
| 7 import 'package:crypto/crypto.dart'; | 8 import 'package:crypto/crypto.dart'; |
| 8 | 9 |
| 9 import '../copy/web_socket_impl.dart'; | 10 import '../copy/web_socket_impl.dart'; |
| 10 | 11 |
| 11 /// This class is deprecated. | 12 /// This class is deprecated. |
| 12 /// | 13 /// |
| 13 /// Use the [`web_socket_channel`][web_socket_channel] package instead. | 14 /// Use the [`web_socket_channel`][web_socket_channel] package instead. |
| 14 /// | 15 /// |
| 15 /// [web_socket_channel]: https://pub.dartlang.org/packages/web_socket_channel | 16 /// [web_socket_channel]: https://pub.dartlang.org/packages/web_socket_channel |
| (...skipping 28 matching lines...) Expand all Loading... |
| 44 String get closeReason; | 45 String get closeReason; |
| 45 | 46 |
| 46 /// Signs a `Sec-WebSocket-Key` header sent by a WebSocket client as part of | 47 /// Signs a `Sec-WebSocket-Key` header sent by a WebSocket client as part of |
| 47 /// the [initial handshake]. | 48 /// the [initial handshake]. |
| 48 /// | 49 /// |
| 49 /// The return value should be sent back to the client in a | 50 /// The return value should be sent back to the client in a |
| 50 /// `Sec-WebSocket-Accept` header. | 51 /// `Sec-WebSocket-Accept` header. |
| 51 /// | 52 /// |
| 52 /// [initial handshake]: https://tools.ietf.org/html/rfc6455#section-4.2.2 | 53 /// [initial handshake]: https://tools.ietf.org/html/rfc6455#section-4.2.2 |
| 53 static String signKey(String key) { | 54 static String signKey(String key) { |
| 54 var hash = new SHA1(); | |
| 55 // We use [codeUnits] here rather than UTF-8-decoding the string because | 55 // We use [codeUnits] here rather than UTF-8-decoding the string because |
| 56 // [key] is expected to be base64 encoded, and so will be pure ASCII. | 56 // [key] is expected to be base64 encoded, and so will be pure ASCII. |
| 57 hash.add((key + webSocketGUID).codeUnits); | 57 return BASE64.encode(sha1.convert((key + webSocketGUID).codeUnits).bytes); |
| 58 return CryptoUtils.bytesToBase64(hash.close()); | |
| 59 } | 58 } |
| 60 | 59 |
| 61 /// Creates a new WebSocket handling messaging across an existing socket. | 60 /// Creates a new WebSocket handling messaging across an existing socket. |
| 62 /// | 61 /// |
| 63 /// Because this is HTTP-API-agnostic, the initial [WebSocket handshake][] | 62 /// Because this is HTTP-API-agnostic, the initial [WebSocket handshake][] |
| 64 /// must have already been completed on the socket before this is called. | 63 /// must have already been completed on the socket before this is called. |
| 65 /// | 64 /// |
| 66 /// If [stream] is also a [StreamSink] (for example, if it's a "dart:io" | 65 /// If [stream] is also a [StreamSink] (for example, if it's a "dart:io" |
| 67 /// `Socket`), it will be used for both sending and receiving data. Otherwise, | 66 /// `Socket`), it will be used for both sending and receiving data. Otherwise, |
| 68 /// it will be used for receiving data and [sink] will be used for sending it. | 67 /// it will be used for receiving data and [sink] will be used for sending it. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 89 /// Closes the web socket connection. | 88 /// Closes the web socket connection. |
| 90 /// | 89 /// |
| 91 /// [closeCode] and [closeReason] are the [close code][] and [reason][] sent | 90 /// [closeCode] and [closeReason] are the [close code][] and [reason][] sent |
| 92 /// to the remote peer, respectively. If they are omitted, the peer will see | 91 /// to the remote peer, respectively. If they are omitted, the peer will see |
| 93 /// a "no status received" code with no reason. | 92 /// a "no status received" code with no reason. |
| 94 /// | 93 /// |
| 95 /// [close code]: https://tools.ietf.org/html/rfc6455#section-7.1.5 | 94 /// [close code]: https://tools.ietf.org/html/rfc6455#section-7.1.5 |
| 96 /// [reason]: https://tools.ietf.org/html/rfc6455#section-7.1.6 | 95 /// [reason]: https://tools.ietf.org/html/rfc6455#section-7.1.6 |
| 97 Future close([int closeCode, String closeReason]); | 96 Future close([int closeCode, String closeReason]); |
| 98 } | 97 } |
| OLD | NEW |