1 /* read-packet.c - Read OpenPGP packets
2 * Copyright (C) 2001, 2002, 2003, 2007, 2008, 2010 Free Software
7 * This file is part of OpenCDK.
9 * The OpenCDK library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
37 #include <gnutls_algorithms.h>
39 /* The version of the MDC packet considering the lastest OpenPGP draft. */
43 stream_read (cdk_stream_t s, void *buf, size_t buflen, size_t * r_nread)
45 *r_nread = cdk_stream_read (s, buf, buflen);
46 return *r_nread > 0 ? 0 : _cdk_stream_get_errno (s);
50 /* Try to read 4 octets from the stream. */
52 read_32 (cdk_stream_t s)
59 stream_read (s, buf, 4, &nread);
62 return buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];
66 /* Try to read 2 octets from a stream. */
68 read_16 (cdk_stream_t s)
75 stream_read (s, buf, 2, &nread);
78 return buf[0] << 8 | buf[1];
82 /* read about S2K at http://tools.ietf.org/html/rfc4880#section-3.7.1 */
84 read_s2k (cdk_stream_t inp, cdk_s2k_t s2k)
88 s2k->mode = cdk_stream_getc (inp);
89 s2k->hash_algo = cdk_stream_getc (inp);
90 if (s2k->mode == CDK_S2K_SIMPLE)
92 else if (s2k->mode == CDK_S2K_SALTED || s2k->mode == CDK_S2K_ITERSALTED)
94 if (stream_read (inp, s2k->salt, DIM (s2k->salt), &nread))
95 return CDK_Inv_Packet;
96 if (nread != DIM (s2k->salt))
97 return CDK_Inv_Packet;
99 if (s2k->mode == CDK_S2K_ITERSALTED)
100 s2k->count = cdk_stream_getc (inp);
102 else if (s2k->mode == CDK_S2K_GNU_EXT)
104 /* GNU extensions to the S2K : read DETAILS from gnupg */
108 return CDK_Not_Implemented;
115 read_mpi (cdk_stream_t inp, bigint_t * ret_m, int secure)
119 byte buf[MAX_MPI_BYTES + 2];
124 return CDK_Inv_Value;
127 nbits = read_16 (inp);
128 nread = (nbits + 7) / 8;
130 if (nbits > MAX_MPI_BITS || nbits == 0)
132 _gnutls_write_log ("read_mpi: too large %d bits\n", (int) nbits);
133 return CDK_MPI_Error; /* Sanity check */
136 rc = stream_read (inp, buf + 2, nread, &nread);
137 if (!rc && nread != ((nbits + 7) / 8))
139 _gnutls_write_log ("read_mpi: too short %d < %d\n", (int) nread,
140 (int) ((nbits + 7) / 8));
141 return CDK_MPI_Error;
147 err = _gnutls_mpi_scan_pgp (&m, buf, nread);
149 return map_gnutls_error (err);
156 /* Read the encoded packet length directly from the file
157 object INP and return it. Reset RET_PARTIAL if this is
158 the last packet in block mode. */
160 _cdk_pkt_read_len (FILE * inp, size_t * ret_partial)
168 if (c1 < 224 || c1 == 255)
169 *ret_partial = 0; /* End of partial data */
172 else if (c1 >= 192 && c1 <= 223)
177 pktlen = ((c1 - 192) << 8) + c2 + 192;
181 pktlen = fgetc (inp) << 24;
182 pktlen |= fgetc (inp) << 16;
183 pktlen |= fgetc (inp) << 8;
184 pktlen |= fgetc (inp) << 0;
187 pktlen = 1 << (c1 & 0x1f);
193 read_pubkey_enc (cdk_stream_t inp, size_t pktlen, cdk_pkt_pubkey_enc_t pke)
198 return CDK_Inv_Value;
201 _gnutls_write_log ("read_pubkey_enc: %d octets\n", (int) pktlen);
204 return CDK_Inv_Packet;
205 pke->version = cdk_stream_getc (inp);
206 if (pke->version < 2 || pke->version > 3)
207 return CDK_Inv_Packet;
208 pke->keyid[0] = read_32 (inp);
209 pke->keyid[1] = read_32 (inp);
210 if (!pke->keyid[0] && !pke->keyid[1])
211 pke->throw_keyid = 1; /* RFC2440 "speculative" keyID */
212 pke->pubkey_algo = _pgp_pub_algo_to_cdk (cdk_stream_getc (inp));
213 nenc = cdk_pk_get_nenc (pke->pubkey_algo);
216 for (i = 0; i < nenc; i++)
218 cdk_error_t rc = read_mpi (inp, &pke->mpi[i], 0);
229 read_mdc (cdk_stream_t inp, cdk_pkt_mdc_t mdc)
235 return CDK_Inv_Value;
238 _gnutls_write_log ("read_mdc:\n");
240 rc = stream_read (inp, mdc->hash, DIM (mdc->hash), &n);
244 return n != DIM (mdc->hash) ? CDK_Inv_Packet : 0;
249 read_compressed (cdk_stream_t inp, size_t pktlen, cdk_pkt_compressed_t c)
252 return CDK_Inv_Value;
255 _gnutls_write_log ("read_compressed: %d octets\n", (int) pktlen);
257 c->algorithm = cdk_stream_getc (inp);
258 if (c->algorithm > 3)
259 return CDK_Inv_Packet;
261 /* don't know the size, so we read until EOF */
268 /* FIXME: Support partial bodies. */
274 read_public_key (cdk_stream_t inp, size_t pktlen, cdk_pkt_pubkey_t pk)
276 size_t i, ndays, npkey;
279 return CDK_Inv_Value;
282 _gnutls_write_log ("read_public_key: %d octets\n", (int) pktlen);
284 pk->is_invalid = 1; /* default to detect missing self signatures */
288 pk->version = cdk_stream_getc (inp);
289 if (pk->version < 2 || pk->version > 4)
290 return CDK_Inv_Packet_Ver;
291 pk->timestamp = read_32 (inp);
294 ndays = read_16 (inp);
296 pk->expiredate = pk->timestamp + ndays * 86400L;
299 pk->pubkey_algo = _pgp_pub_algo_to_cdk (cdk_stream_getc (inp));
300 npkey = cdk_pk_get_npkey (pk->pubkey_algo);
304 _gnutls_write_log ("invalid public key algorithm %d\n",
308 for (i = 0; i < npkey; i++)
310 cdk_error_t rc = read_mpi (inp, &pk->mpi[i], 0);
315 /* This value is just for the first run and will be
316 replaced with the actual key flags from the self signature. */
317 pk->pubkey_usage = 0;
323 read_public_subkey (cdk_stream_t inp, size_t pktlen, cdk_pkt_pubkey_t pk)
326 return CDK_Inv_Value;
327 return read_public_key (inp, pktlen, pk);
331 read_secret_key (cdk_stream_t inp, size_t pktlen, cdk_pkt_seckey_t sk)
333 size_t p1, p2, nread;
337 if (!inp || !sk || !sk->pk)
338 return CDK_Inv_Value;
341 _gnutls_write_log ("read_secret_key: %d octets\n", (int) pktlen);
343 p1 = cdk_stream_tell (inp);
344 rc = read_public_key (inp, pktlen, sk->pk);
348 sk->s2k_usage = cdk_stream_getc (inp);
349 sk->protect.sha1chk = 0;
350 if (sk->s2k_usage == 254 || sk->s2k_usage == 255)
352 sk->protect.sha1chk = (sk->s2k_usage == 254);
353 sk->protect.algo = _pgp_cipher_to_gnutls (cdk_stream_getc (inp));
354 sk->protect.s2k = cdk_calloc (1, sizeof *sk->protect.s2k);
355 if (!sk->protect.s2k)
356 return CDK_Out_Of_Core;
357 rc = read_s2k (inp, sk->protect.s2k);
360 /* refer to --export-secret-subkeys in gpg(1) */
361 if (sk->protect.s2k->mode == CDK_S2K_GNU_EXT)
362 sk->protect.ivlen = 0;
365 sk->protect.ivlen = gnutls_cipher_get_block_size (sk->protect.algo);
366 if (!sk->protect.ivlen)
367 return CDK_Inv_Packet;
368 rc = stream_read (inp, sk->protect.iv, sk->protect.ivlen, &nread);
371 if (nread != sk->protect.ivlen)
372 return CDK_Inv_Packet;
376 sk->protect.algo = _pgp_cipher_to_gnutls (sk->s2k_usage);
377 if (sk->protect.algo == GNUTLS_CIPHER_NULL)
380 nskey = cdk_pk_get_nskey (sk->pk->pubkey_algo);
386 for (i = 0; i < nskey; i++)
388 rc = read_mpi (inp, &sk->mpi[i], 1);
392 sk->csum = read_16 (inp);
393 sk->is_protected = 0;
395 else if (sk->pk->version < 4)
397 /* The length of each multiprecision integer is stored in plaintext. */
398 nskey = cdk_pk_get_nskey (sk->pk->pubkey_algo);
404 for (i = 0; i < nskey; i++)
406 rc = read_mpi (inp, &sk->mpi[i], 1);
410 sk->csum = read_16 (inp);
411 sk->is_protected = 1;
415 /* We need to read the rest of the packet because we do not
416 have any information how long the encrypted mpi's are */
417 p2 = cdk_stream_tell (inp);
419 sk->enclen = pktlen - p2;
421 return CDK_Inv_Packet; /* at least 16 bits for the checksum! */
422 sk->encdata = cdk_calloc (1, sk->enclen + 1);
424 return CDK_Out_Of_Core;
425 if (stream_read (inp, sk->encdata, sk->enclen, &nread))
426 return CDK_Inv_Packet;
427 /* Handle the GNU S2K extensions we know (just gnu-dummy right now): */
428 if (sk->protect.s2k->mode == CDK_S2K_GNU_EXT)
430 unsigned char gnumode;
431 if ((sk->enclen < strlen ("GNU") + 1) ||
432 (0 != memcmp ("GNU", sk->encdata, strlen ("GNU"))))
433 return CDK_Inv_Packet;
434 gnumode = sk->encdata[strlen ("GNU")];
435 /* we only handle gnu-dummy (mode 1).
436 mode 2 should refer to external smart cards.
439 return CDK_Inv_Packet;
440 /* gnu-dummy should have no more data */
441 if (sk->enclen != strlen ("GNU") + 1)
442 return CDK_Inv_Packet;
444 nskey = cdk_pk_get_nskey (sk->pk->pubkey_algo);
450 /* We mark each MPI entry with NULL to indicate a protected key. */
451 for (i = 0; i < nskey; i++)
453 sk->is_protected = 1;
457 _cdk_copy_pk_to_sk (sk->pk, sk);
463 read_secret_subkey (cdk_stream_t inp, size_t pktlen, cdk_pkt_seckey_t sk)
467 if (!inp || !sk || !sk->pk)
468 return CDK_Inv_Value;
470 rc = read_secret_key (inp, pktlen, sk);
477 read_attribute (cdk_stream_t inp, size_t pktlen, cdk_pkt_userid_t attr)
484 if (!inp || !attr || !pktlen)
485 return CDK_Inv_Value;
488 _gnutls_write_log ("read_attribute: %d octets\n", (int) pktlen);
490 strcpy (attr->name, "[attribute]");
491 attr->len = strlen (attr->name);
492 buf = cdk_calloc (1, pktlen);
494 return CDK_Out_Of_Core;
495 rc = stream_read (inp, buf, pktlen, &nread);
499 return CDK_Inv_Packet;
506 len = _cdk_buftou32 (p);
515 return CDK_Inv_Packet;
517 len = ((len - 192) << 8) + *p + 192;
522 if (*p != 1) /* Currently only 1, meaning an image, is defined. */
525 return CDK_Inv_Packet;
531 return CDK_Inv_Packet;
532 attr->attrib_img = cdk_calloc (1, len);
533 if (!attr->attrib_img)
536 return CDK_Out_Of_Core;
538 attr->attrib_len = len;
539 memcpy (attr->attrib_img, p, len);
546 read_user_id (cdk_stream_t inp, size_t pktlen, cdk_pkt_userid_t user_id)
551 if (!inp || !user_id)
552 return CDK_Inv_Value;
554 return CDK_Inv_Packet;
557 _gnutls_write_log ("read_user_id: %lu octets\n", pktlen);
559 user_id->len = pktlen;
560 rc = stream_read (inp, user_id->name, pktlen, &nread);
564 return CDK_Inv_Packet;
565 user_id->name[nread] = '\0';
571 read_subpkt (cdk_stream_t inp, cdk_subpkt_t * r_ctx, size_t * r_nbytes)
574 size_t size, nread, n;
578 if (!inp || !r_nbytes)
579 return CDK_Inv_Value;
582 _gnutls_write_log ("read_subpkt:\n");
586 c = cdk_stream_getc (inp);
590 size = read_32 (inp);
593 else if (c >= 192 && c < 255)
595 c1 = cdk_stream_getc (inp);
599 size = ((c - 192) << 8) + c1 + 192;
604 return CDK_Inv_Packet;
606 node = cdk_subpkt_new (size);
608 return CDK_Out_Of_Core;
610 node->type = cdk_stream_getc (inp);
612 _gnutls_write_log (" %d octets %d type\n", node->size, node->type);
615 rc = stream_read (inp, node->d, node->size, &nread);
623 cdk_subpkt_add (*r_ctx, node);
629 read_onepass_sig (cdk_stream_t inp, size_t pktlen, cdk_pkt_onepass_sig_t sig)
632 return CDK_Inv_Value;
635 _gnutls_write_log ("read_onepass_sig: %d octets\n", (int) pktlen);
638 return CDK_Inv_Packet;
639 sig->version = cdk_stream_getc (inp);
640 if (sig->version != 3)
641 return CDK_Inv_Packet_Ver;
642 sig->sig_class = cdk_stream_getc (inp);
643 sig->digest_algo = _pgp_hash_algo_to_gnutls (cdk_stream_getc (inp));
644 sig->pubkey_algo = _pgp_pub_algo_to_cdk (cdk_stream_getc (inp));
645 sig->keyid[0] = read_32 (inp);
646 sig->keyid[1] = read_32 (inp);
647 sig->last = cdk_stream_getc (inp);
653 parse_sig_subpackets (cdk_pkt_signature_t sig)
657 /* Setup the standard packet entries, so we can use V4
658 signatures similar to V3. */
659 for (node = sig->unhashed; node; node = node->next)
661 if (node->type == CDK_SIGSUBPKT_ISSUER && node->size >= 8)
663 sig->keyid[0] = _cdk_buftou32 (node->d);
664 sig->keyid[1] = _cdk_buftou32 (node->d + 4);
666 else if (node->type == CDK_SIGSUBPKT_EXPORTABLE && node->d[0] == 0)
668 /* Sometimes this packet might be placed in the unhashed area */
669 sig->flags.exportable = 0;
672 for (node = sig->hashed; node; node = node->next)
674 if (node->type == CDK_SIGSUBPKT_SIG_CREATED && node->size >= 4)
675 sig->timestamp = _cdk_buftou32 (node->d);
676 else if (node->type == CDK_SIGSUBPKT_SIG_EXPIRE && node->size >= 4)
678 sig->expiredate = _cdk_buftou32 (node->d);
679 if (sig->expiredate > 0 && sig->expiredate < (u32) gnutls_time (NULL))
680 sig->flags.expired = 1;
682 else if (node->type == CDK_SIGSUBPKT_POLICY)
683 sig->flags.policy_url = 1;
684 else if (node->type == CDK_SIGSUBPKT_NOTATION)
685 sig->flags.notation = 1;
686 else if (node->type == CDK_SIGSUBPKT_REVOCABLE && node->d[0] == 0)
687 sig->flags.revocable = 0;
688 else if (node->type == CDK_SIGSUBPKT_EXPORTABLE && node->d[0] == 0)
689 sig->flags.exportable = 0;
691 if (sig->sig_class == 0x1F)
693 cdk_desig_revoker_t r, rnode;
695 for (node = sig->hashed; node; node = node->next)
697 if (node->type == CDK_SIGSUBPKT_REV_KEY)
701 rnode = cdk_calloc (1, sizeof *rnode);
703 return CDK_Out_Of_Core;
704 rnode->r_class = node->d[0];
705 rnode->algid = node->d[1];
706 memcpy (rnode->fpr, node->d + 2, KEY_FPR_LEN);
708 sig->revkeys = rnode;
711 for (r = sig->revkeys; r->next; r = r->next)
724 read_signature (cdk_stream_t inp, size_t pktlen, cdk_pkt_signature_t sig)
727 size_t i, size, nsig;
731 return CDK_Inv_Value;
734 _gnutls_write_log ("read_signature: %d octets\n", (int) pktlen);
737 return CDK_Inv_Packet;
738 sig->version = cdk_stream_getc (inp);
739 if (sig->version < 2 || sig->version > 4)
740 return CDK_Inv_Packet_Ver;
742 sig->flags.exportable = 1;
743 sig->flags.revocable = 1;
745 if (sig->version < 4)
747 if (cdk_stream_getc (inp) != 5)
748 return CDK_Inv_Packet;
749 sig->sig_class = cdk_stream_getc (inp);
750 sig->timestamp = read_32 (inp);
751 sig->keyid[0] = read_32 (inp);
752 sig->keyid[1] = read_32 (inp);
753 sig->pubkey_algo = _pgp_pub_algo_to_cdk (cdk_stream_getc (inp));
754 sig->digest_algo = _pgp_hash_algo_to_gnutls (cdk_stream_getc (inp));
755 sig->digest_start[0] = cdk_stream_getc (inp);
756 sig->digest_start[1] = cdk_stream_getc (inp);
757 nsig = cdk_pk_get_nsig (sig->pubkey_algo);
760 for (i = 0; i < nsig; i++)
762 rc = read_mpi (inp, &sig->mpi[i], 0);
769 sig->sig_class = cdk_stream_getc (inp);
770 sig->pubkey_algo = _pgp_pub_algo_to_cdk (cdk_stream_getc (inp));
771 sig->digest_algo = _pgp_hash_algo_to_gnutls (cdk_stream_getc (inp));
772 sig->hashed_size = read_16 (inp);
773 size = sig->hashed_size;
777 rc = read_subpkt (inp, &sig->hashed, &nbytes);
782 sig->unhashed_size = read_16 (inp);
783 size = sig->unhashed_size;
784 sig->unhashed = NULL;
787 rc = read_subpkt (inp, &sig->unhashed, &nbytes);
793 rc = parse_sig_subpackets (sig);
797 sig->digest_start[0] = cdk_stream_getc (inp);
798 sig->digest_start[1] = cdk_stream_getc (inp);
799 nsig = cdk_pk_get_nsig (sig->pubkey_algo);
802 for (i = 0; i < nsig; i++)
804 rc = read_mpi (inp, &sig->mpi[i], 0);
815 read_literal (cdk_stream_t inp, size_t pktlen,
816 cdk_pkt_literal_t * ret_pt, int is_partial)
818 cdk_pkt_literal_t pt = *ret_pt;
823 return CDK_Inv_Value;
826 _gnutls_write_log ("read_literal: %d octets\n", (int) pktlen);
828 pt->mode = cdk_stream_getc (inp);
829 if (pt->mode != 0x62 && pt->mode != 0x74 && pt->mode != 0x75)
830 return CDK_Inv_Packet;
831 if (cdk_stream_eof (inp))
832 return CDK_Inv_Packet;
834 pt->namelen = cdk_stream_getc (inp);
837 *ret_pt = pt = cdk_realloc (pt, sizeof *pt + pt->namelen + 2);
839 return CDK_Out_Of_Core;
840 pt->name = (char *) pt + sizeof (*pt);
841 rc = stream_read (inp, pt->name, pt->namelen, &nread);
844 if ((int) nread != pt->namelen)
845 return CDK_Inv_Packet;
846 pt->name[pt->namelen] = '\0';
848 pt->timestamp = read_32 (inp);
849 pktlen = pktlen - 6 - pt->namelen;
851 _cdk_stream_set_blockmode (inp, pktlen);
858 /* Read an old packet CTB and return the length of the body. */
860 read_old_length (cdk_stream_t inp, int ctb, size_t * r_len, size_t * r_size)
862 int llen = ctb & 0x03;
866 *r_len = cdk_stream_getc (inp);
871 *r_len = read_16 (inp);
876 *r_len = read_32 (inp);
887 /* Read a new CTB and decode the body length. */
889 read_new_length (cdk_stream_t inp,
890 size_t * r_len, size_t * r_size, size_t * r_partial)
894 c = cdk_stream_getc (inp);
898 else if (c >= 192 && c <= 223)
900 c1 = cdk_stream_getc (inp);
902 *r_len = ((c - 192) << 8) + c1 + 192;
906 *r_len = read_32 (inp);
911 *r_len = 1 << (c & 0x1f);
917 /* Skip the current packet body. */
919 skip_packet (cdk_stream_t inp, size_t pktlen)
922 size_t nread, buflen = DIM (buf);
926 stream_read (inp, buf, pktlen > buflen ? buflen : pktlen, &nread);
930 assert (pktlen == 0);
936 * @inp: the input stream
937 * @pkt: allocated packet handle to store the packet
939 * Parse the next packet on the @inp stream and return its contents in @pkt.
942 cdk_pkt_read (cdk_stream_t inp, cdk_packet_t pkt)
946 size_t pktlen = 0, pktsize = 0, is_partial = 0;
950 return CDK_Inv_Value;
952 ctb = cdk_stream_getc (inp);
953 if (cdk_stream_eof (inp) || ctb == EOF)
956 return CDK_Inv_Packet;
961 _cdk_log_info ("cdk_pkt_read: no openpgp data found. "
962 "(ctb=%02X; fpos=%02X)\n", (int) ctb,
963 (int) cdk_stream_tell (inp));
964 return CDK_Inv_Packet;
967 if (ctb & 0x40) /* RFC2440 packet format. */
969 pkttype = ctb & 0x3f;
972 else /* the old RFC1991 packet format. */
974 pkttype = ctb & 0x3f;
981 _cdk_log_info ("cdk_pkt_read: unknown type %d\n", pkttype);
982 return CDK_Inv_Packet;
986 read_new_length (inp, &pktlen, &pktsize, &is_partial);
988 read_old_length (inp, ctb, &pktlen, &pktsize);
990 pkt->pkttype = pkttype;
991 pkt->pktlen = pktlen;
992 pkt->pktsize = pktsize + pktlen;
993 pkt->old_ctb = is_newctb ? 0 : 1;
996 switch (pkt->pkttype)
998 case CDK_PKT_ATTRIBUTE:
999 pkt->pkt.user_id = cdk_calloc (1, sizeof *pkt->pkt.user_id
1000 + pkt->pktlen + 16 + 1);
1001 if (!pkt->pkt.user_id)
1002 return CDK_Out_Of_Core;
1003 pkt->pkt.user_id->name =
1004 (char *) pkt->pkt.user_id + sizeof (*pkt->pkt.user_id);
1006 rc = read_attribute (inp, pktlen, pkt->pkt.user_id);
1007 pkt->pkttype = CDK_PKT_ATTRIBUTE;
1010 case CDK_PKT_USER_ID:
1011 pkt->pkt.user_id = cdk_calloc (1, sizeof *pkt->pkt.user_id
1013 if (!pkt->pkt.user_id)
1014 return CDK_Out_Of_Core;
1015 pkt->pkt.user_id->name =
1016 (char *) pkt->pkt.user_id + sizeof (*pkt->pkt.user_id);
1017 rc = read_user_id (inp, pktlen, pkt->pkt.user_id);
1020 case CDK_PKT_PUBLIC_KEY:
1021 pkt->pkt.public_key = cdk_calloc (1, sizeof *pkt->pkt.public_key);
1022 if (!pkt->pkt.public_key)
1023 return CDK_Out_Of_Core;
1024 rc = read_public_key (inp, pktlen, pkt->pkt.public_key);
1027 case CDK_PKT_PUBLIC_SUBKEY:
1028 pkt->pkt.public_key = cdk_calloc (1, sizeof *pkt->pkt.public_key);
1029 if (!pkt->pkt.public_key)
1030 return CDK_Out_Of_Core;
1031 rc = read_public_subkey (inp, pktlen, pkt->pkt.public_key);
1034 case CDK_PKT_SECRET_KEY:
1035 pkt->pkt.secret_key = cdk_calloc (1, sizeof *pkt->pkt.secret_key);
1036 if (!pkt->pkt.secret_key)
1037 return CDK_Out_Of_Core;
1038 pkt->pkt.secret_key->pk = cdk_calloc (1,
1039 sizeof *pkt->pkt.secret_key->pk);
1040 if (!pkt->pkt.secret_key->pk)
1041 return CDK_Out_Of_Core;
1042 rc = read_secret_key (inp, pktlen, pkt->pkt.secret_key);
1045 case CDK_PKT_SECRET_SUBKEY:
1046 pkt->pkt.secret_key = cdk_calloc (1, sizeof *pkt->pkt.secret_key);
1047 if (!pkt->pkt.secret_key)
1048 return CDK_Out_Of_Core;
1049 pkt->pkt.secret_key->pk = cdk_calloc (1,
1050 sizeof *pkt->pkt.secret_key->pk);
1051 if (!pkt->pkt.secret_key->pk)
1052 return CDK_Out_Of_Core;
1053 rc = read_secret_subkey (inp, pktlen, pkt->pkt.secret_key);
1056 case CDK_PKT_LITERAL:
1057 pkt->pkt.literal = cdk_calloc (1, sizeof *pkt->pkt.literal);
1058 if (!pkt->pkt.literal)
1059 return CDK_Out_Of_Core;
1060 rc = read_literal (inp, pktlen, &pkt->pkt.literal, is_partial);
1063 case CDK_PKT_ONEPASS_SIG:
1064 pkt->pkt.onepass_sig = cdk_calloc (1, sizeof *pkt->pkt.onepass_sig);
1065 if (!pkt->pkt.onepass_sig)
1066 return CDK_Out_Of_Core;
1067 rc = read_onepass_sig (inp, pktlen, pkt->pkt.onepass_sig);
1070 case CDK_PKT_SIGNATURE:
1071 pkt->pkt.signature = cdk_calloc (1, sizeof *pkt->pkt.signature);
1072 if (!pkt->pkt.signature)
1073 return CDK_Out_Of_Core;
1074 rc = read_signature (inp, pktlen, pkt->pkt.signature);
1077 case CDK_PKT_PUBKEY_ENC:
1078 pkt->pkt.pubkey_enc = cdk_calloc (1, sizeof *pkt->pkt.pubkey_enc);
1079 if (!pkt->pkt.pubkey_enc)
1080 return CDK_Out_Of_Core;
1081 rc = read_pubkey_enc (inp, pktlen, pkt->pkt.pubkey_enc);
1084 case CDK_PKT_COMPRESSED:
1085 pkt->pkt.compressed = cdk_calloc (1, sizeof *pkt->pkt.compressed);
1086 if (!pkt->pkt.compressed)
1087 return CDK_Out_Of_Core;
1088 rc = read_compressed (inp, pktlen, pkt->pkt.compressed);
1092 pkt->pkt.mdc = cdk_calloc (1, sizeof *pkt->pkt.mdc);
1094 return CDK_Out_Of_Core;
1095 rc = read_mdc (inp, pkt->pkt.mdc);
1099 /* Skip all packets we don't understand */
1100 skip_packet (inp, pktlen);