Add PKCS7_bundle_certificates.

This function serialises a PKCS#7 structure containing a number of
certificates.

Change-Id: Iaf15887e1060d5d201d5a3dd3dca8d51105ee6d6
Reviewed-on: https://boringssl-review.googlesource.com/1431
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/include/openssl/bytestring.h b/include/openssl/bytestring.h
index 510ef7e..6c0e799 100644
--- a/include/openssl/bytestring.h
+++ b/include/openssl/bytestring.h
@@ -245,6 +245,12 @@
  * success and zero otherwise. */
 OPENSSL_EXPORT int CBB_add_bytes(CBB *cbb, const uint8_t *data, size_t len);
 
+/* CBB_add_space appends |len| bytes to |cbb| and sets |*out_data| to point to
+ * the beginning of that space. The caller must then write |len| bytes of
+ * actual contents to |*out_data|. It returns one on success and zero
+ * otherwise. */
+OPENSSL_EXPORT int CBB_add_space(CBB *cbb, uint8_t **out_data, size_t len);
+
 /* CBB_add_u8 appends an 8-bit number from |value| to |cbb|. It returns one on
  * success and zero otherwise. */
 OPENSSL_EXPORT int CBB_add_u8(CBB *cbb, uint8_t value);
diff --git a/include/openssl/obj.h b/include/openssl/obj.h
index f868fd3..81066bb 100644
--- a/include/openssl/obj.h
+++ b/include/openssl/obj.h
@@ -59,6 +59,7 @@
 
 #include <openssl/base.h>
 
+#include <openssl/bytestring.h>
 #include <openssl/obj_mac.h>
 
 #if defined(__cplusplus)
@@ -127,6 +128,10 @@
 /* OBJ_nid2sn returns the long name for |nid|, or NULL if |nid| is unknown. */
 OPENSSL_EXPORT const char *OBJ_nid2ln(int nid);
 
+/* OBJ_nid2cbs writes |nid| as an ASN.1 OBJECT IDENTIFIER to |out|. It returns
+ * one on success or zero otherwise. */
+OPENSSL_EXPORT int OBJ_nid2cbb(CBB *out, int nid);
+
 
 /* Dealing with textual representations of object identifiers. */
 
diff --git a/include/openssl/x509.h b/include/openssl/x509.h
index 058bbff..ac23f9c 100644
--- a/include/openssl/x509.h
+++ b/include/openssl/x509.h
@@ -1195,6 +1195,11 @@
  * and zero on error. */
 OPENSSL_EXPORT int PKCS7_get_certificates(STACK_OF(X509) *out_certs, CBS *cbs);
 
+/* PKCS7_bundle_certificates appends a PKCS#7, SignedData structure containing
+ * |certs| to |cbb|. It returns one on success and zero on error. */
+OPENSSL_EXPORT int PKCS7_bundle_certificates(
+    CBB *out, const STACK_OF(X509) *certs);
+
 
 /* EVP_PK values indicate the algorithm of the public key in a certificate. */