From da0e1aa69defa7cbc87209966c751918f523f1fb Mon Sep 17 00:00:00 2001 From: Piotr Szarmanski Date: Sat, 5 Aug 2023 22:57:30 +0200 Subject: Encoder refactor, new tests and proper non-file stream handling --- src/backend.lisp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/backend.lisp') diff --git a/src/backend.lisp b/src/backend.lisp index 8d1405b..d2b81b2 100644 --- a/src/backend.lisp +++ b/src/backend.lisp @@ -27,11 +27,14 @@ "Using the BACKEND, return a stream that decodes the provided READ-CAPABILITY object.")) -(defgeneric store-data (input backend &key secret &allow-other-keys) +(defgeneric store-data (input backend &key secret block-size &allow-other-keys) (:documentation "Using the BACKEND, store the INPUT, which is either a stream or an octet vector. An additional 32-byte octet-vector SECRET can be provided in order to -protect the data from attacks against convergent encryption.")) +protect the data from attacks against convergent encryption. + +BLOCK-SIZE is by default 32kib, except if the input is a file or vector with a +size less than 16kib. It should be set either to 1024b or 32kib.")) ;; Default methods @@ -41,13 +44,15 @@ protect the data from attacks against convergent encryption.")) (with-slots (fetch-function) backend (eris-decode read-capability fetch-function))) -(defmethod store-data (input (backend encoding-backend) &key (secret null-secret) &allow-other-keys) +(defmethod store-data (input (backend encoding-backend) &key (secret null-secret) (block-size 32kib) &allow-other-keys) (declare (type octet-vector secret)) (with-slots (output-function) backend (eris-encode input ;; According to ERIS spec recommendation. (if (> (etypecase input - (stream (file-length input)) - (vector (length input))) + (pathname (file-size input)) + (file-stream (file-length input)) + (vector (length input)) + (t block-size)) 16384) 32kib 1kib) -- cgit v1.2.3