diff options
| -rw-r--r-- | kasi-totp.el | 4 | ||||
| -rw-r--r-- | kasi.el | 32 |
2 files changed, 18 insertions, 18 deletions
diff --git a/kasi-totp.el b/kasi-totp.el index f22c30c..5a54397 100644 --- a/kasi-totp.el +++ b/kasi-totp.el | |||
| @@ -86,8 +86,8 @@ concept of encoding partial quanta is not implemented fully." | |||
| 86 | (setq string (upcase string)) | 86 | (setq string (upcase string)) |
| 87 | (let* ((trimmed-array (append (string-trim-right string "=+") nil)) | 87 | (let* ((trimmed-array (append (string-trim-right string "=+") nil)) |
| 88 | (hex (format "%X" (seq-reduce | 88 | (hex (format "%X" (seq-reduce |
| 89 | (lambda (acc char) (+ (ash acc 5) (aref base32-alphabet char))) | 89 | (lambda (acc char) (+ (ash acc 5) (aref base32-alphabet char))) |
| 90 | trimmed-array 0)))) | 90 | trimmed-array 0)))) |
| 91 | (if (cl-oddp (length hex)) | 91 | (if (cl-oddp (length hex)) |
| 92 | (concat "0" hex) | 92 | (concat "0" hex) |
| 93 | hex))) | 93 | hex))) |
| @@ -91,23 +91,23 @@ Two %s are needed for password and username for now.") | |||
| 91 | (kasi--filename-short file))))) | 91 | (kasi--filename-short file))))) |
| 92 | 92 | ||
| 93 | (defun kasi--random-string (length charset) | 93 | (defun kasi--random-string (length charset) |
| 94 | "Generate a random string of LENGTH using characters from CHARSET. | 94 | "Generate a random string of LENGTH using characters from CHARSET. |
| 95 | Uses /dev/urandom for cryptographic security." | 95 | Uses /dev/urandom for cryptographic security." |
| 96 | ;; I have not seen any other built-in way to get cryptographically | 96 | ;; I have not seen any other built-in way to get cryptographically |
| 97 | ;; random outputs in Emacs. | 97 | ;; random outputs in Emacs. |
| 98 | (let* ((bytes (with-temp-buffer | 98 | (let* ((bytes (with-temp-buffer |
| 99 | (call-process "dd" nil (current-buffer) nil | 99 | (call-process "dd" nil (current-buffer) nil |
| 100 | "if=/dev/urandom" "bs=1" (format "count=%d" (* length 4))) | 100 | "if=/dev/urandom" "bs=1" (format "count=%d" (* length 4))) |
| 101 | (buffer-string))) | 101 | (buffer-string))) |
| 102 | (charset-len (length charset)) | 102 | (charset-len (length charset)) |
| 103 | (result "")) | 103 | (result "")) |
| 104 | (dotimes (i length) | 104 | (dotimes (i length) |
| 105 | (setq result (concat result | 105 | (setq result (concat result |
| 106 | (char-to-string | 106 | (char-to-string |
| 107 | (aref charset | 107 | (aref charset |
| 108 | (% (aref bytes i) | 108 | (% (aref bytes i) |
| 109 | charset-len)))))) | 109 | charset-len)))))) |
| 110 | result)) | 110 | result)) |
| 111 | 111 | ||
| 112 | ;; TODO implement some kind of validation of the sexp when saving | 112 | ;; TODO implement some kind of validation of the sexp when saving |
| 113 | (defun kasi--edit (file) | 113 | (defun kasi--edit (file) |
