Lines Matching +full:encode +full:- +full:only
1 // SPDX-License-Identifier: GPL-2.0-only
14 * asn1_encode_integer() - encode positive integer to ASN.1
19 * This is a simplified encoder: it only currently does
27 int data_len = end_data - data; in asn1_encode_integer()
33 "BUG: integer encode only supports positive integers")) in asn1_encode_integer()
34 return ERR_PTR(-EINVAL); in asn1_encode_integer()
41 return ERR_PTR(-EINVAL); in asn1_encode_integer()
44 data_len -= 2; in asn1_encode_integer()
52 for (i = sizeof(integer); i > 0 ; i--) { in asn1_encode_integer()
53 int byte = integer >> (8 * (i - 1)); in asn1_encode_integer()
70 data_len--; in asn1_encode_integer()
75 return ERR_PTR(-EINVAL); in asn1_encode_integer()
78 data_len--; in asn1_encode_integer()
82 data[1] = d - data - 2; in asn1_encode_integer()
96 return -EINVAL; in asn1_encode_oid_digit()
101 (*data_len)--; in asn1_encode_oid_digit()
106 start -= 7; in asn1_encode_oid_digit()
112 oid = oid - (byte << start); in asn1_encode_oid_digit()
113 start -= 7; in asn1_encode_oid_digit()
116 (*data_len)--; in asn1_encode_oid_digit()
121 (*data_len)--; in asn1_encode_oid_digit()
123 ret = -EINVAL; in asn1_encode_oid_digit()
132 * asn1_encode_oid() - encode an oid to ASN.1
144 int data_len = end_data - data; in asn1_encode_oid()
149 return ERR_PTR(-EINVAL); in asn1_encode_oid()
152 return ERR_PTR(-EINVAL); in asn1_encode_oid()
160 return ERR_PTR(-EINVAL); in asn1_encode_oid()
165 data_len -= 3; in asn1_encode_oid()
173 data[1] = d - data - 2; in asn1_encode_oid()
180 * asn1_encode_length() - encode a length to follow an ASN.1 tag
181 * @data: pointer to encode at
183 * @len: length to encode
185 * This routine can encode lengths up to 65535 using the ASN.1 rules.
189 * sequence will be re-encoded when the length is known.
194 return -EINVAL; in asn1_encode_length()
198 (*data_len)--; in asn1_encode_length()
204 (*data_len)--; in asn1_encode_length()
209 return -EINVAL; in asn1_encode_length()
214 *data_len -= 2; in asn1_encode_length()
219 return -EINVAL; in asn1_encode_length()
225 *data_len -= 3; in asn1_encode_length()
230 return -EINVAL; in asn1_encode_length()
233 return -EINVAL; in asn1_encode_length()
238 *data_len -= 4; in asn1_encode_length()
244 * asn1_encode_tag() - add a tag for optional or explicit value
251 * Note this currently only handles short form tags < 31.
259 * To encode in place pass a NULL @string and -1 for @len and the
266 * expects to be called with @data pointing to where the first encode
273 int data_len = end_data - data; in asn1_encode_tag()
277 return ERR_PTR(-EINVAL); in asn1_encode_tag()
281 return ERR_PTR(-EINVAL); in asn1_encode_tag()
292 data -= 2; in asn1_encode_tag()
297 return ERR_PTR(-EINVAL); in asn1_encode_tag()
300 data_len--; in asn1_encode_tag()
309 return ERR_PTR(-EINVAL); in asn1_encode_tag()
319 * asn1_encode_octet_string() - encode an ASN.1 OCTET STRING
320 * @data: pointer to encode at
332 int data_len = end_data - data; in asn1_encode_octet_string()
340 return ERR_PTR(-EINVAL); in asn1_encode_octet_string()
343 data_len--; in asn1_encode_octet_string()
350 return ERR_PTR(-EINVAL); in asn1_encode_octet_string()
360 * asn1_encode_sequence() - wrap a byte stream in an ASN.1 SEQUENCE
361 * @data: pointer to encode at
366 * Fill in a sequence. To encode in place, pass NULL for @seq and -1
370 * where the first encode placed it.
376 int data_len = end_data - data; in asn1_encode_sequence()
381 return ERR_PTR(-EINVAL); in asn1_encode_sequence()
392 data -= 2; in asn1_encode_sequence()
397 return ERR_PTR(-EINVAL); in asn1_encode_sequence()
400 data_len--; in asn1_encode_sequence()
410 return ERR_PTR(-EINVAL); in asn1_encode_sequence()
420 * asn1_encode_boolean() - encode a boolean value to ASN.1
421 * @data: pointer to encode at
429 int data_len = end_data - data; in asn1_encode_boolean()
436 return ERR_PTR(-EINVAL); in asn1_encode_boolean()
439 data_len--; in asn1_encode_boolean()