summaryrefslogtreecommitdiff
path: root/src/scm/webid-oidc/errors.scm
diff options
context:
space:
mode:
authorVivien Kraus <vivien@planete-kraus.eu>2020-11-27 19:42:01 +0100
committerVivien Kraus <vivien@planete-kraus.eu>2021-06-19 15:44:24 +0200
commit57aea257548dbfbe0324baf7919d1fe29e91bb3d (patch)
treecffaa0a2cb0e9420d8873c9a3d4c538279928fa0 /src/scm/webid-oidc/errors.scm
parent6202ffc3fa4ffd0ab4f62535a0526792571f76e7 (diff)
Implement JWS encoding and decoding
Diffstat (limited to 'src/scm/webid-oidc/errors.scm')
-rw-r--r--src/scm/webid-oidc/errors.scm104
1 files changed, 104 insertions, 0 deletions
diff --git a/src/scm/webid-oidc/errors.scm b/src/scm/webid-oidc/errors.scm
index ad8fef3..e6c7a3e 100644
--- a/src/scm/webid-oidc/errors.scm
+++ b/src/scm/webid-oidc/errors.scm
@@ -104,6 +104,86 @@
(raise-exception
((record-constructor &invalid-signature) key payload signature)))
+(define-public &not-a-jws-header
+ (make-exception-type
+ '&not-a-jws-header
+ &external-error
+ '(value cause)))
+
+(define-public (raise-not-a-jws-header value cause)
+ (raise-exception
+ ((record-constructor &not-a-jws-header) value cause)))
+
+(define-public &not-a-jws-payload
+ (make-exception-type
+ '&not-a-jws-payload
+ &external-error
+ '(value cause)))
+
+(define-public (raise-not-a-jws-payload value cause)
+ (raise-exception
+ ((record-constructor &not-a-jws-payload) value cause)))
+
+(define-public &not-a-jws
+ (make-exception-type
+ '&not-a-jws
+ &external-error
+ '(value cause)))
+
+(define-public (raise-not-a-jws value cause)
+ (raise-exception
+ ((record-constructor &not-a-jws-payload) value cause)))
+
+(define-public &not-in-3-parts
+ (make-exception-type
+ '&not-in-3-parts
+ &external-error
+ '(string separator)))
+
+(define-public (raise-not-in-3-parts string separator)
+ (raise-exception
+ ((record-constructor &not-in-3-parts) string separator)))
+
+(define-public &missing-alist-key
+ (make-exception-type
+ '&missing-alist-key
+ &external-error
+ '(value key)))
+
+(define-public (raise-missing-alist-key value key)
+ (raise-exception
+ ((record-constructor &missing-alist-key) value key)))
+
+(define-public &no-matching-key
+ (make-exception-type
+ '&no-matching-key
+ &external-error
+ '(candidates alg payload signature other-problems)))
+
+(define-public (raise-no-matching-key candidates alg payload signature)
+ (raise-exception
+ ((record-constructor &no-matching-key) candidates alg payload signature)))
+
+(define-public &cannot-decode-jws
+ (make-exception-type
+ '&cannot-decode-jws
+ &external-error
+ '(value cause)))
+
+(define-public (raise-cannot-decode-jws value cause)
+ (raise-exception
+ ((record-constructor &cannot-decode-jws) value cause)))
+
+(define-public &cannot-encode-jws
+ (make-exception-type
+ '&cannot-encode-jws
+ &external-error
+ '(jws key cause)))
+
+(define-public (raise-cannot-encode-jws jws key cause)
+ (raise-exception
+ ((record-constructor &cannot-encode-jws) jws key cause)))
+
(define*-public (error->str err #:key (max-depth #f))
(if (record? err)
(let* ((type (record-type-descriptor err))
@@ -156,6 +236,30 @@
((&unsupported-alg)
(format #f (G_ "the value ~s does not identify a hash algorithm")
(get 'value)))
+ ((&missing-alist-key)
+ (format #f (G_ "the value ~s is not an alist or misses key ~s")
+ (get 'value) (get 'key)))
+ ((&not-a-jws-header)
+ (format #f (G_ "the value ~s is not a JWS header (because ~a)")
+ (get 'value) (recurse (get 'cause))))
+ ((&not-a-jws-payload)
+ (format #f (G_ "the value ~s is not a JWS payload (because ~a)")
+ (get 'value) (recurse (get 'cause))))
+ ((&not-a-jws)
+ (format #f (G_ "the value ~s is not a JWS (because ~a)")
+ (get 'value) (recurse (get 'cause))))
+ ((&not-in-3-parts)
+ (format #f (G_ "the string ~s cannot be split in 3 parts with ~s")
+ (get 'string) (get 'separator)))
+ ((&no-matching-key)
+ (format #f (G_ "all key candidates failed to verify signature ~s with algorithm ~s and payload ~a (there were ~a: ~s)")
+ (get 'signature) (get 'alg) (get 'payload) (length (get 'candidates)) (get 'candidates)))
+ ((&cannot-decode-jws)
+ (format #f (G_ "I cannot decode JWS ~a (because ~a)")
+ (get 'value) (recurse (get 'cause))))
+ ((&cannot-encode-jws)
+ (format #f (G_ "I cannot encode JWS ~a (because ~a)")
+ (get 'value) (recurse (get 'cause))))
((&compound-exception)
(let ((components (get 'components)))
(if (null? components)