diff options
author | Piotr Szarmanski | 2022-09-23 12:53:43 +0200 |
---|---|---|
committer | Piotr Szarmanski | 2022-09-23 12:53:43 +0200 |
commit | 9ed9bd758871d2f01a3d19192e9808ce19925a16 (patch) | |
tree | 71302b122212261b8d87e139a622dd1e0d32bae8 | |
parent | 4d82ef18a8bb18317be3e089f432f95b6e5dbd4a (diff) |
Simplify octets-to-reference-pair
-rw-r--r-- | src/eris-decode.lisp | 12 | ||||
-rw-r--r-- | src/eris.lisp | 12 |
2 files changed, 11 insertions, 13 deletions
diff --git a/src/eris-decode.lisp b/src/eris-decode.lisp index 43f8db0..b660cae 100644 --- a/src/eris-decode.lisp +++ b/src/eris-decode.lisp @@ -86,7 +86,7 @@ fetched from a trusted party.") (flet ((find-last-reference (block) (loop for i from (1- (/ block-size 64)) downto 0 - for key-reference = (octets-to-reference-pair (subseq-shared block (* 64 i))) + for key-reference = (octets-to-reference-pair block (* 64 i)) unless (key-reference-null? key-reference) return (values key-reference i)))) (loop with position = 0 @@ -116,8 +116,8 @@ fetched from a trusted party.") (when (zerop next-pos) ;; if 1+ mod blocks results in a zero, then update the next block (process-block (cdr blocks) mod (1+ level))) (let ((kr (octets-to-reference-pair - (subseq-shared (data (cadr blocks)) - (the fixnum (* next-pos 64)))))) + (data (cadr blocks)) + (the fixnum (* next-pos 64))))) (setf (data current) (funcall get-block (reference kr) (key kr) (svref nonce-array level))))))) (process-block (reverse root) (/ block-size 64) 0) ;; process the blocks from level 0 up @@ -175,8 +175,8 @@ fetched from a trusted party.") until (eq nil (cdr blocks)) when (or update-tree (not (eq block-position (pos lower-block)))) do (let ((rk (octets-to-reference-pair - (subseq-shared (data (car blocks)) - (* 64 block-position))))) + (data (car blocks)) + (* 64 block-position)))) (when (key-reference-null? rk) (error 'eof :eof new-pos :position (pos stream))) (setf (data lower-block) (funcall get-block (reference rk) (key rk) (svref nonce-array (1- level))) @@ -221,7 +221,7 @@ cache." (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." - ;;(when (> level 0) (hash-check root (key root-reference-pair))) + (when (> level 0) (hash-check root (key root-reference-pair))) (case level ;; Treat level 0 blocks specially, since those are just a single buffer. (0 (let ((stream diff --git a/src/eris.lisp b/src/eris.lisp index c3bbe5f..b30c6a4 100644 --- a/src/eris.lisp +++ b/src/eris.lisp @@ -42,12 +42,10 @@ (replace buf (reference pair) :start1 start) (replace buf (key pair) :start1 (+ 32 start))) -(defun octets-to-reference-pair (octets) - (let ((key (make-array 32 :element-type '(unsigned-byte 8))) - (reference (make-array 32 :element-type '(unsigned-byte 8)))) - (replace reference octets) - (replace key octets :start2 32) - (make-instance 'reference-pair :key key :reference reference))) +(defun octets-to-reference-pair (octets &optional (start 0)) + (declare (type (simple-array (unsigned-byte 8)) octets)) + (make-instance 'reference-pair :key (subseq octets (+ 32 start) (+ 64 start)) + :reference (subseq octets start (+ 32 start)))) (defun compute-reference (block) @@ -124,7 +122,7 @@ (setf (level capability) (aref octets 1)) (setf (reference-pair capability) - (octets-to-reference-pair (subseq-shared octets 2))) + (octets-to-reference-pair octets 2)) capability)) (defun read-capability-to-urn (capability) |