Lines Matching +full:byte +full:- +full:len

1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* include/k5-der.h - Distinguished Encoding Rules (DER) declarations */
34 * Most ASN.1 encoding and decoding is done using the table-driven framework in
44 #include "k5-buf.h"
45 #include "k5-input.h"
47 /* Return the number of bytes needed to encode len as a DER encoding length. */
49 k5_der_len_len(size_t len) in k5_der_len_len() argument
53 if (len < 128) in k5_der_len_len()
56 while (len > 0) { in k5_der_len_len()
57 len >>= 8; in k5_der_len_len()
64 * byte and length) for a given contents length. */
71 /* Add a DER identifier byte (composed by the caller, including the ASN.1
74 k5_der_add_taglen(struct k5buf *buf, uint8_t idbyte, size_t len) in k5_der_add_taglen() argument
77 size_t llen = k5_der_len_len(len); in k5_der_add_taglen()
83 if (len < 128) { in k5_der_add_taglen()
84 *p = len; in k5_der_add_taglen()
86 *p = 0x80 | (llen - 1); in k5_der_add_taglen()
87 /* Encode the length bytes backwards so the most significant byte is in k5_der_add_taglen()
90 while (len > 0) { in k5_der_add_taglen()
91 *--p = len & 0xFF; in k5_der_add_taglen()
92 len >>= 8; in k5_der_add_taglen()
97 /* Add a DER value (identifier byte, length, and contents). */
100 size_t len) in k5_der_add_value() argument
102 k5_der_add_taglen(buf, idbyte, len); in k5_der_add_value()
103 k5_buf_add_len(buf, contents, len); in k5_der_add_value()
107 * If the next byte in in matches idbyte and the subsequent DER length is
119 size_t len; in k5_der_get_value() local
122 /* Do nothing if in is empty or the next byte doesn't match idbyte. */ in k5_der_get_value()
123 if (in->status || in->len == 0 || *in->ptr != idbyte) in k5_der_get_value()
126 /* Advance past the identifier byte and decode the length. */ in k5_der_get_value()
130 len = lenbyte; in k5_der_get_value()
132 len = 0; in k5_der_get_value()
134 if (len > (SIZE_MAX >> 8)) { in k5_der_get_value()
138 len = (len << 8) | k5_input_get_byte(in); in k5_der_get_value()
142 bytes = k5_input_get_bytes(in, len); in k5_der_get_value()
145 k5_input_init(contents_out, bytes, len); in k5_der_get_value()