~ubuntu-branches/ubuntu/hardy/gnupg2/hardy-proposed

« back to all changes in this revision

Viewing changes to g10/parse-packet.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Bienia
  • Date: 2007-05-15 13:54:55 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20070515135455-89qfyalmgjy6gcqw
Tags: 2.0.4-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Remove libpcsclite-dev, libopensc2-dev build dependencies (they are in
    universe).
  - Build-depend on libcurl3-gnutls-dev
  - g10/call-agent.c: set DBG_ASSUAN to 0 to suppress a debug message
  - Include /doc files as done with gnupg
  - debian/rules: add doc/com-certs.pem to the docs for gpgsm
  - debian/copyright: update download url
  - debian/README.Debian: remove note the gnupg2 isn't released yet.
  - debian/control: Change Maintainer/XSBC-Original-Maintainer field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* parse-packet.c  - read packets
2
 
 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3
 
 *               2006 Free Software Foundation, Inc.
 
2
 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
 
3
 *               2007 Free Software Foundation, Inc.
4
4
 *
5
5
 * This file is part of GnuPG.
6
6
 *
52
52
static void skip_packet( IOBUF inp, int pkttype,
53
53
                         unsigned long pktlen, int partial );
54
54
static void *read_rest( IOBUF inp, size_t pktlen, int partial );
 
55
static int  parse_marker( IOBUF inp, int pkttype, unsigned long pktlen );
55
56
static int  parse_symkeyenc( IOBUF inp, int pkttype, unsigned long pktlen,
56
57
                                                             PACKET *packet );
57
58
static int  parse_pubkeyenc( IOBUF inp, int pkttype, unsigned long pktlen,
579
580
      case PKT_GPG_CONTROL:
580
581
        rc = parse_gpg_control(inp, pkttype, pktlen, pkt, partial );
581
582
        break;
 
583
    case PKT_MARKER:
 
584
        rc = parse_marker(inp,pkttype,pktlen);
 
585
        break;
582
586
      default:
583
587
        skip_packet(inp, pkttype, pktlen, partial);
584
588
        break;
644
648
static void
645
649
skip_packet( IOBUF inp, int pkttype, unsigned long pktlen, int partial )
646
650
{
647
 
    if( list_mode ) {
648
 
        if( pkttype == PKT_MARKER )
649
 
            fputs(":marker packet:\n", listfp );
650
 
        else
651
 
            fprintf (listfp, ":unknown packet: type %2d, length %lu\n",
652
 
                     pkttype, pktlen);
653
 
        if( pkttype ) {
654
 
            int c, i=0 ;
655
 
            if( pkttype != PKT_MARKER )
656
 
                fputs("dump:", listfp );
657
 
            if( partial ) {
658
 
                while( (c=iobuf_get(inp)) != -1 )
659
 
                    dump_hex_line(c, &i);
660
 
            }
661
 
            else {
662
 
                for( ; pktlen; pktlen-- )
663
 
                    dump_hex_line(iobuf_get(inp), &i);
664
 
            }
665
 
            putc ('\n', listfp);
666
 
            return;
 
651
  if( list_mode )
 
652
    {
 
653
      fprintf (listfp, ":unknown packet: type %2d, length %lu\n",
 
654
               pkttype, pktlen);
 
655
      if( pkttype )
 
656
        {
 
657
          int c, i=0 ;
 
658
          fputs("dump:", listfp );
 
659
          if( partial )
 
660
            {
 
661
              while( (c=iobuf_get(inp)) != -1 )
 
662
                dump_hex_line(c, &i);
 
663
            }
 
664
          else
 
665
            {
 
666
              for( ; pktlen; pktlen-- )
 
667
                dump_hex_line(iobuf_get(inp), &i);
 
668
            }
 
669
          putc ('\n', listfp);
 
670
          return;
667
671
        }
668
672
    }
669
 
    iobuf_skip_rest(inp,pktlen,partial);
 
673
  iobuf_skip_rest(inp,pktlen,partial);
670
674
}
671
675
 
672
 
 
673
676
static void *
674
677
read_rest( IOBUF inp, size_t pktlen, int partial )
675
678
{
688
691
    return p;
689
692
}
690
693
 
691
 
 
 
694
static int
 
695
parse_marker( IOBUF inp, int pkttype, unsigned long pktlen )
 
696
{
 
697
  if(pktlen!=3)
 
698
    goto fail;
 
699
 
 
700
  if(iobuf_get(inp)!='P')
 
701
    {
 
702
      pktlen--;
 
703
      goto fail;
 
704
    }
 
705
 
 
706
  if(iobuf_get(inp)!='G')
 
707
    {
 
708
      pktlen--;
 
709
      goto fail;
 
710
    }
 
711
 
 
712
  if(iobuf_get(inp)!='P')
 
713
    {
 
714
      pktlen--;
 
715
      goto fail;
 
716
    }
 
717
 
 
718
  if(list_mode)
 
719
    fputs(":marker packet: PGP\n", listfp );
 
720
 
 
721
  return 0;
 
722
 
 
723
 fail:
 
724
  log_error("invalid marker packet\n");
 
725
  iobuf_skip_rest(inp,pktlen,0);
 
726
  return G10ERR_INVALID_PACKET;
 
727
}
692
728
 
693
729
static int
694
730
parse_symkeyenc( IOBUF inp, int pkttype, unsigned long pktlen, PACKET *packet )
1474
1510
 
1475
1511
    if( list_mode ) {
1476
1512
        fprintf (listfp, ":signature packet: algo %d, keyid %08lX%08lX\n"
1477
 
               "\tversion %d, created %lu, md5len %d, sigclass %02x\n"
 
1513
               "\tversion %d, created %lu, md5len %d, sigclass 0x%02x\n"
1478
1514
               "\tdigest algo %d, begin of digest %02x %02x\n",
1479
1515
                sig->pubkey_algo,
1480
1516
                (ulong)sig->keyid[0], (ulong)sig->keyid[1],