2 * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>.
4 * Redistribution and modifications are permitted subject to BSD license.
6 #include <asn_internal.h>
7 #include <OCTET_STRING.h>
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];
20 (void)td; /* Unused argument */
22 if(!st || (!st->buf && st->size))
23 return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;
26 * Dump the contents of the buffer in hexadecimal.
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)
37 *p++ = h2c[(*buf >> 4) & 0x0F];
38 *p++ = h2c[*buf & 0x0F];
43 p--; /* Remove the tail space */
44 if(cb(scratch, p - scratch, app_key) < 0)
52 OCTET_STRING_print_utf8(const asn_TYPE_descriptor_t *td, const void *sptr,
53 int ilevel, asn_app_consume_bytes_f *cb,
55 const OCTET_STRING_t *st = (const OCTET_STRING_t *)sptr;
57 (void)td; /* Unused argument */
58 (void)ilevel; /* Unused argument */
60 if(st && (st->buf || !st->size)) {
61 return (cb(st->buf, st->size, app_key) < 0) ? -1 : 0;
63 return (cb("<absent>", 8, app_key) < 0) ? -1 : 0;