diff mbox series

[bug#43699] guix: Fix argument order of fxbit-set?

Message ID 20200929082923.GA7294@zpidnp36
State Accepted
Headers show
Series [bug#43699] guix: Fix argument order of fxbit-set? | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job

Commit Message

Lars-Dominik Braun Sept. 29, 2020, 8:29 a.m. UTC
* 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(-)

Comments

Ludovic Courtès Sept. 29, 2020, 8:56 p.m. UTC | #1
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’.
Lars-Dominik Braun Sept. 30, 2020, 6:30 a.m. UTC | #2
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
Ludovic Courtès Sept. 30, 2020, 9:34 a.m. UTC | #3
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’.
diff mbox series

Patch

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