diff options
Diffstat (limited to 'src/eris-decode.lisp')
-rw-r--r-- | src/eris-decode.lisp | 29 |
1 files changed, 19 insertions, 10 deletions
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." |