Skip to content
Snippets Groups Projects
Unverified Commit b835e158 authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

openpgp: Add 'string->openpgp-packet'.

* guix/openpgp.scm (string->openpgp-packet): New procedure.
* tests/openpgp.scm ("verify-openpgp-signature, missing key")
("verify-openpgp-signature, good signatures")
("verify-openpgp-signature, bad signature"): Use it.
parent bd812655
No related branches found
No related tags found
No related merge requests found
...@@ -55,7 +55,8 @@ (define-module (guix openpgp) ...@@ -55,7 +55,8 @@ (define-module (guix openpgp)
lookup-key-by-fingerprint lookup-key-by-fingerprint
get-openpgp-keyring get-openpgp-keyring
read-radix-64) read-radix-64
string->openpgp-packet)
#:use-module (rnrs bytevectors) #:use-module (rnrs bytevectors)
#:use-module (rnrs io ports) #:use-module (rnrs io ports)
#:use-module (srfi srfi-1) #:use-module (srfi srfi-1)
...@@ -1067,3 +1068,9 @@ (define (skip-headers port) ...@@ -1067,3 +1068,9 @@ (define (skip-headers port)
(values #f kind))) (values #f kind)))
(loop (cons str lines)))))))) (loop (cons str lines))))))))
(values #f #f)))) (values #f #f))))
(define (string->openpgp-packet str)
"Read STR, an ASCII-armored OpenPGP packet, and return the corresponding
OpenPGP record."
(get-packet
(open-bytevector-input-port (call-with-input-string str read-radix-64))))
...@@ -194,10 +194,7 @@ (define %hello-signature/ed25519/sha1 ;digest-algo: sha1 ...@@ -194,10 +194,7 @@ (define %hello-signature/ed25519/sha1 ;digest-algo: sha1
(test-equal "verify-openpgp-signature, missing key" (test-equal "verify-openpgp-signature, missing key"
`(missing-key ,%rsa-key-fingerprint) `(missing-key ,%rsa-key-fingerprint)
(let* ((keyring (get-openpgp-keyring (%make-void-port "r"))) (let* ((keyring (get-openpgp-keyring (%make-void-port "r")))
(signature (get-openpgp-packet (signature (string->openpgp-packet %hello-signature/rsa)))
(open-bytevector-input-port
(call-with-input-string %hello-signature/rsa
read-radix-64)))))
(let-values (((status key) (let-values (((status key)
(verify-openpgp-signature signature keyring (verify-openpgp-signature signature keyring
(open-input-string "Hello!\n")))) (open-input-string "Hello!\n"))))
...@@ -214,10 +211,7 @@ (define %hello-signature/ed25519/sha1 ;digest-algo: sha1 ...@@ -214,10 +211,7 @@ (define %hello-signature/ed25519/sha1 ;digest-algo: sha1
(keyring (get-openpgp-keyring (keyring (get-openpgp-keyring
(open-bytevector-input-port (open-bytevector-input-port
(call-with-input-file key read-radix-64)))) (call-with-input-file key read-radix-64))))
(signature (get-openpgp-packet (signature (string->openpgp-packet signature)))
(open-bytevector-input-port
(call-with-input-string signature
read-radix-64)))))
(let-values (((status key) (let-values (((status key)
(verify-openpgp-signature signature keyring (verify-openpgp-signature signature keyring
(open-input-string "Hello!\n")))) (open-input-string "Hello!\n"))))
...@@ -246,10 +240,7 @@ (define %hello-signature/ed25519/sha1 ;digest-algo: sha1 ...@@ -246,10 +240,7 @@ (define %hello-signature/ed25519/sha1 ;digest-algo: sha1
"tests/ed25519.key" "tests/ed25519.key" "tests/ed25519.key" "tests/ed25519.key"
"tests/ed25519.key")))) "tests/ed25519.key"))))
(map (lambda (signature) (map (lambda (signature)
(let ((signature (get-openpgp-packet (let ((signature (string->openpgp-packet signature)))
(open-bytevector-input-port
(call-with-input-string signature
read-radix-64)))))
(let-values (((status key) (let-values (((status key)
(verify-openpgp-signature signature keyring (verify-openpgp-signature signature keyring
(open-input-string "What?!")))) (open-input-string "What?!"))))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment