Re: OpenPGP format example program

New Message Reply About this list Date view Thread view Subject view Author view

Johnny Eriksson (bygg@sunet.se)
Mon, 16 Mar 1998 06:28:21 -0500


> Here's my weekend hacking project. Hope somebody finds it useful.
>
> Salvo Salasio

I do have a comment on a couple of your statements:

> switch (packet_tag & OLDLENGTH)
> {
> case 0:
> length = getbyte(pgpfile);
> break;
> case 1:
> length = getbyte(pgpfile) * 256 +
> getbyte(pgpfile);
> break;
> case 2:
> length = getbyte(pgpfile) * 256 * 256 * 256 +
> getbyte(pgpfile) * 256 * 256 +
> getbyte(pgpfile) * 256 +
> getbyte(pgpfile); /* Let compiler do it */
> break;

The code for cases 1 and 2 above depends on your compiler having the same
evaluation order as the byte order in the message. Reality is harsh, and
the eval order is unspecified in the ANSI C standard. I would suggest:

                    case 0:
                        length = getbyte(pgpfile);
                        break;
                    case 1:
                        length = getbyte(pgpfile) << 8;
                        length += getbyte(pgpfile);
                        break;
                    case 2:
                        length = getbyte(pgpfile) << 24;
                        length += getbyte(pgpfile) << 16;
                        length += getbyte(pgpfile) << 8;
                        length += getbyte(pgpfile);
                        break;

--Johnny


New Message Reply About this list Date view Thread view Subject view Author view

 
All trademarks and copyrights are the property of their respective owners.

Other Directory Sites: SeekWonder | Directory Owners Forum

The following archive was created by hippie-mail 7.98617-22 on Fri Aug 21 1998 - 17:16:00 ADT