aboutsummaryrefslogtreecommitdiff
path: root/cas.scm
blob: e314cf982b758f0a4c22dabe97a69a6fae567f79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(define-module (cas)
  #:use-module (rnrs bytevectors)
  #:use-module (leveldb)
  #:use-module (srfi srfi-167)
  #:use-module (srfi srfi-26)
  #:use-module (srfi srfi-9)
  #:use-module (gcrypt hash)

  #:export (make-cas
            cas?
            cas-okvs

            cas-put!
            cas-get))

(define blake2b-256
  (cut bytevector-hash <> (hash-algorithm blake2b-256)))

(define-record-type <cas>
  (%make-cas okvs hash)
  cas?
  (okvs cas-okvs)
  (hash cas-hash))

(define* (make-cas okvs #:optional (hash blake2b-256))
  (%make-cas okvs hash))

(define (cas-put! cas bv)
  (let ((key (apply (cas-hash cas) (list bv))))
    (okvs-set! (cas-okvs cas) key bv)
    key))

(define (cas-get cas key)
  (okvs-ref (cas-okvs cas) key))