1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

websocket: add Client.nonce_size field

This commit is contained in:
Delyan Angelov
2020-06-01 20:31:45 +03:00
parent 0c7bac4ba7
commit 328a235f94
2 changed files with 7 additions and 6 deletions

View File

@@ -42,11 +42,11 @@ fn create_key_challenge_response(seckey string) string {
return b64
}
fn get_nonce() string {
mut nonce := []byte{}
fn get_nonce(nonce_size int) string {
mut nonce := []byte{len: nonce_size, cap: nonce_size}
alphanum := '0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz'
for _ in 0 .. 18 {
nonce << alphanum[rand.next(61)]
for i in 0 .. nonce_size {
nonce[i] = alphanum[rand.next(61)]
}
return string(byteptr(nonce.data))
return tos(nonce.data, nonce.len).clone()
}