OCTET_STRING_print.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>.
3  * All rights reserved.
4  * Redistribution and modifications are permitted subject to BSD license.
5  */
8 
9 int
10 OCTET_STRING_print(const asn_TYPE_descriptor_t *td, const void *sptr,
11  int ilevel, asn_app_consume_bytes_f *cb, void *app_key) {
12  const char * const h2c = "0123456789ABCDEF";
13  const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr;
14  char scratch[16 * 3 + 4];
15  char *p = scratch;
16  uint8_t *buf;
17  uint8_t *end;
18  size_t i;
19 
20  (void)td; /* Unused argument */
21 
22  if(!st || (!st->buf && st->size))
23  return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
24 
25  /*
26  * Dump the contents of the buffer in hexadecimal.
27  */
28  buf = st->buf;
29  end = (buf == NULL)? NULL : buf + st->size;
30  for(i = 0; buf < end; buf++, i++) {
31  if(!(i % 16) && (i || st->size > 16)) {
32  if(cb(scratch, p - scratch, app_key) < 0)
33  return -1;
34  _i_INDENT(1);
35  p = scratch;
36  }
37  *p++ = h2c[(*buf >> 4) & 0x0F];
38  *p++ = h2c[*buf & 0x0F];
39  *p++ = 0x20;
40  }
41 
42  if(p > scratch) {
43  p--; /* Remove the tail space */
44  if(cb(scratch, p - scratch, app_key) < 0)
45  return -1;
46  }
47 
48  return 0;
49 }
50 
51 int
52 OCTET_STRING_print_utf8(const asn_TYPE_descriptor_t *td, const void *sptr,
53  int ilevel, asn_app_consume_bytes_f *cb,
54  void *app_key) {
55  const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr;
56 
57  (void)td; /* Unused argument */
58  (void)ilevel; /* Unused argument */
59 
60  if(st && (st->buf || !st->size)) {
61  return (cb(st->buf, st->size, app_key) < 0) ? -1 : 0;
62  } else {
63  return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
64  }
65 }
OCTET_STRING::buf
uint8_t * buf
Definition: OCTET_STRING.h:15
OCTET_STRING_print_utf8
int OCTET_STRING_print_utf8(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, asn_app_consume_bytes_f *cb, void *app_key)
Definition: OCTET_STRING_print.c:52
asn_TYPE_descriptor_s
Definition: constr_TYPE.h:224
OCTET_STRING_print
int OCTET_STRING_print(const asn_TYPE_descriptor_t *td, const void *sptr, int ilevel, asn_app_consume_bytes_f *cb, void *app_key)
Definition: OCTET_STRING_print.c:10
OCTET_STRING
Definition: OCTET_STRING.h:14
asn_app_consume_bytes_f
int() asn_app_consume_bytes_f(const void *buffer, size_t size, void *application_specific_key)
Definition: asn_application.h:124
asn_internal.h
_i_INDENT
#define _i_INDENT(nl)
Definition: asn_internal.h:127
OCTET_STRING.h
OCTET_STRING::size
size_t size
Definition: OCTET_STRING.h:16


etsi_its_spatem_ts_coding
Author(s): Jean-Pierre Busch , Guido Küppers , Lennart Reiher
autogenerated on Sun May 18 2025 02:29:28