-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.clj
31 lines (24 loc) · 1.1 KB
/
core.clj
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
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/
(ns magnet.secrets-storage.core
(:require
[clojure.spec.alpha :as s]
[magnet.secrets-storage.util :refer [encode-base64 decode-base64 base64?]]))
(s/def ::crypt-key bytes?)
(s/def ::serialized-crypt-key base64?)
(defn serialize [encryption-key]
(encode-base64 encryption-key))
(s/fdef serialize
:args #(s/cat :encryption-key ::crypt-key)
:ret ::serialized-crypt-key)
(defn deserialize [encryption-key]
(decode-base64 encryption-key))
(s/fdef deserialize
:args #(s/cat :encryption-key ::serialized-crypt-key)
:ret ::crypt-key)
(defprotocol UserEncryptionKeyStore
"Abstraction for managing encryption keys used for PII encryption/decryption"
(get-key [this user-id] "Get encryption key of the user specified by user-id")
(put-key [this user-id encryption-key] "Put encryption key assigned to the user specified by user-id")
(delete-key [this user-id] "Delete encryption key assigned to user-id"))