zone.lisp: Allow pathnames as input to `:sshfp' records.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 22 Dec 2014 20:32:58 +0000 (20:32 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Tue, 23 Dec 2014 11:57:35 +0000 (11:57 +0000)
zone.lisp

index e43e017..841d62a 100644 (file)
--- a/zone.lisp
+++ b/zone.lisp
 
 (defzoneparse :sshfp (name data rec)
   ":sshfp { FILENAME | ((FPR :alg ALG :type HASH)*) }"
-  (if (stringp data)
-      (with-open-file (in (merge-pathnames data *sshfp-pathname-defaults*))
-       (loop (let ((line (read-line in nil)))
-               (unless line (return))
-               (let ((words (str-split-words line)))
-                 (pop words)
-                 (when (string= (car words) "IN") (pop words))
-                 (unless (and (string= (car words) "SSHFP")
-                              (= (length words) 4))
-                   (error "Invalid SSHFP record."))
-                 (pop words)
-                 (destructuring-bind (alg type fpr) words
-                   (rec :data (list (parse-integer alg)
-                                    (parse-integer type)
-                                    fpr)))))))
-      (dolist (item (listify data))
-       (destructuring-bind (fpr &key (alg 'rsa) (type 'sha-1))
-           (listify item)
-         (rec :data (list (lookup-enum alg 'sshfp-algorithm :min 0 :max 255)
-                          (lookup-enum type 'sshfp-type :min 0 :max 255)
-                          fpr))))))
+  (typecase data
+    ((or string pathname)
+     (with-open-file (in (merge-pathnames data *sshfp-pathname-defaults*))
+       (loop (let ((line (read-line in nil)))
+              (unless line (return))
+              (let ((words (str-split-words line)))
+                (pop words)
+                (when (string= (car words) "IN") (pop words))
+                (unless (and (string= (car words) "SSHFP")
+                             (= (length words) 4))
+                  (error "Invalid SSHFP record."))
+                (pop words)
+                (destructuring-bind (alg type fpr) words
+                  (rec :data (list (parse-integer alg)
+                                   (parse-integer type)
+                                   fpr))))))))
+    (t
+     (dolist (item (listify data))
+       (destructuring-bind (fpr &key (alg 'rsa) (type 'sha-1))
+          (listify item)
+        (rec :data (list (lookup-enum alg 'sshfp-algorithm :min 0 :max 255)
+                         (lookup-enum type 'sshfp-type :min 0 :max 255)
+                         fpr)))))))
 
 (defmethod zone-record-rrdata ((type (eql :sshfp)) zr)
   (destructuring-bind (alg type fpr) (zr-data zr)