aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpukkamustard <pukkamustard@posteo.net>2020-11-27 13:00:43 +0100
committerpukkamustard <pukkamustard@posteo.net>2020-11-27 13:00:43 +0100
commita2866d438f77600e789c765593800f387703bf60 (patch)
tree44796569edcb5407b5e62968e5debcfd6b711d57
parent59e1becdb12f629debd284cc9bd3551553c5a10f (diff)
(eris): encode string, bytevector or content from port
-rw-r--r--doc/eris.adoc2
-rw-r--r--eris.scm15
-rw-r--r--tests/eris/pseudo-random.scm4
-rw-r--r--tests/eris/test-vectors.scm2
4 files changed, 15 insertions, 8 deletions
diff --git a/doc/eris.adoc b/doc/eris.adoc
index 441da3a..1056fb5 100644
--- a/doc/eris.adoc
+++ b/doc/eris.adoc
@@ -378,7 +378,7 @@ Transport mechanisms include:
- HTTP: A simple HTTP endpoint can be used to dereference blocks
- Sneakernet: Blocks can be transported on a physical medium such as a USB stick
-More interesting transport and storage layers use the fact that blocks are content-addressed. For example the peer-to-peer network https://ipfs.io/[IPFS] can be used to store and transport blocks (see the https://gitlab.com/openengiadina/eris/-/blob/main/eris/block-storage/ipfs.scm[example] using the reference Guile implementation). The major advantages over using IPFS directly include:
+More interesting transport and storage layers use the fact that blocks are content-addressed. For example the peer-to-peer network https://ipfs.io/[IPFS] can be used to store and transport blocks (see the https://gitlab.com/openengiadina/eris/-/blob/main/examples/ipfs.scm[example] using the reference Guile implementation). The major advantages over using IPFS directly include:
- Content is encrypted and not readable to IPFS peers without the read capability.
- Identifier of blocks and encoded content is not tied to the IPFS network. Applications can transparently use IPFS or any other storage/transport mechanism.
diff --git a/eris.scm b/eris.scm
index a8e407a..e3b1fcd 100644
--- a/eris.scm
+++ b/eris.scm
@@ -62,9 +62,16 @@ single pair consisting of the reduced blocks and the read capability"
((result) result)
((result input) input)))
+(define (->port readable)
+ "Helper to read content as port"
+ (cond
+ ((port? readable) readable)
+ ((bytevector? readable) (open-bytevector-input-port readable))
+ ((string? readable) (->port (string->utf8 readable)))))
+
;; Higher-level interfaces for encoding
-(define* (eris-encode port #:key
+(define* (eris-encode readable #:key
(block-reducer rcons)
(convergence-secret null-convergence-secret)
(block-size eris-block-size-small))
@@ -76,16 +83,16 @@ single pair consisting of the reduced blocks and the read capability"
(tstore-blocks block-reducer))
(rlast)
(lambda (port) (get-bytevector-n port block-size))
- port)))
+ (->port readable))))
(values (car read-capability-blocks)
(cdr read-capability-blocks))))
-(define* (eris-encode->urn port #:key
+(define* (eris-encode->urn readable #:key
(convergence-secret null-convergence-secret)
(block-size eris-block-size-small))
"Encode content, discard blocks and return the read capability as URN. This is useful for verifying that content is properly encoded."
(let-values (((read-capability block-count)
- (eris-encode port #:convergence-secret convergence-secret
+ (eris-encode readable #:convergence-secret convergence-secret
#:block-size block-size
#:block-reducer rcount)))
(read-capability->string read-capability)))
diff --git a/tests/eris/pseudo-random.scm b/tests/eris/pseudo-random.scm
index 27c7bd8..6a09b49 100644
--- a/tests/eris/pseudo-random.scm
+++ b/tests/eris/pseudo-random.scm
@@ -41,7 +41,7 @@
(let ((bv (pseudo-random-bytevector l)))
- (let-values (((urn blocks) (eris-encode (open-bytevector-input-port bv)
+ (let-values (((urn blocks) (eris-encode bv
#:block-reducer rcons
#:convergence-secret null-convergence-secret
#:block-size eris-block-size-small)))
@@ -78,7 +78,7 @@
(let ((bv (pseudo-random-bytevector l)))
- (let-values (((urn blocks) (eris-encode (open-bytevector-input-port bv)
+ (let-values (((urn blocks) (eris-encode bv
#:block-reducer rcons
#:convergence-secret null-convergence-secret
#:block-size eris-block-size-large)))
diff --git a/tests/eris/test-vectors.scm b/tests/eris/test-vectors.scm
index 8694cdd..0d2d8f4 100644
--- a/tests/eris/test-vectors.scm
+++ b/tests/eris/test-vectors.scm
@@ -38,7 +38,7 @@
(test-equal "content encodes to specified URN"
(test-vector-urn test-vector)
- (eris-encode->urn (open-bytevector-input-port (test-vector-content test-vector))
+ (eris-encode->urn (test-vector-content test-vector)
#:convergence-secret (test-vector-convergence-secret test-vector)
#:block-size (test-vector-block-size test-vector)))