kasi.el

This package provides an easy way to manage secrets via M-x kasi.
Log | Files | Refs | LICENSE

commit 4601077dcb28f21ca96e949d1840d1ba8188260d
parent a8ccce5a5fb60c896a24585292602d7edb92874e
Author: Vineet Kumar <git@vineetk.net>
Date:   Fri, 22 May 2026 15:05:16 -0400

add zero-padding to base32 decoding for odd-length totp secrets

Diffstat:
Mkasi-totp.el | 18+++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/kasi-totp.el b/kasi-totp.el @@ -5,8 +5,8 @@ ;; https://github.com/juergenhoetzel/emacs-totp ;; https://github.com/grimnebulin/emacs-hmac (require 'bindat) -(require 'hexl) (require 'cl-lib) +(require 'hexl) (require 'subr-x) (defconst hmac-algorithm-blocksizes @@ -56,17 +56,17 @@ string." "The cheats' version of base-32 decode. This is not a 100% faithful implementation of RFC 4648. The -concept of encoding partial quanta is not implemented fully. - -No attempt is made to pad the output either as that is not -required for HMAC-TOTP." +concept of encoding partial quanta is not implemented fully." (unless (mod (length string) 8) (error "Padding is incorrect")) (setq string (upcase string)) - (let ((trimmed-array (append (string-trim-right string "=+") nil))) - (format "%X" (seq-reduce - (lambda (acc char) (+ (ash acc 5) (aref base32-alphabet char))) - trimmed-array 0)))) + (let* ((trimmed-array (append (string-trim-right string "=+") nil)) + (hex (format "%X" (seq-reduce + (lambda (acc char) (+ (ash acc 5) (aref base32-alphabet char))) + trimmed-array 0)))) + (if (cl-oddp (length hex)) + (concat "0" hex) + hex))) (defun totp--hex-decode-string (string) "Hex-decode STRING and return the result as a unibyte string."