Skip to content

Commit

Permalink
Switch from binascii to cl-base64
Browse files Browse the repository at this point in the history
binascii fails to compile on ECL, so making the switch to cl-base64
which works fine on ECL, SBCL and CCL.
  • Loading branch information
dnaeon committed Jul 11, 2023
1 parent 47ffdc9 commit 789ea28
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
8 changes: 4 additions & 4 deletions cl-ssh-keys.asd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:name "cl-ssh-keys"
:long-name "cl-ssh-keys"
:description "Common Lisp system for generating and parsing of OpenSSH keys"
:version "0.5.0"
:version "0.7.0"
:author "Marin Atanasov Nikolov <[email protected]>"
:maintainer "Marin Atanasov Nikolov <[email protected]>"
:license "BSD 2-Clause"
Expand All @@ -19,18 +19,18 @@
:ironclad
:uiop
:alexandria
:binascii)
:cl-base64)
:components ((:module "core"
:pathname #P"src/"
:components ((:file "package")
(:file "base" :depends-on ("package"))
(:file "base" :depends-on ("package"))
(:file "rfc8017" :depends-on ("package"))
(:file "generics" :depends-on ("package"))
(:file "public-key" :depends-on ("package"))
(:file "private-key" :depends-on ("package"))
(:file "conditions" :depends-on ("package"))
(:file "key-types" :depends-on ("package"))
(:file "signature" :depends-on ("package"))
(:file "signature" :depends-on ("package"))
(:file "ciphers" :depends-on ("package"))))
(:module "keys"
:pathname #P"src/"
Expand Down
1 change: 1 addition & 0 deletions src/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
(:import-from :cl-rfc4251)
(:import-from :uiop)
(:import-from :alexandria)
(:import-from :cl-base64)
(:export
;; base
:base-key
Expand Down
4 changes: 2 additions & 2 deletions src/private-key.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ If NIL is provided then encryption will be removed for the private key."
(let* ((s (rfc4251:make-binary-output-stream))
(size (rfc4251:encode :private-key key s))
(data (rfc4251:get-binary-stream-bytes s))
(encoded (binascii:encode-base64 data)))
(encoded (cl-base64:usb8-array-to-base64-string data)))
(declare (ignore size))
(format stream "~a~&" +private-key-mark-begin+)
(loop for char across encoded
Expand Down Expand Up @@ -435,7 +435,7 @@ BODY with VAR bound to the decoded private key"
"Parses an OpenSSH private key from the given plain-text string"
(let* ((s (make-string-input-stream text))
(extracted (extract-private-key s))
(decoded (binascii:decode-base64 extracted))
(decoded (cl-base64:base64-string-to-usb8-array extracted))
(stream (rfc4251:make-binary-input-stream decoded)))
(multiple-value-bind (key size) (rfc4251:decode :private-key stream :passphrase passphrase)
(declare (ignore size))
Expand Down
8 changes: 4 additions & 4 deletions src/public-key.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type name, when being embedded within a certificate."
(size (rfc4251:encode :public-key key stream))
(bytes (rfc4251:get-binary-stream-bytes stream))
(digest (ironclad:digest-sequence :sha1 bytes))
(encoded (binascii:encode-base64 digest))
(encoded (cl-base64:usb8-array-to-base64-string digest))
(trim-position (position #\= encoded :test #'char=))) ;; Trim padding characters
(declare (ignore size))
(subseq encoded 0 trim-position)))
Expand All @@ -130,7 +130,7 @@ type name, when being embedded within a certificate."
(size (rfc4251:encode :public-key key stream))
(bytes (rfc4251:get-binary-stream-bytes stream))
(digest (ironclad:digest-sequence :sha256 bytes))
(encoded (binascii:encode-base64 digest))
(encoded (cl-base64:usb8-array-to-base64-string digest))
(trim-position (position #\= encoded :test #'char=))) ;; Trim padding characters
(declare (ignore size))
(subseq encoded 0 trim-position)))
Expand All @@ -140,7 +140,7 @@ type name, when being embedded within a certificate."
(let* ((s (rfc4251:make-binary-output-stream))
(size (rfc4251:encode :public-key key s))
(data (rfc4251:get-binary-stream-bytes s))
(encoded (binascii:encode-base64 data))
(encoded (cl-base64:usb8-array-to-base64-string data))
(key-type-name (getf (key-kind key) :name))
(comment (key-comment key)))
(declare (ignore size))
Expand Down Expand Up @@ -170,7 +170,7 @@ BODY with VAR bound to the decoded public key"
;; OpenSSH public keys are encoded in a way, so that the
;; key kind preceeds the actual public key components.
;; See RFC 4253 for more details.
(let* ((stream (rfc4251:make-binary-input-stream (binascii:decode-base64 data)))
(let* ((stream (rfc4251:make-binary-input-stream (cl-base64:base64-string-to-usb8-array data)))
(key-type-name (getf key-type :name))
(encoded-key-type-name (rfc4251:decode :string stream)))
(unless (string= key-type-name encoded-key-type-name)
Expand Down

0 comments on commit 789ea28

Please sign in to comment.