Increase length of magic id (decs. chance of accidental collision)
This commit is contained in:
parent
1d482b8893
commit
3e830a4b3a
3 changed files with 17 additions and 12 deletions
|
|
@ -2,7 +2,7 @@ Current [semantic](http://semver.org/) version:
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
[com.taoensso/nippy "1.2.1"] ; Stable
|
[com.taoensso/nippy "1.2.1"] ; Stable
|
||||||
[com.taoensso/nippy "2.0.0-alpha2"] ; Development (see notes below)
|
[com.taoensso/nippy "2.0.0-alpha3"] ; Development (see notes below)
|
||||||
```
|
```
|
||||||
|
|
||||||
2.x adds pluggable compression, crypto support (also pluggable), an improved API (including much better error messages), and hugely improved performance. It **is backwards compatible**, but please note that the `freeze-to-bytes`/`thaw-from-bytes` API has been **deprecated** in favor of `freeze`/`thaw`.
|
2.x adds pluggable compression, crypto support (also pluggable), an improved API (including much better error messages), and hugely improved performance. It **is backwards compatible**, but please note that the `freeze-to-bytes`/`thaw-from-bytes` API has been **deprecated** in favor of `freeze`/`thaw`.
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
(defproject com.taoensso/nippy "2.0.0-alpha2"
|
(defproject com.taoensso/nippy "2.0.0-alpha3"
|
||||||
:description "Clojure serialization library"
|
:description "Clojure serialization library"
|
||||||
:url "https://github.com/ptaoussanis/nippy"
|
:url "https://github.com/ptaoussanis/nippy"
|
||||||
:license {:name "Eclipse Public License"
|
:license {:name "Eclipse Public License"
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,14 @@
|
||||||
;; TODO Provide ToFreeze, Frozen, Encrypted, etc. tooling helpers
|
;; TODO Provide ToFreeze, Frozen, Encrypted, etc. tooling helpers
|
||||||
|
|
||||||
;;;; Header IDs
|
;;;; Header IDs
|
||||||
;; Nippy 2.x+ prefixes frozen data with a 5-byte header:
|
;; Nippy 2.x+ prefixes frozen data with a header:
|
||||||
|
(def ^:const header-len 6)
|
||||||
(def ^:const id-nippy-magic-prefix (byte 17))
|
(def ^:const id-nippy-magic-id1 (byte 17))
|
||||||
(def ^:const id-nippy-header-ver (byte 0))
|
(def ^:const id-nippy-magic-id2 (byte -42))
|
||||||
|
(def ^:const id-nippy-header-ver (byte 0))
|
||||||
;; * Compressor id (0 if no compressor)
|
;; * Compressor id (0 if no compressor)
|
||||||
;; * Encryptor id (0 if no encryptor)
|
;; * Encryptor id (0 if no encryptor)
|
||||||
(def ^:const id-nippy-reserved (byte 0))
|
(def ^:const id-nippy-reserved (byte 0))
|
||||||
|
|
||||||
;;;; Data type IDs
|
;;;; Data type IDs
|
||||||
|
|
||||||
|
|
@ -173,7 +174,8 @@
|
||||||
|
|
||||||
(defn- wrap-nippy-header [data-ba compressor encryptor password]
|
(defn- wrap-nippy-header [data-ba compressor encryptor password]
|
||||||
(let [header-ba (byte-array
|
(let [header-ba (byte-array
|
||||||
[id-nippy-magic-prefix
|
[id-nippy-magic-id1
|
||||||
|
id-nippy-magic-id2
|
||||||
id-nippy-header-ver
|
id-nippy-header-ver
|
||||||
(byte (if compressor (compression/header-id compressor) 0))
|
(byte (if compressor (compression/header-id compressor) 0))
|
||||||
(byte (if password (encryption/header-id encryptor) 0))
|
(byte (if password (encryption/header-id encryptor) 0))
|
||||||
|
|
@ -289,8 +291,11 @@
|
||||||
|
|
||||||
maybe-headers
|
maybe-headers
|
||||||
(fn []
|
(fn []
|
||||||
(when-let [[[id-magic* & _ :as headers] data-ba] (utils/ba-split ba 5)]
|
(when-let [[[id-mag1* id-mag2* & _ :as headers] data-ba]
|
||||||
(when (= id-magic* id-nippy-magic-prefix) ; Not a guarantee of correctness!
|
(utils/ba-split ba header-len)]
|
||||||
|
(when (and (= id-mag1* id-nippy-magic-id1)
|
||||||
|
(= id-mag2* id-nippy-magic-id2))
|
||||||
|
;; Not a guarantee of correctness!
|
||||||
[headers data-ba])))
|
[headers data-ba])))
|
||||||
|
|
||||||
legacy-thaw
|
legacy-thaw
|
||||||
|
|
@ -312,7 +317,7 @@
|
||||||
|
|
||||||
(if (= legacy-mode true)
|
(if (= legacy-mode true)
|
||||||
(legacy-thaw ba) ; Read as legacy, and only as legacy
|
(legacy-thaw ba) ; Read as legacy, and only as legacy
|
||||||
(if-let [[[_ id-header* id-comp* id-enc* _] data-ba] (maybe-headers)]
|
(if-let [[[_ _ id-hver* id-comp* id-enc* _] data-ba] (maybe-headers)]
|
||||||
(let [compressed? (not (zero? id-comp*))
|
(let [compressed? (not (zero? id-comp*))
|
||||||
encrypted? (not (zero? id-enc*))]
|
encrypted? (not (zero? id-enc*))]
|
||||||
|
|
||||||
|
|
@ -322,7 +327,7 @@
|
||||||
(catch Exception _ (legacy-thaw ba)))
|
(catch Exception _ (legacy-thaw ba)))
|
||||||
|
|
||||||
(cond ; Read as modern, and only as modern
|
(cond ; Read as modern, and only as modern
|
||||||
(> id-header* id-nippy-header-ver)
|
(> id-hver* id-nippy-header-ver)
|
||||||
(ex "Data frozen with newer Nippy version. Please upgrade.")
|
(ex "Data frozen with newer Nippy version. Please upgrade.")
|
||||||
|
|
||||||
(and strict? (not encrypted?) password)
|
(and strict? (not encrypted?) password)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue