Lines Matching refs:b
59 asn_get_header(struct asn_buf *b, u_char *type, asn_len_t *len) in asn_get_header() argument
63 if (b->asn_len == 0) { in asn_get_header()
64 asn_error(b, "no identifier for header"); in asn_get_header()
67 *type = *b->asn_cptr; in asn_get_header()
69 asn_error(b, "tags > 0x1e not supported (%#x)", in asn_get_header()
73 b->asn_cptr++; in asn_get_header()
74 b->asn_len--; in asn_get_header()
75 if (b->asn_len == 0) { in asn_get_header()
76 asn_error(b, "no length field"); in asn_get_header()
79 if (*b->asn_cptr & 0x80) { in asn_get_header()
80 length = *b->asn_cptr++ & 0x7f; in asn_get_header()
81 b->asn_len--; in asn_get_header()
83 asn_error(b, "indefinite length not supported"); in asn_get_header()
87 asn_error(b, "long length too long (%u)", length); in asn_get_header()
90 if (length > b->asn_len) { in asn_get_header()
91 asn_error(b, "long length truncated"); in asn_get_header()
96 *len = (*len << 8) | *b->asn_cptr++; in asn_get_header()
97 b->asn_len--; in asn_get_header()
100 *len = *b->asn_cptr++; in asn_get_header()
101 b->asn_len--; in asn_get_header()
111 if (*len > b->asn_len) { in asn_get_header()
112 asn_error(b, "lenen %u exceeding asn_len %u", *len, b->asn_len); in asn_get_header()
162 asn_put_header(struct asn_buf *b, u_char type, asn_len_t len) in asn_put_header() argument
172 if (b->asn_len == 0) in asn_put_header()
175 *b->asn_ptr++ = type; in asn_put_header()
176 b->asn_len--; in asn_put_header()
181 if (b->asn_len < lenlen) in asn_put_header()
184 (void)asn_put_len(b->asn_ptr, len); in asn_put_header()
185 b->asn_ptr += lenlen; in asn_put_header()
186 b->asn_len -= lenlen; in asn_put_header()
200 asn_put_temp_header(struct asn_buf *b, u_char type, u_char **ptr) in asn_put_temp_header() argument
204 if (b->asn_len < TEMP_LEN) in asn_put_temp_header()
206 *ptr = b->asn_ptr; in asn_put_temp_header()
207 if ((ret = asn_put_header(b, type, ASN_MAXLEN)) == ASN_ERR_OK) in asn_put_temp_header()
208 assert(b->asn_ptr == *ptr + TEMP_LEN); in asn_put_temp_header()
212 asn_commit_header(struct asn_buf *b, u_char *ptr, size_t *moved) in asn_commit_header() argument
218 len = b->asn_ptr - (ptr + TEMP_LEN); in asn_commit_header()
229 b->asn_ptr -= shift; in asn_commit_header()
230 b->asn_len += shift; in asn_commit_header()
246 asn_get_real_integer(struct asn_buf *b, asn_len_t len, int64_t *vp) in asn_get_real_integer() argument
252 if (b->asn_len < len) { in asn_get_real_integer()
253 asn_error(b, "truncated integer"); in asn_get_real_integer()
257 asn_error(b, "zero-length integer"); in asn_get_real_integer()
263 asn_error(b, "integer too long"); in asn_get_real_integer()
266 ((*b->asn_cptr == 0x00 && (b->asn_cptr[1] & 0x80) == 0) || in asn_get_real_integer()
267 (*b->asn_cptr == 0xff && (b->asn_cptr[1] & 0x80) == 0x80))) { in asn_get_real_integer()
268 asn_error(b, "non-minimal integer"); in asn_get_real_integer()
272 if (*b->asn_cptr & 0x80) in asn_get_real_integer()
277 val |= neg ? (u_char)~*b->asn_cptr : *b->asn_cptr; in asn_get_real_integer()
278 b->asn_len--; in asn_get_real_integer()
279 b->asn_cptr++; in asn_get_real_integer()
293 asn_put_real_integer(struct asn_buf *b, u_char type, int64_t ival) in asn_put_real_integer() argument
321 if ((ret = asn_put_header(b, type, OCTETS - i))) in asn_put_real_integer()
323 if (OCTETS - (u_int)i > b->asn_len) in asn_put_real_integer()
327 *b->asn_ptr++ = buf[i++]; in asn_put_real_integer()
328 b->asn_len--; in asn_put_real_integer()
341 asn_get_real_unsigned(struct asn_buf *b, asn_len_t len, uint64_t *vp) in asn_get_real_unsigned() argument
344 if (b->asn_len < len) { in asn_get_real_unsigned()
345 asn_error(b, "truncated integer"); in asn_get_real_unsigned()
350 asn_error(b, "zero-length integer"); in asn_get_real_unsigned()
353 if (len > 1 && *b->asn_cptr == 0x00 && (b->asn_cptr[1] & 0x80) == 0) { in asn_get_real_unsigned()
355 asn_error(b, "non-minimal unsigned"); in asn_get_real_unsigned()
356 b->asn_cptr += len; in asn_get_real_unsigned()
357 b->asn_len -= len; in asn_get_real_unsigned()
364 if ((*b->asn_cptr & 0x80) || len > 9 || in asn_get_real_unsigned()
365 (len == 9 && *b->asn_cptr != 0)) { in asn_get_real_unsigned()
368 asn_error(b, "unsigned too large or negative"); in asn_get_real_unsigned()
369 b->asn_cptr += len; in asn_get_real_unsigned()
370 b->asn_len -= len; in asn_get_real_unsigned()
375 *vp = (*vp << 8) | *b->asn_cptr++; in asn_get_real_unsigned()
376 b->asn_len--; in asn_get_real_unsigned()
386 asn_put_real_unsigned(struct asn_buf *b, u_char type, uint64_t val) in asn_put_real_unsigned() argument
402 if ((ret = asn_put_header(b, type, OCTETS - i))) in asn_put_real_unsigned()
404 if (OCTETS - (u_int)i > b->asn_len) in asn_put_real_unsigned()
408 *b->asn_ptr++ = buf[i++]; in asn_put_real_unsigned()
409 b->asn_len--; in asn_put_real_unsigned()
419 asn_get_integer_raw(struct asn_buf *b, asn_len_t len, int32_t *vp) in asn_get_integer_raw() argument
424 if ((ret = asn_get_real_integer(b, len, &val)) == ASN_ERR_OK) { in asn_get_integer_raw()
426 asn_error(b, "integer too long"); in asn_get_integer_raw()
430 asn_error(b, "integer out of range"); in asn_get_integer_raw()
439 asn_get_integer(struct asn_buf *b, int32_t *vp) in asn_get_integer() argument
445 if ((err = asn_get_header(b, &type, &len)) != ASN_ERR_OK) in asn_get_integer()
448 asn_error(b, "bad type for integer (%u)", type); in asn_get_integer()
452 return (asn_get_integer_raw(b, len, vp)); in asn_get_integer()
456 asn_put_integer(struct asn_buf *b, int32_t val) in asn_put_integer() argument
458 return (asn_put_real_integer(b, ASN_TYPE_INTEGER, val)); in asn_put_integer()
471 asn_get_octetstring_raw(struct asn_buf *b, asn_len_t len, u_char *octets, in asn_get_octetstring_raw() argument
477 asn_error(b, "octetstring truncated"); in asn_get_octetstring_raw()
480 if (b->asn_len < len) { in asn_get_octetstring_raw()
481 asn_error(b, "truncatet octetstring"); in asn_get_octetstring_raw()
485 memcpy(octets, b->asn_cptr, *noctets); in asn_get_octetstring_raw()
487 memcpy(octets, b->asn_cptr, len); in asn_get_octetstring_raw()
489 b->asn_cptr += len; in asn_get_octetstring_raw()
490 b->asn_len -= len; in asn_get_octetstring_raw()
495 asn_get_octetstring(struct asn_buf *b, u_char *octets, u_int *noctets) in asn_get_octetstring() argument
501 if ((err = asn_get_header(b, &type, &len)) != ASN_ERR_OK) in asn_get_octetstring()
504 asn_error(b, "bad type for octetstring (%u)", type); in asn_get_octetstring()
507 return (asn_get_octetstring_raw(b, len, octets, noctets)); in asn_get_octetstring()
511 asn_put_octetstring(struct asn_buf *b, const u_char *octets, u_int noctets) in asn_put_octetstring() argument
515 if ((ret = asn_put_header(b, ASN_TYPE_OCTETSTRING, noctets)) != ASN_ERR_OK) in asn_put_octetstring()
517 if (b->asn_len < noctets) in asn_put_octetstring()
520 memcpy(b->asn_ptr, octets, noctets); in asn_put_octetstring()
521 b->asn_ptr += noctets; in asn_put_octetstring()
522 b->asn_len -= noctets; in asn_put_octetstring()
532 asn_get_null_raw(struct asn_buf *b, asn_len_t len) in asn_get_null_raw() argument
535 if (b->asn_len < len) { in asn_get_null_raw()
536 asn_error(b, "truncated NULL"); in asn_get_null_raw()
539 asn_error(b, "bad length for NULL (%u)", len); in asn_get_null_raw()
540 b->asn_len -= len; in asn_get_null_raw()
541 b->asn_ptr += len; in asn_get_null_raw()
548 asn_get_null(struct asn_buf *b) in asn_get_null() argument
554 if ((err = asn_get_header(b, &type, &len)) != ASN_ERR_OK) in asn_get_null()
557 asn_error(b, "bad type for NULL (%u)", type); in asn_get_null()
560 return (asn_get_null_raw(b, len)); in asn_get_null()
564 asn_put_null(struct asn_buf *b) in asn_put_null() argument
566 return (asn_put_header(b, ASN_TYPE_NULL, 0)); in asn_put_null()
570 asn_put_exception(struct asn_buf *b, u_int except) in asn_put_exception() argument
572 return (asn_put_header(b, ASN_CLASS_CONTEXT | except, 0)); in asn_put_exception()
581 asn_get_objid_raw(struct asn_buf *b, asn_len_t len, struct asn_oid *oid) in asn_get_objid_raw() argument
586 if (b->asn_len < len) { in asn_get_objid_raw()
587 asn_error(b, "truncated OBJID"); in asn_get_objid_raw()
592 asn_error(b, "short OBJID"); in asn_get_objid_raw()
600 asn_error(b, "OID too long (%u)", oid->len); in asn_get_objid_raw()
601 b->asn_cptr += len; in asn_get_objid_raw()
602 b->asn_len -= len; in asn_get_objid_raw()
608 asn_error(b, "unterminated subid"); in asn_get_objid_raw()
612 asn_error(b, "OID subid too larger"); in asn_get_objid_raw()
615 subid = (subid << 7) | (*b->asn_cptr & 0x7f); in asn_get_objid_raw()
617 b->asn_len--; in asn_get_objid_raw()
618 } while (*b->asn_cptr++ & 0x80); in asn_get_objid_raw()
636 asn_get_objid(struct asn_buf *b, struct asn_oid *oid) in asn_get_objid() argument
642 if ((err = asn_get_header(b, &type, &len)) != ASN_ERR_OK) in asn_get_objid()
645 asn_error(b, "bad type for OBJID (%u)", type); in asn_get_objid()
648 return (asn_get_objid_raw(b, len, oid)); in asn_get_objid()
652 asn_put_objid(struct asn_buf *b, const struct asn_oid *oid) in asn_put_objid() argument
702 if ((err1 = asn_put_header(b, ASN_TYPE_OBJID, len)) != ASN_ERR_OK) in asn_put_objid()
704 if (b->asn_len < len) in asn_put_objid()
710 *b->asn_ptr++ = sub; in asn_put_objid()
711 b->asn_len--; in asn_put_objid()
713 *b->asn_ptr++ = (sub >> 7) | 0x80; in asn_put_objid()
714 *b->asn_ptr++ = sub & 0x7f; in asn_put_objid()
715 b->asn_len -= 2; in asn_put_objid()
717 *b->asn_ptr++ = (sub >> 14) | 0x80; in asn_put_objid()
718 *b->asn_ptr++ = ((sub >> 7) & 0x7f) | 0x80; in asn_put_objid()
719 *b->asn_ptr++ = sub & 0x7f; in asn_put_objid()
720 b->asn_len -= 3; in asn_put_objid()
722 *b->asn_ptr++ = (sub >> 21) | 0x80; in asn_put_objid()
723 *b->asn_ptr++ = ((sub >> 14) & 0x7f) | 0x80; in asn_put_objid()
724 *b->asn_ptr++ = ((sub >> 7) & 0x7f) | 0x80; in asn_put_objid()
725 *b->asn_ptr++ = sub & 0x7f; in asn_put_objid()
726 b->asn_len -= 4; in asn_put_objid()
728 *b->asn_ptr++ = (sub >> 28) | 0x80; in asn_put_objid()
729 *b->asn_ptr++ = ((sub >> 21) & 0x7f) | 0x80; in asn_put_objid()
730 *b->asn_ptr++ = ((sub >> 14) & 0x7f) | 0x80; in asn_put_objid()
731 *b->asn_ptr++ = ((sub >> 7) & 0x7f) | 0x80; in asn_put_objid()
732 *b->asn_ptr++ = sub & 0x7f; in asn_put_objid()
733 b->asn_len -= 5; in asn_put_objid()
744 asn_get_sequence(struct asn_buf *b, asn_len_t *len) in asn_get_sequence() argument
749 if ((err = asn_get_header(b, &type, len)) != ASN_ERR_OK) in asn_get_sequence()
752 asn_error(b, "bad sequence type %u", type); in asn_get_sequence()
755 if (*len > b->asn_len) { in asn_get_sequence()
756 asn_error(b, "truncated sequence"); in asn_get_sequence()
768 asn_get_ipaddress_raw(struct asn_buf *b, asn_len_t len, u_char *addr) in asn_get_ipaddress_raw() argument
772 if (b->asn_len < len) { in asn_get_ipaddress_raw()
773 asn_error(b, "truncated ip-address"); in asn_get_ipaddress_raw()
777 asn_error(b, "short length for ip-Address %u", len); in asn_get_ipaddress_raw()
779 *addr++ = *b->asn_cptr++; in asn_get_ipaddress_raw()
782 b->asn_len -= len; in asn_get_ipaddress_raw()
786 *addr++ = *b->asn_cptr++; in asn_get_ipaddress_raw()
787 b->asn_cptr += len - 4; in asn_get_ipaddress_raw()
788 b->asn_len -= len; in asn_get_ipaddress_raw()
793 asn_get_ipaddress(struct asn_buf *b, u_char *addr) in asn_get_ipaddress() argument
799 if ((err = asn_get_header(b, &type, &len)) != ASN_ERR_OK) in asn_get_ipaddress()
802 asn_error(b, "bad type for ip-address %u", type); in asn_get_ipaddress()
805 return (asn_get_ipaddress_raw(b, len, addr)); in asn_get_ipaddress()
809 asn_put_ipaddress(struct asn_buf *b, const u_char *addr) in asn_put_ipaddress() argument
813 if ((err = asn_put_header(b, ASN_CLASS_APPLICATION|ASN_APP_IPADDRESS, in asn_put_ipaddress()
816 if (b->asn_len < 4) in asn_put_ipaddress()
819 memcpy(b->asn_ptr, addr, 4); in asn_put_ipaddress()
820 b->asn_ptr += 4; in asn_put_ipaddress()
821 b->asn_len -= 4; in asn_put_ipaddress()
832 asn_get_uint32_raw(struct asn_buf *b, asn_len_t len, uint32_t *vp) in asn_get_uint32_raw() argument
837 if ((err = asn_get_real_unsigned(b, len, &v)) == ASN_ERR_OK) { in asn_get_uint32_raw()
839 asn_error(b, "uint32 too large %llu", v); in asn_get_uint32_raw()
848 asn_put_uint32(struct asn_buf *b, u_char type, uint32_t val) in asn_put_uint32() argument
852 return (asn_put_real_unsigned(b, ASN_CLASS_APPLICATION|type, v)); in asn_put_uint32()
860 asn_get_counter64_raw(struct asn_buf *b, asn_len_t len, uint64_t *vp) in asn_get_counter64_raw() argument
862 return (asn_get_real_unsigned(b, len, vp)); in asn_get_counter64_raw()
866 asn_put_counter64(struct asn_buf *b, uint64_t val) in asn_put_counter64() argument
868 return (asn_put_real_unsigned(b, in asn_put_counter64()
877 asn_get_timeticks(struct asn_buf *b, uint32_t *vp) in asn_get_timeticks() argument
883 if ((err = asn_get_header(b, &type, &len)) != ASN_ERR_OK) in asn_get_timeticks()
886 asn_error(b, "bad type for timeticks %u", type); in asn_get_timeticks()
889 return (asn_get_uint32_raw(b, len, vp)); in asn_get_timeticks()
893 asn_put_timeticks(struct asn_buf *b, uint32_t val) in asn_put_timeticks() argument
897 return (asn_put_real_unsigned(b, in asn_put_timeticks()
931 asn_skip(struct asn_buf *b, asn_len_t len) in asn_skip() argument
933 if (b->asn_len < len) in asn_skip()
935 b->asn_cptr += len; in asn_skip()
936 b->asn_len -= len; in asn_skip()
944 asn_pad(struct asn_buf *b, asn_len_t len) in asn_pad() argument
946 if (b->asn_len < len) in asn_pad()
948 b->asn_ptr += len; in asn_pad()
949 b->asn_len -= len; in asn_pad()
1029 asn_error_func(const struct asn_buf *b, const char *err, ...) in asn_error_func() argument
1039 if (b != NULL) { in asn_error_func()
1041 for (i = 0; b->asn_len > i; i++) in asn_error_func()
1042 fprintf(stderr, " %02x", b->asn_cptr[i]); in asn_error_func()