             [caesium.crypto.secretbox :as s]
             [caesium.randombytes :as r]
             [caesium.byte-bufs :as bb]
-            [caesium.util :as u]
-            [taoensso.timbre :refer [spy info]])
+            [caesium.util :as u])
   (:import (java.nio ByteBuffer)))
 
 (def keybytes s/keybytes)
+
+(defn ^:private split-pfx
+  [^ByteBuffer out]
+  (let [n (-> out (.duplicate) (.limit s/noncebytes))
+        c (-> out (.duplicate) (.position s/noncebytes))]
+    [n c]))
 
 (defn secretbox-pfx-to-buf!
   "Like [[secretbox-pfx]], but you manage the output buffer. See that fn for

  All buffers must be `java.nio.ByteBuffer`.

  Buffer `c` must be of length of `m` + [[s/noncebytes]] + [[s/macbytes]]."
  [^ByteBuffer c ^ByteBuffer m ^ByteBuffer n ^ByteBuffer k]
  (.put c n)
  (s/secretbox-easy-to-buf! c m n k))

(defn secretbox-pfx
  "secretbox, with the given nonce embedded in the ciphertext as a prefix.

  To decrypt, use [[decrypt]] or [[open]], depending on which argument order
  you prefer."
  [m n k]
  (let [out (bb/alloc (+ s/noncebytes (bb/buflen m) s/macbytes))]
    (secretbox-pfx-to-buf!
     out
     (bb/->indirect-byte-buf m)
     (bb/->indirect-byte-buf n)
     (bb/->indirect-byte-buf k))
    (bb/->bytes out)))

(defn ^:private random-nonce!
  "Creates a random nonce suitable for use in secretbox.
