 
 ;; Multihash identifiers have two properties:
 ;;
-;; - `:code` is a numeric code for an algorithm entry in `digest-algorithms` or
-;;   an application-specific algorithm code.
+;; - `:code` is a numeric code for an algorithm entry in `algorithms` or an
+;;   application-specific algorithm code.
 ;; - `:digest` is a string holding the hex-encoded algorithm output.
 (deftype Multihash
   [^long code ^String digest _meta]


;; ## Hash Function Algorithms

(def ^:const digest-algorithms
  "Map of content hashing algorithms to system names and byte encodings."
  {:sha1     {:code 0x11, :length 20, :system "SHA-1"}
   :sha2-256 {:code 0x12, :length 32, :system "SHA-256"}

  code or a keyword name as the first argument. The digest may either by a byte
  array or a hex string."
  [algorithm digest]
  (let [code (:code (get-algorithm algorithm))
        digest (if (string? digest)
                 (bytes->hex (hex->bytes digest))
                 (bytes->hex digest))
        length (/ (count digest) 2)]
    (when-not (integer? code)
      (throw (IllegalArgumentException.
               (str "Algorithm argument " (pr-str algorithm) " does not "
                    "represent a valid hash algorithm."))))
    (when (< length 1)
      (throw (IllegalArgumentException.
               (str "Digest must contain at least one byte"))))
    (when (> length 127)
      (throw (IllegalArgumentException.
               (str "Digest exceeds maximum supported length of 127: "
                    length))))
    (Multihash. code digest nil)))


