Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 1 | /*- |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame] | 2 | * Copyright (c) 2004, 2005, 2006 Lev Walkin <vlm@lionet.info>. |
| 3 | * All rights reserved. |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 4 | * Redistribution and modifications are permitted subject to BSD license. |
| 5 | */ |
| 6 | /* |
Lev Walkin | 41635d3 | 2006-03-18 05:06:57 +0000 | [diff] [blame] | 7 | * Read the NativeInteger.h for the explanation wrt. differences between |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 8 | * INTEGER and NativeInteger. |
| 9 | * Basically, both are decoders and encoders of ASN.1 INTEGER type, but this |
| 10 | * implementation deals with the standard (machine-specific) representation |
| 11 | * of them instead of using the platform-independent buffer. |
| 12 | */ |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 13 | #include <asn_internal.h> |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 14 | #include <NativeInteger.h> |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 15 | |
| 16 | /* |
| 17 | * NativeInteger basic type description. |
| 18 | */ |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 19 | static ber_tlv_tag_t asn_DEF_NativeInteger_tags[] = { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 20 | (ASN_TAG_CLASS_UNIVERSAL | (2 << 2)) |
| 21 | }; |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 22 | asn_TYPE_descriptor_t asn_DEF_NativeInteger = { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 23 | "INTEGER", /* The ASN.1 type is still INTEGER */ |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 24 | "INTEGER", |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 25 | NativeInteger_free, |
| 26 | NativeInteger_print, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 27 | asn_generic_no_constraint, |
| 28 | NativeInteger_decode_ber, |
| 29 | NativeInteger_encode_der, |
Lev Walkin | 435cb28 | 2004-10-21 14:13:48 +0000 | [diff] [blame] | 30 | NativeInteger_decode_xer, |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 31 | NativeInteger_encode_xer, |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 32 | NativeInteger_decode_uper, /* Unaligned PER decoder */ |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame] | 33 | NativeInteger_encode_uper, /* Unaligned PER encoder */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 34 | 0, /* Use generic outmost tag fetcher */ |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 35 | asn_DEF_NativeInteger_tags, |
| 36 | sizeof(asn_DEF_NativeInteger_tags) / sizeof(asn_DEF_NativeInteger_tags[0]), |
| 37 | asn_DEF_NativeInteger_tags, /* Same as above */ |
| 38 | sizeof(asn_DEF_NativeInteger_tags) / sizeof(asn_DEF_NativeInteger_tags[0]), |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 39 | 0, /* No PER visible constraints */ |
Lev Walkin | 449f832 | 2004-08-20 13:23:42 +0000 | [diff] [blame] | 40 | 0, 0, /* No members */ |
Lev Walkin | d9bd775 | 2004-06-05 08:17:50 +0000 | [diff] [blame] | 41 | 0 /* No specifics */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | /* |
| 45 | * Decode INTEGER type. |
| 46 | */ |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 47 | asn_dec_rval_t |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 48 | NativeInteger_decode_ber(asn_codec_ctx_t *opt_codec_ctx, |
| 49 | asn_TYPE_descriptor_t *td, |
Lev Walkin | 8c3b854 | 2005-03-10 18:52:02 +0000 | [diff] [blame] | 50 | void **nint_ptr, const void *buf_ptr, size_t size, int tag_mode) { |
Lev Walkin | e0b56e0 | 2005-02-25 12:10:27 +0000 | [diff] [blame] | 51 | long *native = (long *)*nint_ptr; |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 52 | asn_dec_rval_t rval; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 53 | ber_tlv_len_t length; |
| 54 | |
| 55 | /* |
| 56 | * If the structure is not there, allocate it. |
| 57 | */ |
Lev Walkin | e0b56e0 | 2005-02-25 12:10:27 +0000 | [diff] [blame] | 58 | if(native == NULL) { |
| 59 | native = (long *)(*nint_ptr = CALLOC(1, sizeof(*native))); |
| 60 | if(native == NULL) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 61 | rval.code = RC_FAIL; |
| 62 | rval.consumed = 0; |
| 63 | return rval; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | ASN_DEBUG("Decoding %s as INTEGER (tm=%d)", |
| 68 | td->name, tag_mode); |
| 69 | |
| 70 | /* |
| 71 | * Check tags. |
| 72 | */ |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 73 | rval = ber_check_tags(opt_codec_ctx, td, 0, buf_ptr, size, |
| 74 | tag_mode, 0, &length, 0); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 75 | if(rval.code != RC_OK) |
| 76 | return rval; |
| 77 | |
| 78 | ASN_DEBUG("%s length is %d bytes", td->name, (int)length); |
| 79 | |
| 80 | /* |
| 81 | * Make sure we have this length. |
| 82 | */ |
Lev Walkin | 8c3b854 | 2005-03-10 18:52:02 +0000 | [diff] [blame] | 83 | buf_ptr = ((const char *)buf_ptr) + rval.consumed; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 84 | size -= rval.consumed; |
Lev Walkin | d9bd775 | 2004-06-05 08:17:50 +0000 | [diff] [blame] | 85 | if(length > (ber_tlv_len_t)size) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 86 | rval.code = RC_WMORE; |
| 87 | rval.consumed = 0; |
| 88 | return rval; |
| 89 | } |
| 90 | |
| 91 | /* |
| 92 | * ASN.1 encoded INTEGER: buf_ptr, length |
Lev Walkin | e0b56e0 | 2005-02-25 12:10:27 +0000 | [diff] [blame] | 93 | * Fill the native, at the same time checking for overflow. |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 94 | * If overflow occured, return with RC_FAIL. |
| 95 | */ |
| 96 | { |
| 97 | INTEGER_t tmp; |
Lev Walkin | 7e033b5 | 2005-07-02 08:19:17 +0000 | [diff] [blame] | 98 | union { |
| 99 | const void *constbuf; |
| 100 | void *nonconstbuf; |
| 101 | } unconst_buf; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 102 | long l; |
Lev Walkin | 7e033b5 | 2005-07-02 08:19:17 +0000 | [diff] [blame] | 103 | |
| 104 | unconst_buf.constbuf = buf_ptr; |
| 105 | tmp.buf = (uint8_t *)unconst_buf.nonconstbuf; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 106 | tmp.size = length; |
| 107 | |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 108 | if(asn_INTEGER2long(&tmp, &l)) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 109 | rval.code = RC_FAIL; |
| 110 | rval.consumed = 0; |
| 111 | return rval; |
| 112 | } |
| 113 | |
Lev Walkin | e0b56e0 | 2005-02-25 12:10:27 +0000 | [diff] [blame] | 114 | *native = l; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | rval.code = RC_OK; |
| 118 | rval.consumed += length; |
| 119 | |
Lev Walkin | e0b56e0 | 2005-02-25 12:10:27 +0000 | [diff] [blame] | 120 | ASN_DEBUG("Took %ld/%ld bytes to encode %s (%ld)", |
| 121 | (long)rval.consumed, (long)length, td->name, (long)*native); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 122 | |
| 123 | return rval; |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * Encode the NativeInteger using the standard INTEGER type DER encoder. |
| 128 | */ |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 129 | asn_enc_rval_t |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 130 | NativeInteger_encode_der(asn_TYPE_descriptor_t *sd, void *ptr, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 131 | int tag_mode, ber_tlv_tag_t tag, |
| 132 | asn_app_consume_bytes_f *cb, void *app_key) { |
Lev Walkin | e0b56e0 | 2005-02-25 12:10:27 +0000 | [diff] [blame] | 133 | unsigned long native = *(unsigned long *)ptr; /* Disable sign ext. */ |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 134 | asn_enc_rval_t erval; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 135 | INTEGER_t tmp; |
| 136 | |
| 137 | #ifdef WORDS_BIGENDIAN /* Opportunistic optimization */ |
| 138 | |
Lev Walkin | e0b56e0 | 2005-02-25 12:10:27 +0000 | [diff] [blame] | 139 | tmp.buf = (uint8_t *)&native; |
| 140 | tmp.size = sizeof(native); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 141 | |
| 142 | #else /* Works even if WORDS_BIGENDIAN is not set where should've been */ |
Lev Walkin | e0b56e0 | 2005-02-25 12:10:27 +0000 | [diff] [blame] | 143 | uint8_t buf[sizeof(native)]; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 144 | uint8_t *p; |
| 145 | |
Lev Walkin | d54f255 | 2004-10-27 13:24:51 +0000 | [diff] [blame] | 146 | /* Prepare a fake INTEGER */ |
Lev Walkin | e0b56e0 | 2005-02-25 12:10:27 +0000 | [diff] [blame] | 147 | for(p = buf + sizeof(buf) - 1; p >= buf; p--, native >>= 8) |
| 148 | *p = native; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 149 | |
| 150 | tmp.buf = buf; |
| 151 | tmp.size = sizeof(buf); |
| 152 | #endif /* WORDS_BIGENDIAN */ |
| 153 | |
| 154 | /* Encode fake INTEGER */ |
| 155 | erval = INTEGER_encode_der(sd, &tmp, tag_mode, tag, cb, app_key); |
| 156 | if(erval.encoded == -1) { |
| 157 | assert(erval.structure_ptr == &tmp); |
| 158 | erval.structure_ptr = ptr; |
| 159 | } |
| 160 | return erval; |
| 161 | } |
| 162 | |
Lev Walkin | 435cb28 | 2004-10-21 14:13:48 +0000 | [diff] [blame] | 163 | /* |
| 164 | * Decode the chunk of XML text encoding INTEGER. |
| 165 | */ |
| 166 | asn_dec_rval_t |
| 167 | NativeInteger_decode_xer(asn_codec_ctx_t *opt_codec_ctx, |
| 168 | asn_TYPE_descriptor_t *td, void **sptr, const char *opt_mname, |
Lev Walkin | 8c3b854 | 2005-03-10 18:52:02 +0000 | [diff] [blame] | 169 | const void *buf_ptr, size_t size) { |
Lev Walkin | 435cb28 | 2004-10-21 14:13:48 +0000 | [diff] [blame] | 170 | asn_dec_rval_t rval; |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 171 | INTEGER_t st; |
Lev Walkin | f0b7c9a | 2005-01-27 17:54:57 +0000 | [diff] [blame] | 172 | void *st_ptr = (void *)&st; |
Lev Walkin | e0b56e0 | 2005-02-25 12:10:27 +0000 | [diff] [blame] | 173 | long *native = (long *)*sptr; |
Lev Walkin | 435cb28 | 2004-10-21 14:13:48 +0000 | [diff] [blame] | 174 | |
Lev Walkin | e0b56e0 | 2005-02-25 12:10:27 +0000 | [diff] [blame] | 175 | if(!native) { |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 176 | native = (long *)(*sptr = CALLOC(1, sizeof(*native))); |
| 177 | if(!native) _ASN_DECODE_FAILED; |
Lev Walkin | 435cb28 | 2004-10-21 14:13:48 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 180 | memset(&st, 0, sizeof(st)); |
| 181 | rval = INTEGER_decode_xer(opt_codec_ctx, td, &st_ptr, |
Lev Walkin | f0b7c9a | 2005-01-27 17:54:57 +0000 | [diff] [blame] | 182 | opt_mname, buf_ptr, size); |
Lev Walkin | 435cb28 | 2004-10-21 14:13:48 +0000 | [diff] [blame] | 183 | if(rval.code == RC_OK) { |
| 184 | long l; |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 185 | if(asn_INTEGER2long(&st, &l)) { |
Lev Walkin | 435cb28 | 2004-10-21 14:13:48 +0000 | [diff] [blame] | 186 | rval.code = RC_FAIL; |
| 187 | rval.consumed = 0; |
| 188 | } else { |
Lev Walkin | e0b56e0 | 2005-02-25 12:10:27 +0000 | [diff] [blame] | 189 | *native = l; |
Lev Walkin | 435cb28 | 2004-10-21 14:13:48 +0000 | [diff] [blame] | 190 | } |
| 191 | } else { |
Lev Walkin | e0b56e0 | 2005-02-25 12:10:27 +0000 | [diff] [blame] | 192 | /* |
| 193 | * Cannot restart from the middle; |
| 194 | * there is no place to save state in the native type. |
| 195 | * Request a continuation from the very beginning. |
| 196 | */ |
Lev Walkin | 435cb28 | 2004-10-21 14:13:48 +0000 | [diff] [blame] | 197 | rval.consumed = 0; |
| 198 | } |
Lev Walkin | adcb586 | 2006-03-17 02:11:12 +0000 | [diff] [blame] | 199 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &st); |
Lev Walkin | 435cb28 | 2004-10-21 14:13:48 +0000 | [diff] [blame] | 200 | return rval; |
| 201 | } |
| 202 | |
| 203 | |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 204 | asn_enc_rval_t |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 205 | NativeInteger_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 206 | int ilevel, enum xer_encoder_flags_e flags, |
| 207 | asn_app_consume_bytes_f *cb, void *app_key) { |
| 208 | char scratch[32]; /* Enough for 64-bit int */ |
| 209 | asn_enc_rval_t er; |
Lev Walkin | e0b56e0 | 2005-02-25 12:10:27 +0000 | [diff] [blame] | 210 | const long *native = (const long *)sptr; |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 211 | |
| 212 | (void)ilevel; |
| 213 | (void)flags; |
| 214 | |
Lev Walkin | e0b56e0 | 2005-02-25 12:10:27 +0000 | [diff] [blame] | 215 | if(!native) _ASN_ENCODE_FAILED; |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 216 | |
Lev Walkin | e0b56e0 | 2005-02-25 12:10:27 +0000 | [diff] [blame] | 217 | er.encoded = snprintf(scratch, sizeof(scratch), "%ld", *native); |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 218 | if(er.encoded <= 0 || (size_t)er.encoded >= sizeof(scratch) |
| 219 | || cb(scratch, er.encoded, app_key) < 0) |
| 220 | _ASN_ENCODE_FAILED; |
| 221 | |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 222 | _ASN_ENCODED_OK(er); |
| 223 | } |
| 224 | |
| 225 | asn_dec_rval_t |
| 226 | NativeInteger_decode_uper(asn_codec_ctx_t *opt_codec_ctx, |
| 227 | asn_TYPE_descriptor_t *td, |
| 228 | asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) { |
| 229 | |
| 230 | asn_dec_rval_t rval; |
| 231 | long *native = (long *)*sptr; |
| 232 | INTEGER_t tmpint; |
| 233 | void *tmpintptr = &tmpint; |
| 234 | |
| 235 | (void)opt_codec_ctx; |
| 236 | ASN_DEBUG("Decoding NativeInteger %s (UPER)", td->name); |
| 237 | |
| 238 | if(!native) { |
| 239 | native = (long *)(*sptr = CALLOC(1, sizeof(*native))); |
| 240 | if(!native) _ASN_DECODE_FAILED; |
| 241 | } |
| 242 | |
| 243 | memset(&tmpint, 0, sizeof tmpint); |
| 244 | rval = INTEGER_decode_uper(opt_codec_ctx, td, constraints, |
| 245 | &tmpintptr, pd); |
Lev Walkin | b2bed82 | 2005-11-27 12:40:43 +0000 | [diff] [blame] | 246 | if(rval.code == RC_OK) { |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 247 | if(asn_INTEGER2long(&tmpint, native)) |
| 248 | rval.code = RC_FAIL; |
| 249 | else |
| 250 | ASN_DEBUG("NativeInteger %s got value %ld", |
| 251 | td->name, *native); |
Lev Walkin | b2bed82 | 2005-11-27 12:40:43 +0000 | [diff] [blame] | 252 | } |
Lev Walkin | adcb586 | 2006-03-17 02:11:12 +0000 | [diff] [blame] | 253 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &tmpint); |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 254 | |
| 255 | return rval; |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame] | 258 | asn_enc_rval_t |
| 259 | NativeInteger_encode_uper(asn_TYPE_descriptor_t *td, |
| 260 | asn_per_constraints_t *constraints, void *sptr, asn_per_outp_t *po) { |
| 261 | asn_enc_rval_t er; |
| 262 | long native; |
| 263 | INTEGER_t tmpint; |
| 264 | |
| 265 | if(!sptr) _ASN_ENCODE_FAILED; |
| 266 | |
| 267 | native = *(long *)sptr; |
| 268 | |
| 269 | ASN_DEBUG("Encoding NativeInteger %s %ld (UPER)", td->name, native); |
| 270 | |
| 271 | memset(&tmpint, 0, sizeof(tmpint)); |
| 272 | if(asn_long2INTEGER(&tmpint, native)) |
| 273 | _ASN_ENCODE_FAILED; |
| 274 | er = INTEGER_encode_uper(td, constraints, &tmpint, po); |
| 275 | ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &tmpint); |
| 276 | return er; |
| 277 | } |
| 278 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 279 | /* |
| 280 | * INTEGER specific human-readable output. |
| 281 | */ |
| 282 | int |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 283 | NativeInteger_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 284 | asn_app_consume_bytes_f *cb, void *app_key) { |
Lev Walkin | e0b56e0 | 2005-02-25 12:10:27 +0000 | [diff] [blame] | 285 | const long *native = (const long *)sptr; |
Lev Walkin | db13f51 | 2004-07-19 17:30:25 +0000 | [diff] [blame] | 286 | char scratch[32]; /* Enough for 64-bit int */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 287 | int ret; |
| 288 | |
Lev Walkin | d9bd775 | 2004-06-05 08:17:50 +0000 | [diff] [blame] | 289 | (void)td; /* Unused argument */ |
| 290 | (void)ilevel; /* Unused argument */ |
| 291 | |
Lev Walkin | e0b56e0 | 2005-02-25 12:10:27 +0000 | [diff] [blame] | 292 | if(native) { |
| 293 | ret = snprintf(scratch, sizeof(scratch), "%ld", *native); |
| 294 | assert(ret > 0 && (size_t)ret < sizeof(scratch)); |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 295 | return (cb(scratch, ret, app_key) < 0) ? -1 : 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 296 | } else { |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 297 | return (cb("<absent>", 8, app_key) < 0) ? -1 : 0; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | |
| 301 | void |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 302 | NativeInteger_free(asn_TYPE_descriptor_t *td, void *ptr, int contents_only) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 303 | |
| 304 | if(!td || !ptr) |
| 305 | return; |
| 306 | |
| 307 | ASN_DEBUG("Freeing %s as INTEGER (%d, %p, Native)", |
| 308 | td->name, contents_only, ptr); |
| 309 | |
| 310 | if(!contents_only) { |
| 311 | FREEMEM(ptr); |
| 312 | } |
| 313 | } |
| 314 | |