1 /* Copyright (c) 2014, Google Inc. 2 * 3 * Permission to use, copy, modify, and/or distribute this software for any 4 * purpose with or without fee is hereby granted, provided that the above 5 * copyright notice and this permission notice appear in all copies. 6 * 7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 15 #ifndef OPENSSL_HEADER_BYTESTRING_INTERNAL_H 16 #define OPENSSL_HEADER_BYTESTRING_INTERNAL_H 17 18 #include <openssl/base.h> 19 20 #if defined(__cplusplus) 21 extern "C" { 22 #endif 23 24 25 /* CBS_asn1_ber_to_der reads an ASN.1 structure from |in|. If it finds 26 * indefinite-length elements then it attempts to convert the BER data to DER 27 * and sets |*out| and |*out_length| to describe a malloced buffer containing 28 * the DER data. Additionally, |*in| will be advanced over the ASN.1 data. 29 * 30 * If it doesn't find any indefinite-length elements then it sets |*out| to 31 * NULL and |*in| is unmodified. 32 * 33 * A sufficiently complex ASN.1 structure will break this function because it's 34 * not possible to generically convert BER to DER without knowledge of the 35 * structure itself. However, this sufficies to handle the PKCS#7 and #12 output 36 * from NSS. 37 * 38 * It returns one on success and zero otherwise. */ 39 OPENSSL_EXPORT int CBS_asn1_ber_to_der(CBS *in, uint8_t **out, size_t *out_len); 40 41 /* CBS_get_any_ber_asn1_element acts the same as |CBS_get_any_asn1_element| but 42 * also allows indefinite-length elements to be returned. In that case, 43 * |*out_header_len| and |CBS_len(out)| will both be two as only the header is 44 * returned. */ 45 OPENSSL_EXPORT int CBS_get_any_ber_asn1_element(CBS *cbs, CBS *out, 46 unsigned *out_tag, 47 size_t *out_header_len); 48 49 50 #if defined(__cplusplus) 51 } /* extern C */ 52 #endif 53 54 #endif /* OPENSSL_HEADER_BYTESTRING_INTERNAL_H */ 55