* [bug#43699] [PATCH] guix: Fix argument order of fxbit-set?
@ 2020-09-29 8:29 Lars-Dominik Braun
2020-09-29 20:56 ` bug#43699: " Ludovic Courtès
0 siblings, 1 reply; 4+ messages in thread
From: Lars-Dominik Braun @ 2020-09-29 8:29 UTC (permalink / raw)
To: 43699
[-- Attachment #1: Type: text/plain, Size: 4257 bytes --]
* guix/openpgp.scm (port-ascii-armored?): Fix it here…
(get-packet*): …and here…
(parse-subpackets): …and also here.
* tests/openpgp.scm (%binary-sample): New test vector.
("port-ascii-armored?, #t"): Add test.
("port-ascii-armored?, #f"): Add another test.
---
guix/openpgp.scm | 14 +++++++-------
tests/openpgp.scm | 12 ++++++++++++
2 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/guix/openpgp.scm b/guix/openpgp.scm
index 33c851255b..f6c9f8ac78 100644
--- a/guix/openpgp.scm
+++ b/guix/openpgp.scm
@@ -239,7 +239,7 @@ writes to PORT the value 42 as an 8-bit integer and the value #x7777 as a
(let ((idx (fxarithmetic-shift-right i 3))
(bit (fxand i #b111)))
(and (< idx (bytevector-length bv))
- (fxbit-set? (bytevector-u8-ref bv idx) bit))))
+ (fxbit-set? bit (bytevector-u8-ref bv idx)))))
(do ((names names (cdr names))
(i 0 (fx+ i 1))
(bits '()
@@ -410,9 +410,9 @@ hexadecimal format for fingerprints."
(define (port-ascii-armored? p)
(let ((tag (lookahead-u8 p)))
(cond ((eof-object? tag) #f)
- ((not (fxbit-set? tag 7)) #t)
+ ((not (fxbit-set? 7 tag)) #t)
(else
- (let ((type (if (fxbit-set? tag 6)
+ (let ((type (if (fxbit-set? 6 tag)
(fxbit-field tag 0 6)
(fxbit-field tag 2 6))))
(not (<= PACKET-SESSION-KEY type PACKET-MDC)))))))
@@ -444,7 +444,7 @@ hexadecimal format for fingerprints."
(define (get-packet* p get-data)
(let ((tag (get-u8 p)))
;; (unless (fxbit-set? tag 7) (error 'get-packet "Invalid tag" tag))
- (cond ((fxbit-set? tag 6) ;New packet format
+ (cond ((fxbit-set? 6 tag) ;New packet format
(let ((tag (fxbit-field tag 0 6))
(len (get-v4-length p)))
(get-data p tag len)))
@@ -726,7 +726,7 @@ FINGERPRINT, a bytevector."
(define (parse-subpackets bv signature-port)
(define (parse tag data)
(let ((type (fxbit-field tag 0 7))
- (critical? (fxbit-set? tag 7)))
+ (critical? (fxbit-set? 7 tag)))
(cond
((= type SUBPACKET-SIGNATURE-CTIME)
(cons 'signature-ctime
@@ -764,7 +764,7 @@ FINGERPRINT, a bytevector."
(value (get-bytevector-n p vlen)))
(cons 'notation-data
(list (utf8->string name)
- (if (fxbit-set? f1 7)
+ (if (fxbit-set? 7 f1)
(utf8->string value)
value)))))))
((= type SUBPACKET-PREFERRED-HASH-ALGORITHMS)
@@ -777,7 +777,7 @@ FINGERPRINT, a bytevector."
((= type SUBPACKET-KEY-SERVER-PREFERENCES)
(cons 'key-server-preferences
(if (and (>= (bytevector-length data) 1)
- (fxbit-set? (bytevector-u8-ref data 0) 7))
+ (fxbit-set? 7 (bytevector-u8-ref data 0)))
(list 'no-modify)
(list))))
((= type SUBPACKET-PREFERRED-KEY-SERVER)
diff --git a/tests/openpgp.scm b/tests/openpgp.scm
index 0beab6f88b..c2be26fa49 100644
--- a/tests/openpgp.scm
+++ b/tests/openpgp.scm
@@ -50,6 +50,12 @@ vBSFjNSiVHsuAA==
=AAAA
-----END PGP MESSAGE-----\n")
+(define %binary-sample
+ ;; Same message as %radix-64-sample, decoded into bytevector.
+ (base16-string->bytevector
+ "c838013b6d96c411efecef17ecefe3ca0004ce8979ea250a897995f979a9\
+0ad9a9a9050a890ac5a9c945a940c1a2fcd2bc14858cd4a2547b2e00"))
+
(define %civodul-fingerprint
"3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5")
@@ -155,6 +161,12 @@ Pz7oopeN72xgggYUNT37ezqN3MeCqw0=
read-radix-64))
list))
+(test-assert "port-ascii-armored?, #t"
+ (call-with-input-string %radix-64-sample port-ascii-armored?))
+
+(test-assert "port-ascii-armored?, #f"
+ (not (port-ascii-armored? (open-bytevector-input-port %binary-sample))))
+
(test-assert "get-openpgp-keyring"
(let* ((key (search-path %load-path "tests/civodul.key"))
(keyring (get-openpgp-keyring
--
2.26.2
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
^ permalink raw reply related [flat|nested] 4+ messages in thread
* bug#43699: [PATCH] guix: Fix argument order of fxbit-set?
2020-09-29 8:29 [bug#43699] [PATCH] guix: Fix argument order of fxbit-set? Lars-Dominik Braun
@ 2020-09-29 20:56 ` Ludovic Courtès
2020-09-30 6:30 ` [bug#43699] " Lars-Dominik Braun
0 siblings, 1 reply; 4+ messages in thread
From: Ludovic Courtès @ 2020-09-29 20:56 UTC (permalink / raw)
To: Lars-Dominik Braun; +Cc: 43699-done
Hello!
Lars-Dominik Braun <ldb@leibniz-psychology.org> skribis:
> * guix/openpgp.scm (port-ascii-armored?): Fix it here…
> (get-packet*): …and here…
> (parse-subpackets): …and also here.
> * tests/openpgp.scm (%binary-sample): New test vector.
> ("port-ascii-armored?, #t"): Add test.
> ("port-ascii-armored?, #f"): Add another test.
Good catch!
The root problem is that the ‘fxbit-set?’ alias defined at the top of
openpgp.scm had the arguments swapped compared to ‘bit-set?’. So I
changed that alias instead of changing its users (‘fxbit-set?’ is
defined in R6RS).
Pushed as 680b80e37453d4e23ad8188d60894916e1c07162 along with the new
tests.
Thank you!
Ludo’.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [bug#43699] [PATCH] guix: Fix argument order of fxbit-set?
2020-09-29 20:56 ` bug#43699: " Ludovic Courtès
@ 2020-09-30 6:30 ` Lars-Dominik Braun
2020-09-30 9:34 ` Ludovic Courtès
0 siblings, 1 reply; 4+ messages in thread
From: Lars-Dominik Braun @ 2020-09-30 6:30 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: 43699-done
[-- Attachment #1: Type: text/plain, Size: 510 bytes --]
Hi Ludo,
> The root problem is that the ‘fxbit-set?’ alias defined at the top of
> openpgp.scm had the arguments swapped compared to ‘bit-set?’. So I
> changed that alias instead of changing its users (‘fxbit-set?’ is
> defined in R6RS).
oh, okay. I looked at SRFI 143 which also has a fxbit-set? with the same
argument order as bit-set?, so I thought the alias was mimicking that API. But
this works too I guess.
Thanks,
Lars
[1] https://srfi.schemers.org/srfi-143/srfi-143.html
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* [bug#43699] [PATCH] guix: Fix argument order of fxbit-set?
2020-09-30 6:30 ` [bug#43699] " Lars-Dominik Braun
@ 2020-09-30 9:34 ` Ludovic Courtès
0 siblings, 0 replies; 4+ messages in thread
From: Ludovic Courtès @ 2020-09-30 9:34 UTC (permalink / raw)
To: Lars-Dominik Braun; +Cc: 43699-done
Hi,
Lars-Dominik Braun <ldb@leibniz-psychology.org> skribis:
>> The root problem is that the ‘fxbit-set?’ alias defined at the top of
>> openpgp.scm had the arguments swapped compared to ‘bit-set?’. So I
>> changed that alias instead of changing its users (‘fxbit-set?’ is
>> defined in R6RS).
> oh, okay. I looked at SRFI 143 which also has a fxbit-set? with the same
> argument order as bit-set?, so I thought the alias was mimicking that API. But
> this works too I guess.
Oh, didn’t know about that SRFI; that’s the beauty of Scheme: 10
“standard” interfaces for the same thing. :-)
This OpenPGP code originates from R6RS (Göran Weinholt’s Industria
library and related code) so I think that was right.
Thanks,
Ludo’.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-09-30 9:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-29 8:29 [bug#43699] [PATCH] guix: Fix argument order of fxbit-set? Lars-Dominik Braun
2020-09-29 20:56 ` bug#43699: " Ludovic Courtès
2020-09-30 6:30 ` [bug#43699] " Lars-Dominik Braun
2020-09-30 9:34 ` Ludovic Courtès
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.