Debian Codegraph @

guile/tests/list-pk-algorithms.scm

raw
1 ;;; GnuTLS --- Guile bindings for GnuTLS
2 ;;; Copyright (C) 2011-2025 Free Software Foundation, Inc.
3 ;;;
4 ;;; This file is part of Guile-GnuTLS.
5 ;;;
6 ;;; This program is free software: you can redistribute it and/or modify
7 ;;; it under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation, either version 3 of the License, or
9 ;;; (at your option) any later version.
10 ;;;
11 ;;; This program 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
14 ;;; GNU General Public License for more details.
15 ;;;
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19 ;; Check the public key algorithm inventory
20
21 (use-modules (gnutls)
22 (gnutls build tests))
23
24 (run-test
25 (lambda ()
26 (let ((all-algorithms (pk-algorithm-list)))
27 (for-each
28 (lambda (algo)
29 (unless algo
30 (error "gnutls lists more pk-algorithms than what gnutls-guile enumerates.")))
31 all-algorithms)
32 (unless (member (pk-algorithm->string pk-algorithm/ecdsa)
33 (map pk-algorithm->string all-algorithms))
34 (error "Not enough listed pk algorithms"))
35 (for-each
36 (lambda (algo)
37 (let* ((name (pk-algorithm->string algo))
38 (same-algo (string->pk-algorithm name))
39 (same-name (pk-algorithm->string same-algo)))
40 (unless (and (equal? algo same-algo)
41 (equal? name same-name))
42 (error "Inconsistent PK algorithm name")))
43 (let* ((oid (pk-algorithm->oid algo))
44 (same-algo (and oid (oid->pk-algorithm oid)))
45 (same-oid (and same-algo (pk-algorithm->oid same-algo))))
46 (when oid
47 (unless (and (equal? algo same-algo)
48 (equal? oid same-oid))
49 (error "Inconsistent PK oid"))))
50 (let ((sign-algorithm (pk-algorithm->sign-algorithm algo digest/sha256)))
51 (unless (or (not sign-algorithm)
52 (equal? sign-algorithm sign-algorithm/unknown))
53 (unless (sign-algorithm-supports? sign-algorithm algo)
54 (error "Inconsistent PK supported algorithms"))
55 (let ((any-pk (sign-algorithm->pk-algorithm sign-algorithm)))
56 (unless (sign-algorithm-supports? sign-algorithm any-pk)
57 (error "Inconsistent PK supported algorithms"))))))
58 all-algorithms))))