Go to the source code of this file.
Data Structures | |
struct | PushFilterOps |
struct | PullFilterOps |
Defines | |
#define | GETBYTE(pf, dst) |
Typedefs | |
typedef struct MBuf | MBuf |
typedef struct PushFilter | PushFilter |
typedef struct PullFilter | PullFilter |
typedef struct PushFilterOps | PushFilterOps |
typedef struct PullFilterOps | PullFilterOps |
Functions | |
MBuf * | mbuf_create (int len) |
MBuf * | mbuf_create_from_data (uint8 *data, int len) |
int | mbuf_tell (MBuf *mbuf) |
int | mbuf_avail (MBuf *mbuf) |
int | mbuf_size (MBuf *mbuf) |
int | mbuf_grab (MBuf *mbuf, int len, uint8 **data_p) |
int | mbuf_steal_data (MBuf *mbuf, uint8 **data_p) |
int | mbuf_append (MBuf *dst, const uint8 *buf, int cnt) |
int | mbuf_rewind (MBuf *mbuf) |
int | mbuf_free (MBuf *mbuf) |
int | pushf_create (PushFilter **res, const PushFilterOps *ops, void *init_arg, PushFilter *next) |
int | pushf_write (PushFilter *mp, const uint8 *data, int len) |
void | pushf_free_all (PushFilter *mp) |
void | pushf_free (PushFilter *mp) |
int | pushf_flush (PushFilter *mp) |
int | pushf_create_mbuf_writer (PushFilter **mp_p, MBuf *mbuf) |
int | pullf_create (PullFilter **res, const PullFilterOps *ops, void *init_arg, PullFilter *src) |
int | pullf_read (PullFilter *mp, int len, uint8 **data_p) |
int | pullf_read_max (PullFilter *mp, int len, uint8 **data_p, uint8 *tmpbuf) |
void | pullf_free (PullFilter *mp) |
int | pullf_read_fixed (PullFilter *src, int len, uint8 *dst) |
int | pullf_create_mbuf_reader (PullFilter **pf_p, MBuf *mbuf) |
#define GETBYTE | ( | pf, | ||
dst | ||||
) |
do { \ uint8 __b; \ int __res = pullf_read_fixed(pf, 1, &__b); \ if (__res < 0) \ return __res; \ (dst) = __b; \ } while (0)
typedef struct PullFilter PullFilter |
typedef struct PullFilterOps PullFilterOps |
typedef struct PushFilter PushFilter |
typedef struct PushFilterOps PushFilterOps |
Definition at line 102 of file mbuf.c.
References MBuf::data_end, MBuf::no_write, prepare_room(), and px_debug().
Referenced by copy_crlf(), decrypt_internal(), encrypt_internal(), parse_literal_data(), and push_into_mbuf().
int mbuf_avail | ( | MBuf * | mbuf | ) |
Definition at line 50 of file mbuf.c.
References MBuf::data_end, and MBuf::read_pos.
Referenced by mbuf_grab(), and pgp_encrypt().
MBuf* mbuf_create | ( | int | len | ) |
Definition at line 119 of file mbuf.c.
References MBuf::buf_end, MBuf::data, MBuf::data_end, MBuf::no_write, MBuf::own_data, px_alloc, and MBuf::read_pos.
Referenced by decrypt_internal(), and encrypt_internal().
Definition at line 139 of file mbuf.c.
References MBuf::buf_end, MBuf::data, MBuf::data_end, MBuf::no_write, MBuf::own_data, px_alloc, and MBuf::read_pos.
Referenced by create_mbuf_from_vardata(), and decrypt_internal().
int mbuf_free | ( | MBuf * | mbuf | ) |
Definition at line 68 of file mbuf.c.
References MBuf::buf_end, MBuf::data, MBuf::own_data, and px_free.
Referenced by decrypt_internal(), encrypt_internal(), and pgp_key_id_w().
Definition at line 157 of file mbuf.c.
References mbuf_avail(), MBuf::no_write, and MBuf::read_pos.
Referenced by pgp_encrypt(), and pull_from_mbuf().
{ if (len > mbuf_avail(mbuf)) len = mbuf_avail(mbuf); mbuf->no_write = true; *data_p = mbuf->read_pos; mbuf->read_pos += len; return len; }
int mbuf_rewind | ( | MBuf * | mbuf | ) |
Definition at line 170 of file mbuf.c.
References MBuf::data, and MBuf::read_pos.
int mbuf_size | ( | MBuf * | mbuf | ) |
Definition at line 56 of file mbuf.c.
References MBuf::data, and MBuf::data_end.
Referenced by mbuf_steal_data().
Definition at line 177 of file mbuf.c.
References MBuf::buf_end, MBuf::data, MBuf::data_end, mbuf_size(), MBuf::no_write, MBuf::own_data, and MBuf::read_pos.
Referenced by decrypt_internal(), and encrypt_internal().
int mbuf_tell | ( | MBuf * | mbuf | ) |
Definition at line 62 of file mbuf.c.
References MBuf::data, and MBuf::read_pos.
int pullf_create | ( | PullFilter ** | res, | |
const PullFilterOps * | ops, | |||
void * | init_arg, | |||
PullFilter * | src | |||
) |
Definition at line 206 of file mbuf.c.
References PullFilter::buf, PullFilter::buflen, PullFilterOps::init, NULL, PullFilter::op, PullFilter::pos, PullFilter::priv, px_alloc, and PullFilter::src.
Referenced by parse_symenc_data(), parse_symenc_mdc_data(), pgp_create_pkt_reader(), process_data_packets(), process_secret_key(), and pullf_create_mbuf_reader().
{ PullFilter *pf; void *priv; int res; if (op->init != NULL) { res = op->init(&priv, init_arg, src); if (res < 0) return res; } else { priv = init_arg; res = 0; } pf = px_alloc(sizeof(*pf)); memset(pf, 0, sizeof(*pf)); pf->buflen = res; pf->op = op; pf->priv = priv; pf->src = src; if (pf->buflen > 0) { pf->buf = px_alloc(pf->buflen); pf->pos = 0; } else { pf->buf = NULL; pf->pos = 0; } *pf_p = pf; return 0; }
int pullf_create_mbuf_reader | ( | PullFilter ** | pf_p, | |
MBuf * | mbuf | |||
) |
Definition at line 351 of file mbuf.c.
References NULL, and pullf_create().
Referenced by pgp_decrypt(), pgp_get_keyid(), and pgp_set_pubkey().
{ return pullf_create(mp_p, &mbuf_reader, src, NULL); }
void pullf_free | ( | PullFilter * | mp | ) |
Definition at line 245 of file mbuf.c.
References PullFilter::buf, PullFilter::buflen, PullFilterOps::free, PullFilter::op, PullFilter::priv, and px_free.
Referenced by internal_read_key(), parse_compressed_data(), parse_symenc_data(), parse_symenc_mdc_data(), pgp_decrypt(), pgp_get_keyid(), pgp_set_pubkey(), process_data_packets(), and process_secret_key().
int pullf_read | ( | PullFilter * | mp, | |
int | len, | |||
uint8 ** | data_p | |||
) |
Definition at line 262 of file mbuf.c.
References PullFilter::buf, PullFilter::buflen, PullFilter::op, PullFilter::priv, PullFilterOps::pull, pullf_read(), and PullFilter::src.
Referenced by decrypt_read(), mdc_read(), mdcbuf_refill(), parse_literal_data(), pgp_expect_packet_end(), pgp_parse_pkt_hdr(), pgp_skip_packet(), pktreader_pull(), process_data_packets(), pullf_read(), and pullf_read_max().
{ int res; if (pf->op->pull) { if (pf->buflen && len > pf->buflen) len = pf->buflen; res = pf->op->pull(pf->priv, pf->src, len, data_p, pf->buf, pf->buflen); } else res = pullf_read(pf->src, len, data_p); return res; }
int pullf_read_fixed | ( | PullFilter * | src, | |
int | len, | |||
uint8 * | dst | |||
) |
Definition at line 316 of file mbuf.c.
References pullf_read_max(), and px_debug().
Referenced by _pgp_read_public_key(), check_key_cksum(), check_key_sha1(), pgp_mpi_read(), pgp_parse_pubenc_sesskey(), pgp_s2k_read(), process_secret_key(), and read_pubenc_keyid().
{ int res; uint8 *p; res = pullf_read_max(src, len, &p, dst); if (res < 0) return res; if (res != len) { px_debug("pullf_read_fixed: need=%d got=%d", len, res); return PXE_MBUF_SHORT_READ; } if (p != dst) memcpy(dst, p, len); return 0; }
int pullf_read_max | ( | PullFilter * | mp, | |
int | len, | |||
uint8 ** | data_p, | |||
uint8 * | tmpbuf | |||
) |
Definition at line 279 of file mbuf.c.
References pullf_read().
Referenced by mdc_finish(), parse_literal_data(), parse_symenc_sesskey(), prefix_init(), and pullf_read_fixed().
{ int res, total; uint8 *tmp; res = pullf_read(pf, len, data_p); if (res <= 0 || res == len) return res; /* read was shorter, use tmpbuf */ memcpy(tmpbuf, *data_p, res); *data_p = tmpbuf; len -= res; total = res; while (len > 0) { res = pullf_read(pf, len, &tmp); if (res < 0) { /* so the caller must clear only on success */ memset(tmpbuf, 0, total); return res; } if (res == 0) break; memcpy(tmpbuf + total, tmp, res); total += res; } return total; }
int pushf_create | ( | PushFilter ** | res, | |
const PushFilterOps * | ops, | |||
void * | init_arg, | |||
PushFilter * | next | |||
) |
Definition at line 372 of file mbuf.c.
References PushFilter::block_size, PushFilter::buf, PushFilterOps::init, PushFilter::next, NULL, PushFilter::op, PushFilter::pos, PushFilter::priv, and px_alloc.
Referenced by init_compress(), init_encdata_packet(), init_litdata_packet(), pgp_create_pkt_writer(), pgp_encrypt(), and pushf_create_mbuf_writer().
{ PushFilter *mp; void *priv; int res; if (op->init != NULL) { res = op->init(next, init_arg, &priv); if (res < 0) return res; } else { priv = init_arg; res = 0; } mp = px_alloc(sizeof(*mp)); memset(mp, 0, sizeof(*mp)); mp->block_size = res; mp->op = op; mp->priv = priv; mp->next = next; if (mp->block_size > 0) { mp->buf = px_alloc(mp->block_size); mp->pos = 0; } else { mp->buf = NULL; mp->pos = 0; } *mp_p = mp; return 0; }
int pushf_create_mbuf_writer | ( | PushFilter ** | mp_p, | |
MBuf * | mbuf | |||
) |
Definition at line 560 of file mbuf.c.
References NULL, and pushf_create().
Referenced by pgp_encrypt().
{ return pushf_create(res, &mbuf_filter, dst, NULL); }
int pushf_flush | ( | PushFilter * | mp | ) |
Definition at line 515 of file mbuf.c.
References PushFilter::block_size, PushFilter::buf, PushFilterOps::flush, PushFilter::next, PushFilter::op, PushFilter::pos, PushFilter::priv, and wrap_process().
Referenced by pgp_encrypt(), and pgp_write_pubenc_sesskey().
void pushf_free | ( | PushFilter * | mp | ) |
Definition at line 411 of file mbuf.c.
References PushFilter::block_size, PushFilter::buf, PushFilterOps::free, PushFilter::op, PushFilter::priv, and px_free.
Referenced by init_compress(), init_litdata_packet(), pgp_write_pubenc_sesskey(), and pushf_free_all().
void pushf_free_all | ( | PushFilter * | mp | ) |
Definition at line 427 of file mbuf.c.
References PushFilter::next, and pushf_free().
Referenced by pgp_encrypt().
{ PushFilter *tmp; while (mp) { tmp = mp->next; pushf_free(mp); mp = tmp; } }
int pushf_write | ( | PushFilter * | mp, | |
const uint8 * | data, | |||
int | len | |||
) |
Definition at line 455 of file mbuf.c.
References PushFilter::block_size, PushFilter::buf, PushFilter::pos, and wrap_process().
Referenced by crlf_process(), encrypt_init(), encrypt_process(), init_compress(), init_litdata_packet(), mdc_flush(), mdc_write(), pgp_encrypt(), pgp_mpi_write(), pgp_write_pubenc_sesskey(), pkt_stream_flush(), pkt_stream_process(), wrap_process(), write_normal_header(), write_prefix(), write_symenc_sesskey(), and write_tag_only().
{ int need, res; /* * no buffering */ if (mp->block_size <= 0) return wrap_process(mp, data, len); /* * try to empty buffer */ need = mp->block_size - mp->pos; if (need > 0) { if (len < need) { memcpy(mp->buf + mp->pos, data, len); mp->pos += len; return 0; } memcpy(mp->buf + mp->pos, data, need); len -= need; data += need; } /* * buffer full, process */ res = wrap_process(mp, mp->buf, mp->block_size); if (res < 0) return res; mp->pos = 0; /* * now process directly from data */ while (len > 0) { if (len > mp->block_size) { res = wrap_process(mp, data, mp->block_size); if (res < 0) return res; data += mp->block_size; len -= mp->block_size; } else { memcpy(mp->buf, data, len); mp->pos += len; break; } } return 0; }