summaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorNicolas Graves <ngraves@ngraves.fr>2026-03-01 11:46:10 +0100
committerNguyễn Gia Phong <cnx@loang.net>2026-04-10 14:46:59 +0900
commit4cbd5f883d1b05fd518f88e9256261b4229a6896 (patch)
treec4935e6410d4645c371d5595ac8ea1c6669a6bcc /guix
parent35ee6d0039a1815b763a476b2a00f42dc081423f (diff)
guix: openpgp: Refactor openpgp-fingerprint->bytevector.
Both (guix channel) and (guix git-authenticate) use similar procedures. To refactor the one in (guix git-authenticate), move the procedure to (guix openpgp). * guix/channels.scm: Replace autoloaded import openpgp-public-key-fingerprint with openpgp-fingerprint->bytevector. (openpgp-fingerprint->bytevector): Move function definition from here... * guix/openpgp.scm (openpgp-fingerprint->bytevector): ...to here. * guix/git-authenticate.scm (read-authorizations): Use openpgp-fingerprint->bytevector. * guix/scripts/git/authenticate.scm: Avoid using the (guix channels) module. * tests/git-authenticate.scm : Likewise. Change-Id: Ifd20588fcfaab601990098bd8575ee985e87394a Reviewed-by: Danny Milosavljevic <dannym@friendly-machines.com> Signed-off-by: Nguyễn Gia Phong <cnx@loang.net>
Diffstat (limited to 'guix')
-rw-r--r--guix/channels.scm11
-rw-r--r--guix/git-authenticate.scm5
-rw-r--r--guix/openpgp.scm8
-rw-r--r--guix/scripts/git/authenticate.scm6
4 files changed, 14 insertions, 16 deletions
diff --git a/guix/channels.scm b/guix/channels.scm
index ebd09eba8d..662fc7bae2 100644
--- a/guix/channels.scm
+++ b/guix/channels.scm
@@ -37,7 +37,7 @@
tag->commit
with-repository)
#:autoload (guix git-authenticate) (authenticate-repository)
- #:autoload (guix openpgp) (openpgp-public-key-fingerprint
+ #:autoload (guix openpgp) (openpgp-fingerprint->bytevector
openpgp-format-fingerprint)
#:use-module (guix base16)
#:use-module (guix records)
@@ -80,7 +80,6 @@
channel-introduction-first-signed-commit
channel-introduction-first-commit-signer
- openpgp-fingerprint->bytevector
openpgp-fingerprint
%default-guix-channel
@@ -157,16 +156,10 @@ authentication starts, and SIGNER is the OpenPGP fingerprint (a bytevector) of
the signer of that commit."
(%make-channel-introduction commit signer))
-(define (openpgp-fingerprint->bytevector str)
- "Convert STR, an OpenPGP fingerprint (hexadecimal string with whitespace),
-to the corresponding bytevector."
- (base16-string->bytevector
- (string-downcase (string-filter char-set:hex-digit str))))
-
(define-syntax openpgp-fingerprint
(lambda (s)
"Convert STR, an OpenPGP fingerprint (hexadecimal string with whitespace),
-to the corresponding bytevector."
+to the corresponding bytevector, doing it at compile time when possible."
(syntax-case s ()
((_ str)
(string? (syntax->datum #'str))
diff --git a/guix/git-authenticate.scm b/guix/git-authenticate.scm
index e5796123b9..7b5b3ab5ae 100644
--- a/guix/git-authenticate.scm
+++ b/guix/git-authenticate.scm
@@ -169,10 +169,7 @@ return a list of authorized fingerprints."
(('authorizations ('version 0)
(((? string? fingerprints) _ ...) ...)
_ ...)
- (map (lambda (fingerprint)
- (base16-string->bytevector
- (string-downcase (string-filter char-set:graphic fingerprint))))
- fingerprints))))
+ (map openpgp-fingerprint->bytevector fingerprints))))
(define* (commit-authorized-keys repository commit
#:optional (default-authorizations '()))
diff --git a/guix/openpgp.scm b/guix/openpgp.scm
index 9de7feb644..d99624911b 100644
--- a/guix/openpgp.scm
+++ b/guix/openpgp.scm
@@ -56,6 +56,8 @@
openpgp-public-key-fingerprint openpgp-format-fingerprint
openpgp-public-key-id
+ openpgp-fingerprint->bytevector
+
openpgp-keyring?
%empty-keyring
lookup-key-by-id
@@ -250,6 +252,12 @@ writes to PORT the value 42 as an 8-bit integer and the value #x7777 as a
bits)))
((null? names) (reverse bits))))
+(define (openpgp-fingerprint->bytevector fingerprint)
+ "Convert an OpenPGP FINGERPRINT (hexadecimal string with whitespace),
+to the corresponding bytevector."
+ (base16-string->bytevector
+ (string-downcase (string-filter char-set:hex-digit fingerprint))))
+
(define (openpgp-format-fingerprint bv)
"Return a string representing BV, a bytevector, in the conventional OpenPGP
hexadecimal format for fingerprints."
diff --git a/guix/scripts/git/authenticate.scm b/guix/scripts/git/authenticate.scm
index 3349a54ebf..a43c4ad5e0 100644
--- a/guix/scripts/git/authenticate.scm
+++ b/guix/scripts/git/authenticate.scm
@@ -23,9 +23,9 @@
#:use-module (guix ui)
#:use-module (guix scripts)
#:use-module (guix git-authenticate)
- #:autoload (guix openpgp) (openpgp-format-fingerprint
+ #:autoload (guix openpgp) (openpgp-fingerprint->bytevector
+ openpgp-format-fingerprint
openpgp-public-key-fingerprint)
- #:use-module ((guix channels) #:select (openpgp-fingerprint))
#:use-module ((guix git) #:select (with-git-error-handling))
#:use-module (guix progress)
#:autoload (guix base16) (base16-string->bytevector)
@@ -310,7 +310,7 @@ Authenticate the given Git checkout using COMMIT/SIGNER as its introduction.\n")
char-set:whitespace)
str)
(leave (G_ "~a: invalid OpenPGP fingerprint~%") str))
- (let ((fingerprint (openpgp-fingerprint str)))
+ (let ((fingerprint (openpgp-fingerprint->bytevector str)))
(unless (= 20 (bytevector-length fingerprint))
(leave (G_ "~a: wrong length for OpenPGP fingerprint~%") str))
fingerprint))