guix: Use guile-3.0.
[8sync.git] / 8sync / systems / websocket / utils.scm
1 ;;; guile-websocket --- WebSocket client/server
2 ;;; Copyright © 2016 David Thompson <davet@gnu.org>
3 ;;;
4 ;;; This file is part of guile-websocket.
5 ;;;
6 ;;; Guile-websocket is free software; you can redistribute it and/or modify
7 ;;; it under the terms of the GNU Lesser General Public License as
8 ;;; published by the Free Software Foundation; either version 3 of the
9 ;;; License, or (at your option) any later version.
10 ;;;
11 ;;; Guile-websocket is distributed in the hope that it will be useful,
12 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 ;;; Lesser General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU Lesser General Public
17 ;;; License along with guile-websocket.  If not, see
18 ;;; <http://www.gnu.org/licenses/>.
19
20 ;;; Commentary:
21 ;;
22 ;; WebSocket utilities.
23 ;;
24 ;;; Code:
25
26 (define-module (8sync systems websocket utils)
27   #:use-module (rnrs bytevectors)
28   #:use-module (8sync contrib base64)
29   #:use-module (8sync contrib sha-1)
30   #:export (%handshake-guid
31             make-accept-key))
32
33 ;; See section 1.3 - Opening Handshake
34 (define %handshake-guid "258EAFA5-E914-47DA-95CA-C5AB0DC85B11")
35
36 (define (make-accept-key client-key)
37   "Return a WebSocket accept key based on CLIENT-KEY, a base64 encoded
38 string."
39   (base64-encode
40    (sha-1->bytevector
41     (sha-1
42      (string->utf8
43       (string-append client-key %handshake-guid))))))