Skip to content

Commit

Permalink
[mod] Rename {:return :as-map} -> {:return :map}
Browse files Browse the repository at this point in the history
The "as" in `:as-map` is actually redundant and was there for historical
reasons that aren't relevant to a public release of this library.
  • Loading branch information
ptaoussanis committed Feb 1, 2024
1 parent dcacc74 commit 1931c7d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
20 changes: 10 additions & 10 deletions src/taoensso/tempel.clj
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@
(case return-kind
:ba-content ?ba-cnt
:ba-aad ?ba-aad
:as-map
:map
(enc/assoc-some {}
:ba-content ?ba-cnt
:ba-aad ?ba-aad)
Expand All @@ -474,7 +474,7 @@
:cnt (bytes/?utf8-ba->?str ?ba-cnt))

(enc/unexpected-arg! return-kind
{:expected #{:ba-content :ba-aad :as-map}
{:expected #{:ba-content :ba-aad :map}
:context context})))

(defn encrypt-with-password
Expand Down Expand Up @@ -563,7 +563,7 @@
Return value depends on `:return` option:
`:ba-content` - Returns decrypted byte[] content (default)
`:ba-aad` - Returns verified unencrypted embedded ?byte[] AAD
`:as-map` - Returns {:keys [ba-aad ba-content]} map
`:map` - Returns {:keys [ba-aad ba-content]} map
Takes a password (string, byte[], or char[]). Password will be \"stretched\"
using an appropriate \"Password-Based Key Derivation Function\" (PBKDF).
Expand Down Expand Up @@ -711,7 +711,7 @@
Return value depends on `:return` option:
`:ba-content` - Returns decrypted byte[] content (default)
`:ba-aad` - Returns verified unencrypted embedded ?byte[] AAD
`:as-map` - Returns {:keys [ba-aad ba-content]} map
`:map` - Returns {:keys [ba-aad ba-content]} map
Takes a `KeyChain` (see `keychain`) or byte[] key.
Will throw on decryption failure (bad key, etc.)."
Expand Down Expand Up @@ -919,7 +919,7 @@
Return value depends on `:return` option:
`:ba-content` - Returns decrypted byte[] content (default)
`:ba-aad` - Returns verified unencrypted embedded ?byte[] AAD
`:as-map` - Returns {:keys [ba-aad ba-content]} map
`:map` - Returns {:keys [ba-aad ba-content]} map
Takes a `KeyChain` (see `keychain`) or `KeyPair` (see `keypair-create`).
Key algorithm must support use as an asymmetric cipher.
Expand Down Expand Up @@ -1141,7 +1141,7 @@
Return value depends on `:return` option:
`:ba-content` - Returns decrypted byte[] content (default)
`:ba-aad` - Returns verified unencrypted embedded ?byte[] AAD
`:as-map` - Returns {:keys [ba-aad ba-content]} map
`:map` - Returns {:keys [ba-aad ba-content]} map
Takes `KeyChain`s (see `keychain`) and/or `KeyPair`s (see `keypair-create`).
Key algorithm must support key agreement.
Expand Down Expand Up @@ -1318,7 +1318,7 @@
Return value depends on `:return` option:
`:ba-content` - Returns verified ?byte[] content (when embedded)
`:ba-aad` - Returns verified ?byte[] AAD (when embedded)
`:as-map` - Returns {:keys [ba-aad ba-content]} map (default)
`:map` - Returns {:keys [ba-aad ba-content]} map (default)
Returns nil when verification fails.
Expand All @@ -1333,10 +1333,10 @@
{:arglists
'([ba-signed signer-key-pub &
[{:keys [ba-content return ba-akm]
:or {return :as-map}}]])}
:or {return :map}}]])}

