libksba  1.6.0
About: KSBA is a library to make the tasks of working with X.509 certificates, CMS data and related objects more easy.
  Fossies Dox: libksba-1.6.0.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

ber-decoder.c File Reference
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "util.h"
#include "ksba.h"
#include "asn1-func.h"
#include "ber-decoder.h"
#include "ber-help.h"
Include dependency graph for ber-decoder.c:

Go to the source code of this file.

Data Structures

struct  decoder_state_item_s
 
struct  decoder_state_s
 
struct  ber_decoder_s
 

Macros

#define MAX_IMAGE_LENGTH   (16 * 1024 * 1024)
 

Typedefs

typedef struct decoder_state_item_s DECODER_STATE_ITEM
 
typedef struct decoder_state_sDECODER_STATE
 

Functions

static int sum_a1_a2_gt_b (size_t a1, size_t a2, size_t b)
 
static int sum_a1_a2_ge_b (size_t a1, size_t a2, size_t b)
 
static DECODER_STATE new_decoder_state (void)
 
static void release_decoder_state (DECODER_STATE ds)
 
static void dump_decoder_state (DECODER_STATE ds)
 
static gpg_error_t push_decoder_state (DECODER_STATE ds)
 
static gpg_error_t pop_decoder_state (DECODER_STATE ds)
 
static int set_error (BerDecoder d, AsnNode node, const char *text)
 
static int eof_or_error (BerDecoder d, int premature)
 
static const char * universal_tag_name (unsigned long no)
 
static void dump_tlv (const struct tag_info *ti, FILE *fp)
 
static void clear_help_flags (AsnNode node)
 
static void prepare_copied_tree (AsnNode node)
 
static void fixup_type_any (AsnNode node)
 
BerDecoder _ksba_ber_decoder_new (void)
 
void _ksba_ber_decoder_release (BerDecoder d)
 
gpg_error_t _ksba_ber_decoder_set_module (BerDecoder d, ksba_asn_tree_t module)
 
gpg_error_t _ksba_ber_decoder_set_reader (BerDecoder d, ksba_reader_t r)
 
static int read_byte (ksba_reader_t reader)
 
static int read_buffer (ksba_reader_t reader, char *buffer, size_t count)
 
static int cmp_tag (AsnNode node, const struct tag_info *ti)
 
static AsnNode find_anchor_node (AsnNode root, const struct tag_info *ti)
 
static int match_der (AsnNode root, const struct tag_info *ti, DECODER_STATE ds, AsnNode *retnode, int debug)
 
static gpg_error_t decoder_init (BerDecoder d, const char *start_name)
 
static void decoder_deinit (BerDecoder d)
 
static gpg_error_t decoder_next (BerDecoder d)
 
static gpg_error_t decoder_skip (BerDecoder d)
 
static int distance (AsnNode root, AsnNode node)
 
gpg_error_t _ksba_ber_decoder_dump (BerDecoder d, FILE *fp)
 
gpg_error_t _ksba_ber_decoder_decode (BerDecoder d, const char *start_name, unsigned int flags, AsnNode *r_root, unsigned char **r_image, size_t *r_imagelen)
 

Macro Definition Documentation

◆ MAX_IMAGE_LENGTH

#define MAX_IMAGE_LENGTH   (16 * 1024 * 1024)

Definition at line 47 of file ber-decoder.c.

Typedef Documentation

◆ DECODER_STATE

typedef struct decoder_state_s* DECODER_STATE

Definition at line 69 of file ber-decoder.c.

◆ DECODER_STATE_ITEM

Definition at line 1 of file ber-decoder.c.

Function Documentation

◆ _ksba_ber_decoder_decode()

◆ _ksba_ber_decoder_dump()

◆ _ksba_ber_decoder_new()

BerDecoder _ksba_ber_decoder_new ( void  )

Definition at line 344 of file ber-decoder.c.

References xtrycalloc.

Referenced by _ksba_cert_read_der(), create_and_run_decoder(), and one_file().

◆ _ksba_ber_decoder_release()

void _ksba_ber_decoder_release ( BerDecoder  d)

Definition at line 356 of file ber-decoder.c.

References xfree.

Referenced by _ksba_cert_read_der(), create_and_run_decoder(), and one_file().

◆ _ksba_ber_decoder_set_module()

