emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/base32 49cb6d5468 078/103: Implement the base32hex encodin


From: ELPA Syncer
Subject: [nongnu] elpa/base32 49cb6d5468 078/103: Implement the base32hex encoding from RFC4648
Date: Sat, 10 Feb 2024 13:00:10 -0500 (EST)

branch: elpa/base32
commit 49cb6d5468d0e06badaa9ab2458c636110f13081
Author: Vivek Das Mohapatra <vivek@collabora.com>
Commit: Vivek Das Mohapatra <vivek@collabora.com>

    Implement the base32hex encoding from RFC4648
    
    Mechanically this is a base32 encoding witha slightly different
    dictionary but RFC4648 indicates it should _not_ be considered a
    base32 encoding, nor should it be called base32.
    
    It should be called base32hex.
---
 base32.el | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/base32.el b/base32.el
index 5ef61d9c11..1e4304b214 100644
--- a/base32.el
+++ b/base32.el
@@ -20,6 +20,12 @@
 possible 5bit value (0-31) at that index, plus a padding character
 at index 32.")
 
+(defconst base32-hex-dictionary
+  [?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?A ?B ?C ?D ?E ?F
+   ?G ?H ?I ?J ?K ?L ?M ?N ?O ?P ?Q ?R ?S ?T ?U ?V ?=]
+  "The default base32hex dictionary.
+\nLike ‘base32-dictionary’ but for the base32hex encoding.")
+
 (defun base32-lsh (v c)
   "Shift integer V by C bits to the left.
 Shift rightwards if C is negative.
@@ -162,5 +168,13 @@ DICTIONARY defaults to ‘base32-dictionary’."
       (base32--nth-5bit-set output i chunk))
     (if (< output-shorten 0) (substring output 0 output-shorten) output)))
 
+(defun base32-hex-encode (input)
+  "Encode INPUT bytes as base32hex."
+  (base32-encode input base32-hex-dictionary))
+
+(defun base32-hex-decode (input)
+  "Decode INPUT bytes as base32hex."
+  (base32-decode input base32-hex-dictionary))
+
 (provide 'base32)
 ;;; base32.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]