[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/base32 043ce25969 089/103: Add text-file export support
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/base32 043ce25969 089/103: Add text-file export support |
Date: |
Sat, 10 Feb 2024 13:00:12 -0500 (EST) |
branch: elpa/base32
commit 043ce259699ead7ea8d1fe8a5fe971f0cceaedde
Author: Vivek Das Mohapatra <vivek@collabora.com>
Commit: Vivek Das Mohapatra <vivek@collabora.co.uk>
Add text-file export support
---
totp-auth-interop.el | 47 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/totp-auth-interop.el b/totp-auth-interop.el
index c8a8f0556d..335912e5ae 100644
--- a/totp-auth-interop.el
+++ b/totp-auth-interop.el
@@ -445,6 +445,53 @@ Returns a list of otpauth-migration:// URLs."
urls)))
(nreverse urls)))
+(defun totp-auth-export-text (file-or-buffer &optional type secrets)
+ "Export OTP secrets to FILE-OR-BUFFER.
+If the target is a file it should be an epa target (eg a gpg or asc file),
+although that is not enforced by this function.
+TYPE is :otpauth or :otpauth-migration (and defaults to :otpauth).
+SECRETS is a list of ‘totp-auth-unwrap-otp-blob’ secrets, or nil,
+in which case all available secrets are exported."
+ (or type (setq type :otpauth))
+ (or secrets (setq secrets (mapcar #'cdr (totp-auth-secrets))))
+ (with-current-buffer (if (bufferp file-or-buffer)
+ file-or-buffer
+ (find-file-noselect file-or-buffer))
+ (message "exporting %S" secrets)
+ (mapc (lambda (s) (insert s "\n"))
+ (cond ((eq type :otpauth)
+ (mapcar #'totp-auth-wrap-otpauth-url secrets))
+ ((eq type :otpauth-migration)
+ (totp-auth-wrap-otpauth-migration-url secrets))
+ (t (error "Unsupported TOTP export type %S" type))))
+ (if (buffer-file-name (current-buffer))
+ (progn (save-buffer 0) (kill-buffer))
+ (display-buffer (current-buffer)))))
+
+(defun totp-auth-export-file (file &optional type secrets)
+ "Export TOTP secrets to FILE.
+FILE is a destination file.
+If it matches ‘epa-file-name-regexp’ then a text file is saved.
+If ‘image-type-from-file-name’ returns an image type for file then
+a QR code is generated instead.
+TYPE may be :otpauth-migration or :otpauth - which URL scheme to use.
+SECRETS is a list of ‘totp-auth-unwrap-otp-blob’ secrets, or nil for all."
+ (interactive (list (read-file-name "Export to:" nil "totp-auth-export.gpg")
+ (if (y-or-n-p "Use otpauth-migration format? ")
+ :otpauth-migration
+ :otpauth)
+ nil))
+ (setq file (expand-file-name file)
+ type (if (memq type '(:otpauth :otpauth-migration)) type :otpauth))
+ (when (file-exists-p file)
+ (error "Export file %S already exists" file))
+ (let (img-type epa-ok)
+ (setq epa-ok (string-match epa-file-name-regexp file)
+ img-type (image-type-from-file-name file))
+ (cond (epa-ok (totp-auth-export-text file type secrets))
+ (img-type (totp-auth-export-image file img-type type secrets))
+ (t (error "%S is not an EPA file or supported image format" file)))))
+
(defun totp-auth-import-file (file)
"Import an RFC6238 TOTP secret or secrets from FILE.
FILE is processed by ‘totp-auth-load-file’ and each secret extracted
- [nongnu] elpa/base32 b048113b66 100/103: Allow user to create secrets interactively, (continued)
- [nongnu] elpa/base32 b048113b66 100/103: Allow user to create secrets interactively, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 19b6939cca 098/103: Prefer the "TOTP" secrets collection over "login" (if it exists), ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 ce7fe1b815 071/103: Tests now indicate where they are loading totp-auth et al from, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 60c0ea49cf 073/103: Suppress more byte compile warnings, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 e28d088223 081/103: Missed a couple of references to totp-auth-lsh, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 ac5b439624 075/103: Document an otpauth-migration URL quirk in a comment, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 7b56905280 084/103: Add technical documentation about the specifications this implements, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 1c001795de 083/103: Preliminary otpauth-migration URL export support, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 0d7a4e1c9d 087/103: Check for availability of QR code import command, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 3bd26611c1 088/103: Don't add newlines in long otpauth-migration URL data blobs, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 043ce25969 089/103: Add text-file export support,
ELPA Syncer <=
- [nongnu] elpa/base32 4a32e61634 090/103: QR code export, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 967a8375e8 094/103: Add a require for epa-hook in totp-auth-interop, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 6f138d3eaa 099/103: Clean up the flow of totp-auth-sources, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 7e7e43535e 097/103: Update references to old command names in the commentary section, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 d520096a5d 101/103: Fix stale references in docstrings, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 15e19abec5 096/103: Update README files, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 da1498e54d 102/103: Handle empty user strings better when creating labels for secrets, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 d550a728be 066/103: Rename totp-interop.el to totp-auth-interop.el, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 908d2d6aea 076/103: Fix overlong docstring line, ELPA Syncer, 2024/02/10
- [nongnu] elpa/base32 33a93352a9 086/103: Trivia: docstring symbol markup converted to new style, ELPA Syncer, 2024/02/10