@@ -5,7 +5,7 @@ use heapless::{String, Vec};
5
5
/// Websocket details extracted from the http header
6
6
pub struct WebSocketContext {
7
7
/// The list of sub protocols is restricted to a maximum of 3
8
- pub sec_websocket_protocol_list : Vec < WebSocketSubProtocol , U3 > ,
8
+ pub sec_websocket_protocol_list : Vec < WebSocketSubProtocol , 3 > ,
9
9
/// The websocket key user to build the accept string to complete the opening handshake
10
10
pub sec_websocket_key : WebSocketKey ,
11
11
}
@@ -40,7 +40,7 @@ pub struct WebSocketContext {
40
40
pub fn read_http_header < ' a > (
41
41
headers : impl Iterator < Item = ( & ' a str , & ' a [ u8 ] ) > ,
42
42
) -> Result < Option < WebSocketContext > > {
43
- let mut sec_websocket_protocol_list: Vec < String < U24 > , U3 > = Vec :: new ( ) ;
43
+ let mut sec_websocket_protocol_list: Vec < String < 24 > , 3 > = Vec :: new ( ) ;
44
44
let mut is_websocket_request = false ;
45
45
let mut sec_websocket_key = String :: new ( ) ;
46
46
@@ -130,13 +130,13 @@ pub fn build_connect_handshake_request(
130
130
rng : & mut impl RngCore ,
131
131
to : & mut [ u8 ] ,
132
132
) -> Result < ( usize , WebSocketKey ) > {
133
- let mut http_request: String < U1024 > = String :: new ( ) ;
133
+ let mut http_request: String < 1024 > = String :: new ( ) ;
134
134
let mut key_as_base64: [ u8 ; 24 ] = [ 0 ; 24 ] ;
135
135
136
136
let mut key: [ u8 ; 16 ] = [ 0 ; 16 ] ;
137
137
rng. fill_bytes ( & mut key) ;
138
- base64:: encode ( & key, & mut key_as_base64) ;
139
- let sec_websocket_key: String < U24 > = String :: from ( str:: from_utf8 ( & key_as_base64) ?) ;
138
+ base64:: encode_config_slice ( & key, base64 :: STANDARD , & mut key_as_base64) ;
139
+ let sec_websocket_key: String < 24 > = String :: from ( str:: from_utf8 ( & key_as_base64) ?) ;
140
140
141
141
http_request. push_str ( "GET " ) ?;
142
142
http_request. push_str ( websocket_options. path ) ?;
@@ -177,7 +177,7 @@ pub fn build_connect_handshake_response(
177
177
sec_websocket_protocol : Option < & WebSocketSubProtocol > ,
178
178
to : & mut [ u8 ] ,
179
179
) -> Result < usize > {
180
- let mut http_response: String < U1024 > = String :: new ( ) ;
180
+ let mut http_response: String < 1024 > = String :: new ( ) ;
181
181
http_response. push_str (
182
182
"HTTP/1.1 101 Switching Protocols\r \n \
183
183
Connection: Upgrade\r \n Upgrade: websocket\r \n ",
@@ -204,13 +204,14 @@ pub fn build_connect_handshake_response(
204
204
205
205
pub fn build_accept_string ( sec_websocket_key : & WebSocketKey , output : & mut [ u8 ] ) -> Result < ( ) > {
206
206
// concatenate the key with a known websocket GUID (as per the spec)
207
- let mut accept_string: String < U64 > = String :: new ( ) ;
207
+ let mut accept_string: String < 64 > = String :: new ( ) ;
208
208
accept_string. push_str ( sec_websocket_key) ?;
209
209
accept_string. push_str ( "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" ) ?;
210
210
211
211
// calculate the base64 encoded sha1 hash of the accept string above
212
- let sha1 = Sha1 :: from ( & accept_string) ;
213
- let input = sha1. digest ( ) . bytes ( ) ;
214
- base64:: encode ( & input, output) ; // no need for slices since the output WILL be 28 bytes
212
+ let mut sha1 = Sha1 :: new ( ) ;
213
+ sha1. update ( & accept_string) ;
214
+ let input = sha1. finalize ( ) ;
215
+ base64:: encode_config_slice ( & input, base64:: STANDARD , output) ; // no need for slices since the output WILL be 28 bytes
215
216
Ok ( ( ) )
216
217
}
0 commit comments