gpg_error_t _ksba_ber_decoder_set_module ( BerDecoder  d,
ksba_asn_tree_t  module 
)

_ksba_ber_decoder_set_module: @d: Decoder object @module: ASN.1 Parse tree

Initialize the decoder with the ASN.1 module. Note, that this is a shallow copy of the module. Hmmm: What about ref-counting of AsnNodes?

Return value: 0 on success or an error code

Definition at line 373 of file ber-decoder.c.

References GPG_ERR_INV_VALUE, gpg_error, ber_decoder_s::module, and ksba_asn_tree_s::parse_tree.

Referenced by _ksba_cert_read_der(), create_and_run_decoder(), and one_file().

◆ _ksba_ber_decoder_set_reader()

gpg_error_t _ksba_ber_decoder_set_reader ( BerDecoder  d,
ksba_reader_t  r 
)

◆ clear_help_flags()

static void clear_help_flags ( AsnNode  node)
static

◆ cmp_tag()

◆ decoder_deinit()

static void decoder_deinit ( BerDecoder  d)
static

◆ decoder_init()

static gpg_error_t decoder_init ( BerDecoder  d,
const char *  start_name 
)
static

◆ decoder_next()

◆ decoder_skip()

static gpg_error_t decoder_skip ( BerDecoder  d)
static

◆ distance()

static int distance ( AsnNode  root,
AsnNode  node 
)
static

Definition at line 1068 of file ber-decoder.c.

References asn_node_struct::left, and asn_node_struct::right.

Referenced by _ksba_ber_decoder_dump().

◆ dump_decoder_state()

◆ dump_tlv()

static void dump_tlv ( const struct tag_info ti,
FILE *  fp 
)
static

◆ eof_or_error()

static int eof_or_error ( BerDecoder  d,
int  premature 
)
static

◆ find_anchor_node()

static AsnNode find_anchor_node ( AsnNode  root,
const struct tag_info ti 
)
static

◆ fixup_type_any()

static void fixup_type_any ( AsnNode  node)
static

◆ match_der()

◆ new_decoder_state()

◆ pop_decoder_state()

static gpg_error_t pop_decoder_state ( DECODER_STATE  ds)
static

Definition at line 196 of file ber-decoder.c.

References decoder_state_s::cur, gpg_error, decoder_state_s::idx, and decoder_state_s::stack.

Referenced by decoder_next().

◆ prepare_copied_tree()

static void prepare_copied_tree ( AsnNode  node)
static

Definition at line 319 of file ber-decoder.c.

References _ksba_asn_walk_tree(), clear_help_flags(), and asn_node_struct::off.

Referenced by match_der().

◆ push_decoder_state()

static gpg_error_t push_decoder_state ( DECODER_STATE  ds)
static

◆ read_buffer()

static int read_buffer ( ksba_reader_t  reader,
char *  buffer,
size_t  count 
)
static

Definition at line 419 of file ber-decoder.c.

References DIM, and ksba_reader_read().

Referenced by _ksba_ber_decoder_decode(), and decoder_skip().

◆ read_byte()

static int read_byte ( ksba_reader_t  reader)
static

decoding machinery *************

Definition at line 404 of file ber-decoder.c.

References ksba_reader_read().

Referenced by _ksba_ber_decoder_decode(), and _ksba_ber_decoder_dump().

◆ release_decoder_state()

static void release_decoder_state ( DECODER_STATE  ds)
static

Definition at line 157 of file ber-decoder.c.

References xfree.

Referenced by decoder_deinit().

◆ set_error()

static int set_error ( BerDecoder  d,
AsnNode  node,
const char *  text 
)
static

◆ sum_a1_a2_ge_b()

static int sum_a1_a2_ge_b ( size_t  a1,
size_t  a2,
size_t  b 
)
inlinestatic

Definition at line 128 of file ber-decoder.c.

Referenced by decoder_next().

◆ sum_a1_a2_gt_b()

static int sum_a1_a2_gt_b ( size_t  a1,
size_t  a2,
size_t  b 
)
inlinestatic

Definition at line 120 of file ber-decoder.c.

Referenced by _ksba_ber_decoder_decode().

◆ universal_tag_name()

static const char* universal_tag_name ( unsigned long  no)
static

Definition at line 236 of file ber-decoder.c.

References DIM.

Referenced by dump_tlv().