Updated to minitasn1 3.0
[gnutls.git] / guile / tests / priorities.scm
blobfe4f4a8a653b92637b80e42a3df3b00e54e51001
1 ;;; GnuTLS --- Guile bindings for GnuTLS
2 ;;; Copyright (C) 2011-2012 Free Software Foundation, Inc.
3 ;;;
4 ;;; GnuTLS is free software; you can redistribute it and/or modify
5 ;;; it under the terms of the GNU General Public License as published by
6 ;;; the Free Software Foundation; either version 3 of the License, or
7 ;;; (at your option) any later version.
8 ;;;
9 ;;; GnuTLS is distributed in the hope that it will be useful,
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 ;;; GNU General Public License for more details.
13 ;;;
14 ;;; You should have received a copy of the GNU General Public License
15 ;;; along with GnuTLS-EXTRA; if not, write to the Free Software
16 ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17 ;;; USA.
19 ;;; Written by Ludovic Courtès <ludo@gnu.org>.
22 ;;;
23 ;;; Exercise the priority API of GnuTLS.
24 ;;;
26 (use-modules (gnutls)
27              (gnutls build tests)
28              (srfi srfi-1)
29              (srfi srfi-26))
31 (define %valid-priority-strings
32   ;; Valid priority strings (from the manual).
33   '("NONE:+VERS-TLS-ALL:+MAC-ALL:+RSA:+AES-128-CBC:+SIGN-ALL:+COMP-NULL"
34     "NORMAL:-ARCFOUR-128"
35     "SECURE:-VERS-SSL3.0:+COMP-DEFLATE"
36     "NONE:+VERS-TLS-ALL:+AES-128-CBC:+RSA:+SHA1:+COMP-NULL:+SIGN-RSA-SHA1"))
38 (define %invalid-priority-strings
39   ;; Invalid strings: the prefix and the suffix that leads to a parse error.
40   '(("" . "THIS-DOES-NOT-WORK")
41     ("NORMAL:" . "FAIL-HERE")
42     ("SECURE:-VERS-SSL3.0:" . "+FAIL-HERE")
43     ("NONE:+VERS-TLS-ALL:+AES-128-CBC:"
44      . "+FAIL-HERE:+SHA1:+COMP-NULL:+SIGN-RSA-SHA1")))
46 (run-test
48     (lambda ()
49       (let ((s (make-session connection-end/client)))
50         ;; We shouldn't have any exception with the valid priority strings.
51         (for-each (cut set-session-priorities! s <>)
52                   %valid-priority-strings)
54         (every (lambda (prefix+suffix)
55                  (let* ((prefix (car prefix+suffix))
56                         (suffix (cdr prefix+suffix))
57                         (pos    (string-length prefix))
58                         (string (string-append prefix suffix)))
59                    (catch 'gnutls-error
60                      (lambda ()
61                        (let ((s (make-session connection-end/client)))
62                          ;; The following call should raise an exception.
63                          (set-session-priorities! s string)
64                          #f))
65                      (lambda (key err function error-location . unused)
66                        (and (eq? key 'gnutls-error)
67                             (eq? err error/invalid-request)
68                             (eq? function 'set-session-priorities!)
69                             (= error-location pos))))))
70                %invalid-priority-strings))))