(ns caesium.util
  "Internal utilities.

  This ns is not considered public API, and may break without semver
  major version increments."
  (:import (java.util Arrays)
           (org.apache.commons.codec.binary Hex)))

(defn unhexify
  [^String s]
  (.decode (Hex.) (.getBytes s)))

(defn hexify
  [b]
  (Hex/encodeHexString b))

(defn n->bytes
  "Turns n into a byte array of length len."
  [len n]
  (let [unpadded (.toByteArray (biginteger n))
        bytelen (alength unpadded)
        output (byte-array len)]
    (System/arraycopy unpadded 0 output (- len bytelen) bytelen)
    output))

(ns caesium.util
  "Internal utilities.

  This ns is not considered public API, and may break without semver
  major version increments."
  (:import (java.util Arrays)
           (org.apache.commons.codec.binary Hex)))

(defn unhexify
  [^String s]
  (.decode (Hex.) (.getBytes s)))

(defn hexify
  [^bytes b]
  (Hex/encodeHexString b))

(defn n->bytes
  "Turns n into a byte array of length len."
  [len n]
  (let [unpadded (.toByteArray (biginteger n))
        bytelen (alength unpadded)
        output (byte-array len)]
    (System/arraycopy unpadded 0 output (- len bytelen) bytelen)
    output))

Fix a reflection warning on a static method argument type
Fix a reflection warning on a static method argument type

eastwood said: "Reflection warning - call to static method
encodeHexString on org.apache.commons.codec.binary.Hex can't be
resolved (argument types: unknown)."

The `encodeHexString` method has several variants for different
argument types. Looking through the codebase it doesn't seem we
use the `hexify` method for anything but the bytes, so it's safe
to add a type hint here and get rid of the warning.

lvh/caesium