[ba-signed signer-key-pub & [opts]]
(let [{:keys [ba-content return] :or {return :as-map}} opts
(let [{:keys [ba-content return] :or {return :map}} opts
{:keys [ba-akm] :as opts+}
(get-opts+ opts)]

Expand Down Expand Up @@ -1372,4 +1372,4 @@
(comment
(let [kc (keychain)
ba-signed (sign (as-ba "cnt") kc {:ba-aad (as-ba "aad")})]
(signed ba-signed kc {:return :as-map #_:_test})))
(signed ba-signed kc {:return :map #_:_test})))
20 changes: 10 additions & 10 deletions src/taoensso/tempel/keys.clj
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
Return value depends on `:return` option:
`:keychain` - Returns (possibly new) `KeyChain` (default)
`:as-map` - Returns {:keys [keychain changed? key-id]}"
`:map` - Returns {:keys [keychain changed? key-id]}"

[keychain x-key &
[{:keys [key-id priority return]
Expand All @@ -303,16 +303,16 @@

(case return
:keychain kc2
:as-map
:map
(enc/assoc-some
{:keychain keychain, :changed? (not (identical? kc1 kc2))}
:key-id @auto-key-id_)

(enc/unexpected-arg! return
{:expected #{:keychain :as-map}
{:expected #{:keychain :map}
:context `keychain-add-symmetric-key}))))

(comment (keychain-add-symmetric-key (keychain) :random {:return :as-map}))
(comment (keychain-add-symmetric-key (keychain) :random {:return :map}))

(defn ^:public keychain-add-asymmetric-keypair
"Produces a ?new `KeyChain` that contains the given asymmetric keypair.
Expand All @@ -324,7 +324,7 @@
Return value depends on `:return` option:
`:keychain` - Returns (possibly new) `KeyChain` (default)
`:as-map` - Returns {:keys [keychain changed? key-id]}
`:map` - Returns {:keys [keychain changed? key-id]}
And see `*config*` for details:
`keypair-creator`."
Expand Down Expand Up @@ -370,13 +370,13 @@

(case return
:keychain kc2
:as-map
:map
(enc/assoc-some
{:keychain keychain, :changed? (not (identical? kc1 kc2))}
:key-id @auto-key-id_)

(enc/unexpected-arg! return
{:expected #{:keychain :as-map}
{:expected #{:keychain :map}
:context `keychain-add-asymmetric-keypair}))))

(comment (keychain-add-asymmetric-keypair (keychain)
Expand Down Expand Up @@ -1068,7 +1068,7 @@
`:keychain` - Returns decrypted `KeyChain` (default)
`:ba-content` - Returns decrypted byte[] content
`:ba-aad` - Returns verified unencrypted embedded ?byte[] AAD
`:as-map` - Returns {:keys [keychain ba-aad ba-content]} map
`:map` - Returns {:keys [keychain ba-aad ba-content]} map
See `keychain-encrypt` for details.
See Tempel Wiki for detailed usage info, common patterns, examples, etc."
Expand Down Expand Up @@ -1167,7 +1167,7 @@
:keychain keychain
:ba-content ?ba-ucnt
:ba-aad ?ba-aad
:as-map
:map
(enc/assoc-some
{:keychain keychain}
:ba-content ?ba-ucnt
Expand All @@ -1180,7 +1180,7 @@
:cnt (bytes/?utf8-ba->?str ?ba-ucnt))

(enc/unexpected-arg! return
{:expected #{:keychain :ba-content :ba-aad :as-map}
{:expected #{:keychain :ba-content :ba-aad :map}
:context `keychain-decrypt})))))))))

(comment
Expand Down
4 changes: 2 additions & 2 deletions test/taoensso/tempel_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@
enc-backup-opts (when enc-backup-akm? {:ba-akm ba-enc-backup-akm})
dec-backup-opts (when enc-backup-akm? {:ba-akm (case dec-backup-akm* :good ba-enc-backup-akm :bad (impl/rand-ba 32) nil nil)})
enc-opts {:ba-akm ba-enc-akm :backup-key enc-backup-key :backup-opts enc-backup-opts :ba-aad ba-enc-aad :embed-hmac? embed-hmac?}
dec-opts {:ba-akm ba-dec-akm :backup-key dec-backup-key :backup-opts dec-backup-opts :return :as-map}
dec-opts {:ba-akm ba-dec-akm :backup-key dec-backup-key :backup-opts dec-backup-opts :return :map}

enc-result (try (enc-fn input enc-key enc-opts) (catch Throwable t {:error t}))
dec-result (try (dec-fn enc-result dec-key dec-opts) (catch Throwable t {:error t}))
Expand Down Expand Up @@ -734,7 +734,7 @@
(with-rand-data (mbytes 4) 256
(fn [ba-cnt ?ba-aad]
(let [ba-signed (sig ba-cnt kc1 {:ba-aad ?ba-aad})
verified (ver ba-signed kc1 {:return :as-map})]
verified (ver ba-signed kc1 {:return :map})]

[(is (bytes/?ba= ba-cnt (:ba-content verified)))
(is (bytes/?ba= ?ba-aad (:ba-aad verified)))])))]))])
Expand Down

0 comments on commit 1931c7d

Please sign in to comment.