diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2014-04-22 11:41:52 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2014-04-22 11:41:52 +0200 |
| commit | 6ef3644e3462d4a98323f556eefa92a6765ed437 (patch) | |
| tree | c540c4cebb281bfb516e87f73f9951e2995ffb2b | |
| parent | 6f69588529f9898dc4f2defd21603cc4abbaca17 (diff) | |
pk-crypto: Add pretty-printer to 'gcry-error' exceptions.
* guix/pk-crypto.scm (string->canonical-sexp, sign, generate-key): Pass
the procedure name as the first argument to 'throw'.
(gcrypt-error-printer): New procedure.
<top level>: Add call to 'set-exception-printer!'.
* guix/nar.scm (restore-one-item): Add 'proc' parameter to 'catch'
handler for 'gcry-error.
* guix/scripts/archive.scm (%options, generate-key-pair, authorize-key):
Likewise.
* guix/scripts/substitute-binary.scm (narinfo-signature->canonical-sexp):
Likewise.
| -rw-r--r-- | guix/nar.scm | 2 | ||||
| -rw-r--r-- | guix/pk-crypto.scm | 15 | ||||
| -rw-r--r-- | guix/scripts/archive.scm | 6 | ||||
| -rwxr-xr-x | guix/scripts/substitute-binary.scm | 2 |
4 files changed, 17 insertions, 8 deletions
diff --git a/guix/nar.scm b/guix/nar.scm index 6beda91c027..0a7187c2dd3 100644 --- a/guix/nar.scm +++ b/guix/nar.scm | |||
| @@ -370,7 +370,7 @@ protected from GC." | |||
| 370 | (let ((signature (catch 'gcry-error | 370 | (let ((signature (catch 'gcry-error |
| 371 | (lambda () | 371 | (lambda () |
| 372 | (string->canonical-sexp signature)) | 372 | (string->canonical-sexp signature)) |
| 373 | (lambda (err . _) | 373 | (lambda (key proc err) |
| 374 | (raise (condition | 374 | (raise (condition |
| 375 | (&message | 375 | (&message |
| 376 | (message "signature is not a valid \ | 376 | (message "signature is not a valid \ |
diff --git a/guix/pk-crypto.scm b/guix/pk-crypto.scm index 351bf929c55..71104128c16 100644 --- a/guix/pk-crypto.scm +++ b/guix/pk-crypto.scm | |||
| @@ -143,7 +143,7 @@ thrown along with 'gcry-error'." | |||
| 143 | (err (proc sexp (string->pointer str "ISO-8859-1") 0 1))) | 143 | (err (proc sexp (string->pointer str "ISO-8859-1") 0 1))) |
| 144 | (if (= 0 err) | 144 | (if (= 0 err) |
| 145 | (pointer->canonical-sexp (dereference-pointer sexp)) | 145 | (pointer->canonical-sexp (dereference-pointer sexp)) |
| 146 | (throw 'gcry-error err)))))) | 146 | (throw 'gcry-error 'string->canonical-sexp err)))))) |
| 147 | 147 | ||
| 148 | (define-syntax GCRYSEXP_FMT_ADVANCED | 148 | (define-syntax GCRYSEXP_FMT_ADVANCED |
| 149 | (identifier-syntax 3)) | 149 | (identifier-syntax 3)) |
| @@ -296,7 +296,7 @@ is 'private-key'.)" | |||
| 296 | (canonical-sexp->pointer secret-key)))) | 296 | (canonical-sexp->pointer secret-key)))) |
| 297 | (if (= 0 err) | 297 | (if (= 0 err) |
| 298 | (pointer->canonical-sexp (dereference-pointer sig)) | 298 | (pointer->canonical-sexp (dereference-pointer sig)) |
| 299 | (throw 'gry-error err)))))) | 299 | (throw 'gcry-error 'sign err)))))) |
| 300 | 300 | ||
| 301 | (define verify | 301 | (define verify |
| 302 | (let* ((ptr (libgcrypt-func "gcry_pk_verify")) | 302 | (let* ((ptr (libgcrypt-func "gcry_pk_verify")) |
| @@ -318,7 +318,7 @@ s-expression like: (genkey (rsa (nbits 4:2048)))." | |||
| 318 | (err (proc key (canonical-sexp->pointer params)))) | 318 | (err (proc key (canonical-sexp->pointer params)))) |
| 319 | (if (zero? err) | 319 | (if (zero? err) |
| 320 | (pointer->canonical-sexp (dereference-pointer key)) | 320 | (pointer->canonical-sexp (dereference-pointer key)) |
| 321 | (throw 'gcry-error err)))))) | 321 | (throw 'gcry-error 'generate-key err)))))) |
| 322 | 322 | ||
| 323 | (define find-sexp-token | 323 | (define find-sexp-token |
| 324 | (let* ((ptr (libgcrypt-func "gcry_sexp_find_token")) | 324 | (let* ((ptr (libgcrypt-func "gcry_sexp_find_token")) |
| @@ -403,4 +403,13 @@ use pattern matching." | |||
| 403 | 403 | ||
| 404 | (write sexp))))) | 404 | (write sexp))))) |
| 405 | 405 | ||
| 406 | (define (gcrypt-error-printer port key args default-printer) | ||
| 407 | "Print the gcrypt error specified by ARGS." | ||
| 408 | (match args | ||
| 409 | ((proc err) | ||
| 410 | (format port "In procedure ~a: ~a: ~a" | ||
| 411 | proc (error-source err) (error-string err))))) | ||
| 412 | |||
| 413 | (set-exception-printer! 'gcry-error gcrypt-error-printer) | ||
| 414 | |||
| 406 | ;;; pk-crypto.scm ends here | 415 | ;;; pk-crypto.scm ends here |
diff --git a/guix/scripts/archive.scm b/guix/scripts/archive.scm index 0a2e186da68..84904e29da1 100644 --- a/guix/scripts/archive.scm +++ b/guix/scripts/archive.scm | |||
| @@ -123,7 +123,7 @@ Export/import one or more packages from/to the store.\n")) | |||
| 123 | (string->canonical-sexp | 123 | (string->canonical-sexp |
| 124 | (or arg %key-generation-parameters)))) | 124 | (or arg %key-generation-parameters)))) |
| 125 | (alist-cons 'generate-key params result))) | 125 | (alist-cons 'generate-key params result))) |
| 126 | (lambda (key err) | 126 | (lambda (key proc err) |
| 127 | (leave (_ "invalid key generation parameters: ~a: ~a~%") | 127 | (leave (_ "invalid key generation parameters: ~a: ~a~%") |
| 128 | (error-source err) | 128 | (error-source err) |
| 129 | (error-string err)))))) | 129 | (error-string err)))))) |
| @@ -248,7 +248,7 @@ this may take time...~%")) | |||
| 248 | (let* ((pair (catch 'gcry-error | 248 | (let* ((pair (catch 'gcry-error |
| 249 | (lambda () | 249 | (lambda () |
| 250 | (generate-key parameters)) | 250 | (generate-key parameters)) |
| 251 | (lambda (key err) | 251 | (lambda (key proc err) |
| 252 | (leave (_ "key generation failed: ~a: ~a~%") | 252 | (leave (_ "key generation failed: ~a: ~a~%") |
| 253 | (error-source err) | 253 | (error-source err) |
| 254 | (error-string err))))) | 254 | (error-string err))))) |
| @@ -275,7 +275,7 @@ the input port." | |||
| 275 | (catch 'gcry-error | 275 | (catch 'gcry-error |
| 276 | (lambda () | 276 | (lambda () |
| 277 | (string->canonical-sexp (get-string-all (current-input-port)))) | 277 | (string->canonical-sexp (get-string-all (current-input-port)))) |
| 278 | (lambda (key err) | 278 | (lambda (key proc err) |
| 279 | (leave (_ "failed to read public key: ~a: ~a~%") | 279 | (leave (_ "failed to read public key: ~a: ~a~%") |
| 280 | (error-source err) (error-string err))))) | 280 | (error-source err) (error-string err))))) |
| 281 | 281 | ||
diff --git a/guix/scripts/substitute-binary.scm b/guix/scripts/substitute-binary.scm index 8e35612e3a0..c70a4f626c3 100755 --- a/guix/scripts/substitute-binary.scm +++ b/guix/scripts/substitute-binary.scm | |||
| @@ -252,7 +252,7 @@ failure." | |||
| 252 | (catch 'gcry-error | 252 | (catch 'gcry-error |
| 253 | (lambda () | 253 | (lambda () |
| 254 | (string->canonical-sexp signature)) | 254 | (string->canonical-sexp signature)) |
| 255 | (lambda (err . rest) | 255 | (lambda (key proc err) |
| 256 | (leave (_ "signature is not a valid \ | 256 | (leave (_ "signature is not a valid \ |
| 257 | s-expression: ~s~%") | 257 | s-expression: ~s~%") |
| 258 | signature)))))))) | 258 | signature)))))))) |
