Skip to content

Commit 311b413

Browse files
committed
[new] Add utils to de/serialize public part of KeyChains
1 parent ac1cbf3 commit 311b413

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/taoensso/tempel.clj

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@
446446
?key-id (bytes/read-dynamic-?str in)]
447447
(enc/assoc-when
448448
{:kind :encrypted-keychain, :version 1,
449-
:keychain (keys/keychain-restore nil ba-kc-pub)}
449+
:keychain (keys/keychain-thaw nil ba-kc-pub)}
450450
:ba-aad ?ba-aad
451451
:key-id ?key-id
452452
:has-hmac? has-hmac?
@@ -1379,3 +1379,19 @@
13791379
(let [kc (keychain)
13801380
ba-signed (sign (as-ba "cnt") kc {:ba-aad (as-ba "aad")})]
13811381
(signed ba-signed kc {:return :map #_:_test})))
1382+
1383+
(defn keychain-freeze-public
1384+
"Takes a `KeyChain` and serializes any public keys it contains
1385+
to a storable byte[]. Returns the byte[].
1386+
1387+
Thaw (deserialize) output with: `keychain-thaw-public`."
1388+
^bytes [keychain]
1389+
(get (keys/keychain-freeze keychain) :ba-kc-pub))
1390+
1391+
(defn keychain-thaw-public
1392+
"Complement of `keychain-freeze-public`.
1393+
Takes a serialized byte[] of public keys and returns
1394+
a `KeyChain` that contains those public keys."
1395+
[ba-kc-pub] (keys/keychain-thaw nil ba-kc-pub))
1396+
1397+
(comment (let [kc (keychain)] (enc/submap? @kc @(keychain-thaw-public (keychain-freeze-public kc)))))

src/taoensso/tempel/keys.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@
265265
(delay (mkc-freeze m-keychain))
266266
?meta))
267267

268-
(defn keychain-restore
268+
(defn keychain-thaw
269269
"Thaws `KeyChain` from frozen byte[]s."
270270
([ba-kc-prv ba-kc-pub] (-keychain nil (mkc-thaw ba-kc-prv ba-kc-pub)))
271271
([ba-kc_ ] (-keychain nil (mkc-thaw ba-kc_))))
@@ -1162,7 +1162,7 @@
11621162
(let [?ba-kc-prv (bytes/read-dynamic-?ba in)
11631163
?ba-ucnt (bytes/read-dynamic-?ba in) ; User content
11641164
_ (df/read-resv! in)
1165-
keychain (keychain-restore ?ba-kc-prv ?ba-kc-pub)]
1165+
keychain (keychain-thaw ?ba-kc-prv ?ba-kc-pub)]
11661166

11671167
(case return
11681168
:keychain keychain

0 commit comments

Comments
 (0)