Add helpful thaw exceptions
This commit is contained in:
parent
611ab56b74
commit
9a38a12e11
3 changed files with 21 additions and 8 deletions
|
|
@ -2,7 +2,7 @@ Current [semantic](http://semver.org/) version:
|
|||
|
||||
```clojure
|
||||
[com.taoensso/nippy "1.2.1"] ; Stable
|
||||
[com.taoensso/nippy "1.3.0-alpha2"] ; Development (adds crypto support)
|
||||
[com.taoensso/nippy "1.3.0-alpha3"] ; Development (adds crypto support!)
|
||||
```
|
||||
|
||||
# Nippy, a Clojure serialization library
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
(defproject com.taoensso/nippy "1.3.0-alpha2"
|
||||
(defproject com.taoensso/nippy "1.3.0-alpha3"
|
||||
:description "Clojure serialization library"
|
||||
:url "https://github.com/ptaoussanis/nippy"
|
||||
:license {:name "Eclipse Public License"
|
||||
|
|
|
|||
|
|
@ -258,12 +258,25 @@
|
|||
:or {compressed? true
|
||||
read-eval? false ; For `read-string` injection safety - NB!!!
|
||||
}}]
|
||||
(-> (let [ba (if password (crypto/decrypt-aes128 password ba) ba)
|
||||
ba (if compressed? (utils/uncompress-bytes ba) ba)]
|
||||
ba)
|
||||
(ByteArrayInputStream.)
|
||||
(DataInputStream.)
|
||||
(thaw-from-stream! read-eval?)))
|
||||
(try
|
||||
(-> (let [ba (if password (crypto/decrypt-aes128 password ba) ba)
|
||||
ba (if compressed? (utils/uncompress-bytes ba) ba)]
|
||||
ba)
|
||||
(ByteArrayInputStream.)
|
||||
(DataInputStream.)
|
||||
(thaw-from-stream! read-eval?))
|
||||
(catch Exception e
|
||||
(throw (Exception.
|
||||
(cond password "Thaw failed. Unencrypted data or bad password?"
|
||||
compressed? "Thaw failed. Encrypted or uncompressed data?"
|
||||
:else "Thaw failed. Encrypted and/or compressed data?")
|
||||
e)))))
|
||||
|
||||
(comment
|
||||
(-> (freeze-to-bytes "my data" :password [:salted "password"])
|
||||
(thaw-from-bytes))
|
||||
(-> (freeze-to-bytes "my data" :compress? true)
|
||||
(thaw-from-bytes :compressed? false)))
|
||||
|
||||
(def stress-data
|
||||
"Reference data used for tests & benchmarks."
|
||||
|
|
|
|||
Loading…
Reference in a new issue