From c4b44fb12108c0764d1fa4ef1c37f11a54379343 Mon Sep 17 00:00:00 2001 From: Piotr Szarmanski Date: Mon, 24 Oct 2022 10:50:11 +0200 Subject: Add hash-backend and update README. --- src/eris-decode.lisp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src/eris-decode.lisp') diff --git a/src/eris-decode.lisp b/src/eris-decode.lisp index ba20e9d..3d93312 100644 --- a/src/eris-decode.lisp +++ b/src/eris-decode.lisp @@ -218,19 +218,28 @@ hash-table is used, a (copy-seq) needs to be done on the return value of gethash. The keyword argument CACHE-CAPACITY indicates the amount of blocks stored in the -cache." +cache. It may be NIL to turn off caching entirely." (declare (type read-capability read-capability) (type function fetch-function) - (type integer cache-capacity)) + (type (or integer null) cache-capacity)) (with-slots (level block-size root-reference-pair) read-capability - (let* ((get-block (cached-lambda (:cache-class 'lru-cache - :capacity cache-capacity - :table (make-hash-table :size (1+ cache-capacity) :test #'equalp)) - (reference key &optional nonce) - (let* ((block (execute-fetch-function fetch-function reference))) - (unless block (error 'missing-block :reference reference)) - (hash-check block reference) - (decrypt-block block key nonce)))) + (let* ((get-block (if cache-capacity ;; handle caching + (cached-lambda (:cache-class 'lru-cache + :capacity cache-capacity + :table (make-hash-table :size (1+ cache-capacity) :test #'equalp)) + (reference key nonce) + (declare (type octet-vector reference key)) + (let ((block (execute-fetch-function fetch-function reference))) + (declare (type octet-vector block)) + (hash-check block reference) + (decrypt-block block key nonce))) + (lambda (reference key nonce) + (declare (type octet-vector reference key) + (optimize (debug 3))) + (let ((block (execute-fetch-function fetch-function reference))) + (declare (type octet-vector block)) + (hash-check block reference) + (decrypt-block block key nonce))))) (root (funcall get-block (reference root-reference-pair) (key root-reference-pair) (make-nonce level)))) ;; "Implementations MUST verify the key appearing in the read capability ;; if level of encoded content is larger than 0." -- cgit v1.2.3