aper_opentype.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 Lev Walkin <vlm@lionet.info>. All rights reserved.
3  * Redistribution and modifications are permitted subject to BSD license.
4  */
9 
10 static asn_dec_rval_t
12  const asn_TYPE_descriptor_t *td,
13  const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
14  asn_dec_rval_t rv;
15  ssize_t chunk_bytes;
16  int repeat;
17  uint8_t *buf = 0;
18  size_t bufLen = 0;
19  size_t bufSize = 0;
20  asn_per_data_t spd;
21  size_t padding;
22 
24 
25  ASN_DEBUG("Getting open type %s...", td->name);
26 
27  do {
28  chunk_bytes = aper_get_length(pd, -1, -1, -1, &repeat);
29  if(chunk_bytes < 0) {
30  FREEMEM(buf);
32  }
33  if(bufLen + chunk_bytes > bufSize) {
34  void *ptr;
35  bufSize = chunk_bytes + (bufSize << 2);
36  ptr = REALLOC(buf, bufSize);
37  if(!ptr) {
38  FREEMEM(buf);
40  }
41  buf = ptr;
42  }
43  if(per_get_many_bits(pd, buf + bufLen, 0, chunk_bytes << 3)) {
44  FREEMEM(buf);
46  }
47  bufLen += chunk_bytes;
48  } while(repeat);
49 
50  ASN_DEBUG("Getting open type %s encoded in %ld bytes", td->name,
51  (long)bufLen);
52 
53  memset(&spd, 0, sizeof(spd));
54  spd.buffer = buf;
55  spd.nbits = bufLen << 3;
56 
58  rv = td->op->aper_decoder(ctx, td, constraints, sptr, &spd);
60 
61  if(rv.code == RC_OK) {
62  /* Check padding validity */
63  padding = spd.nbits - spd.nboff;
64  if (((padding > 0 && padding < 8) ||
65  /* X.691#10.1.3 */
66  (spd.nboff == 0 && spd.nbits == 8 && spd.buffer == buf)) &&
67  per_get_few_bits(&spd, padding) == 0) {
68  /* Everything is cool */
69  FREEMEM(buf);
70  return rv;
71  }
72  FREEMEM(buf);
73  if(padding >= 8) {
74  ASN_DEBUG("Too large padding %d in open type", (int)padding);
76  } else {
77  ASN_DEBUG("No padding");
78  }
79  } else {
80  FREEMEM(buf);
81  /* rv.code could be RC_WMORE, nonsense in this context */
82  rv.code = RC_FAIL; /* Noone would give us more */
83  }
84 
85  return rv;
86 }
87 
88 int
90  const asn_per_constraints_t *constraints,
91  const void *sptr, asn_per_outp_t *po) {
92  void *buf;
93  void *bptr;
94  ssize_t size;
95  size_t toGo;
96 
97  ASN_DEBUG("Open type put %s ...", td->name);
98 
99  size = aper_encode_to_new_buffer(td, constraints, sptr, &buf);
100  if(size <= 0) return -1;
101 
102  for(bptr = buf, toGo = size; toGo;) {
103  int need_eom = 0;
104  ssize_t maySave = aper_put_length(po, -1, -1, toGo, &need_eom);
105  if(maySave < 0) break;
106  if(per_put_many_bits(po, bptr, maySave * 8)) break;
107  bptr = (char *)bptr + maySave;
108  toGo -= maySave;
109  if(need_eom && (aper_put_length(po, -1, -1, 0, NULL) < 0)) {
110  FREEMEM(buf);
111  return -1;
112  }
113  }
114 
115  FREEMEM(buf);
116  if(toGo) return -1;
117 
118  ASN_DEBUG("Open type put %s of length %zd + overhead (1byte?)",
119  td->name, size);
120 
121  return 0;
122 }
123 
126  const asn_TYPE_descriptor_t *td,
127  const asn_per_constraints_t *constraints,
128  void **sptr, asn_per_data_t *pd) {
129 
130  return aper_open_type_get_simple(ctx, td, constraints, sptr, pd);
131 }
132 
133 int
136  asn_dec_rval_t rv;
138 
139  memset(&op_t, 0, sizeof(op_t));
140  s_td.name = "<unknown extension>";
141  s_td.op = &op_t;
142  s_td.op->aper_decoder = uper_sot_suck;
143 
144  rv = aper_open_type_get(ctx, &s_td, 0, 0, pd);
145  if(rv.code != RC_OK)
146  return -1;
147  else
148  return 0;
149 }
asn_bit_outp_s
Definition: asn_bit_data.h:56
asn_TYPE_operation_s
Definition: constr_TYPE.h:184
asn_bit_data_s::buffer
const uint8_t * buffer
Definition: asn_bit_data.h:18
uper_sot_suck
asn_dec_rval_t uper_sot_suck(const asn_codec_ctx_t *, const asn_TYPE_descriptor_t *td, const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd)
Definition: per_opentype.c:12
asn_bit_data_s::nboff
size_t nboff
Definition: asn_bit_data.h:19
aper_support.h
asn_TYPE_descriptor_s::name
const char * name
Definition: constr_TYPE.h:225
aper_put_length
ssize_t aper_put_length(asn_per_outp_t *po, ssize_t lb, ssize_t ub, size_t n, int *opt_need_eom)
Definition: aper_support.c:196
aper_open_type_get
asn_dec_rval_t aper_open_type_get(const asn_codec_ctx_t *ctx, const asn_TYPE_descriptor_t *td, const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd)
Definition: aper_opentype.c:125
per_get_few_bits
#define per_get_few_bits(data, bits)
Definition: per_support.h:39
REALLOC
#define REALLOC(oldptr, size)
Definition: asn_internal.h:39
FREEMEM
#define FREEMEM(ptr)
Definition: asn_internal.h:40
asn_bit_data_s
Definition: asn_bit_data.h:17
asn_TYPE_descriptor_s
Definition: constr_TYPE.h:224
aper_open_type_get_simple
static asn_dec_rval_t aper_open_type_get_simple(const asn_codec_ctx_t *ctx, const asn_TYPE_descriptor_t *td, const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd)
Definition: aper_opentype.c:11
RC_OK
@ RC_OK
Definition: asn_codecs.h:82
asn_TYPE_descriptor_s::op
asn_TYPE_operation_t * op
Definition: constr_TYPE.h:232
aper_encoder.h
aper_get_length
ssize_t aper_get_length(asn_per_data_t *pd, ssize_t lb, ssize_t ub, int effective_bound_bits, int *repeat)
Definition: aper_support.c:20
asn_TYPE_operation_s::aper_decoder
per_type_decoder_f * aper_decoder
Definition: constr_TYPE.h:199
ASN__STACK_OVERFLOW_CHECK
static int CC_NOTUSED ASN__STACK_OVERFLOW_CHECK(const asn_codec_ctx_t *ctx)
Definition: asn_internal.h:165
per_put_many_bits
#define per_put_many_bits(out, src, nbits)
Definition: per_support.h:47
ASN__DECODE_STARVED
#define ASN__DECODE_STARVED
Definition: asn_codecs.h:97
per_get_many_bits
#define per_get_many_bits(data, dst, align, bits)
Definition: per_support.h:41
asn_internal.h
asn_bit_data_s::nbits
size_t nbits
Definition: asn_bit_data.h:20
asn_codec_ctx_s
Definition: asn_codecs.h:23
aper_open_type_skip
int aper_open_type_skip(const asn_codec_ctx_t *ctx, asn_per_data_t *pd)
Definition: aper_opentype.c:134
asn_dec_rval_s
Definition: asn_codecs.h:86
ASN__DECODE_FAILED
#define ASN__DECODE_FAILED
Definition: asn_codecs.h:90
aper_opentype.h
asn_per_constraints_s
Definition: per_support.h:30
ASN_DEBUG_INDENT_ADD
#define ASN_DEBUG_INDENT_ADD(i)
Definition: asn_internal.h:43
aper_encode_to_new_buffer
ssize_t aper_encode_to_new_buffer(const struct asn_TYPE_descriptor_s *td, const asn_per_constraints_t *constraints, const void *sptr, void **buffer_r)
RC_FAIL
@ RC_FAIL
Definition: asn_codecs.h:84
asn_dec_rval_s::code
enum asn_dec_rval_code_e code
Definition: asn_codecs.h:87
aper_open_type_put
int aper_open_type_put(const asn_TYPE_descriptor_t *td, const asn_per_constraints_t *constraints, const void *sptr, asn_per_outp_t *po)
Definition: aper_opentype.c:89


etsi_its_vam_ts_coding
Author(s): Jean-Pierre Busch , Guido Küppers , Lennart Reiher
autogenerated on Sun May 18 2025 02:30:55