   (into #{} (keys digest-functions)))
 
 
+(defn- assert-valid-digest
+  [algorithm]
+  (when-not (digest-functions algorithm)
+    (throw (IllegalArgumentException.
+             (str "Unsupported digest algorithm: " algorithm
+                  ", must be one of " (string/join ", " digest-algorithms))))))
+
+
 
 ;; BLOB REFERENCE
 

(defn hash-content
  "Calculates the blob reference for the given content."
  [algorithm content]
  (let [hashfn (digest-functions algorithm)]
    (when-not hashfn
      (throw (IllegalArgumentException.
               (str "Unsupported digest algorithm: " algorithm
                    ", must be one of " (string/join ", " digest-algorithms)))))
    (BlobRef. algorithm (-> content hashfn .toLowerCase))))


(defn parse-address
  "Parses an address string into a blobref. Accepts either a hash URI or the
  shorter \"algo:address\" format."
  [address]
  (let [address (if (re-find #"^urn:" address) (subs address 4) address)
        address (if (re-find #"^hash:" address) (subs address 5) address)
        [algorithm digest] (string/split address #":" 2)]
    (BlobRef. (keyword algorithm) digest)))



     x
     (parse-address (str x))))
  ([algorithm digest]
   (assert-valid-digest algorithm)
   (BlobRef. algorithm digest)))
