diff options
author | Werner Koch <[email protected]> | 2015-03-16 18:57:11 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2015-03-16 19:12:44 +0000 |
commit | bcc8250bc5b9a357c6d1444f03e334edec573ede (patch) | |
tree | 90b3aa179c4e5bccb6a97ccd0b9bda15a4e51413 /g10/parse-packet.c | |
parent | gpg: Fix broken write of opaque MPI length header. (diff) | |
download | gnupg-bcc8250bc5b9a357c6d1444f03e334edec573ede.tar.gz gnupg-bcc8250bc5b9a357c6d1444f03e334edec573ede.zip |
gpg: Allow printing of MPI values in --list-mode.
* g10/parse-packet.c (set_packet_list_mode): Set mpi_print_mode.
* g10/misc.c (mpi_print): Do not print an extra leading zero.
--
This was in older versions possible using "--debug 4" but that was
disabled in 2.1 due to a conflict using this values also for
Libgcrypt. Now the values are dumped either with --debug 4 or using
--list-packets along with --verbose.
Because OpenPGP only uses unsigned integers an extra leading zero will
not be printed anymore.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'g10/parse-packet.c')
-rw-r--r-- | g10/parse-packet.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/g10/parse-packet.c b/g10/parse-packet.c index 62320865c..d6a6d109f 100644 --- a/g10/parse-packet.c +++ b/g10/parse-packet.c @@ -112,7 +112,7 @@ read_32 (IOBUF inp) /* Read an external representation of an mpi and return the MPI. The * external format is a 16 bit unsigned value stored in network byte * order, giving the number of bits for the following integer. The - * integer is stored with MSB first (left padded with zeroes to align + * integer is stored with MSB first (left padded with zero bits to align * on a byte boundary). */ static gcry_mpi_t mpi_read (iobuf_t inp, unsigned int *ret_nread, int secure) @@ -177,24 +177,38 @@ set_packet_list_mode (int mode) { int old = list_mode; list_mode = mode; - /* FIXME(gcrypt) mpi_print_mode = DBG_MPI; */ - /* We use stdout print only if invoked by the --list-packets command + + /* We use stdout only if invoked by the --list-packets command but switch to stderr in all other cases. This breaks the previous behaviour but that seems to be more of a bug than intentional. I don't believe that any application makes use of this long standing annoying way of printing to stdout except when doing a --list-packets. If this assumption fails, it will be easy to add an option for the listing stream. Note that we initialize - it only once; mainly because some code may switch the option - value later back to 1 and we want to have all output to the same - stream. + it only once; mainly because there is code which switches + opt.list_mode back to 1 and we want to have all output to the + same stream. The MPI_PRINT_MODE will be enabled if the + corresponding debug flag is set or if we are in --list-packets + and --verbose is given. Using stderr is not actually very clean because it bypasses the logging code but it is a special thing anyway. I am not sure whether using log_stream() would be better. Perhaps we should - enable the list mdoe only with a special option. */ + enable the list mode only with a special option. */ if (!listfp) - listfp = opt.list_packets == 2 ? es_stdout : es_stderr; + { + if (opt.list_packets == 2) + { + listfp = es_stdout; + if (opt.verbose) + mpi_print_mode = 1; + } + else + listfp = es_stderr; + + if (opt.debug && DBG_MPI_VALUE) + mpi_print_mode = 1; + } return old; } |