2 * Copyright 1999-2023 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 #include "internal/cryptlib.h"
12 #include <openssl/pkcs12.h>
13 #include "crypto/pkcs7.h"
14 #include "p12_local.h"
16 /* Initialise a PKCS12 structure to take data */
18 PKCS12 *PKCS12_init_ex(int mode, OSSL_LIB_CTX *ctx, const char *propq)
22 if ((pkcs12 = PKCS12_new()) == NULL) {
23 ERR_raise(ERR_LIB_PKCS12, ERR_R_ASN1_LIB);
26 if (!ASN1_INTEGER_set(pkcs12->version, 3))
28 pkcs12->authsafes->type = OBJ_nid2obj(mode);
30 ossl_pkcs7_set0_libctx(pkcs12->authsafes, ctx);
31 if (!ossl_pkcs7_set1_propq(pkcs12->authsafes, propq)) {
32 ERR_raise(ERR_LIB_PKCS12, ERR_R_PKCS7_LIB);
38 if ((pkcs12->authsafes->d.data = ASN1_OCTET_STRING_new()) == NULL) {
39 ERR_raise(ERR_LIB_PKCS12, ERR_R_ASN1_LIB);
44 ERR_raise(ERR_LIB_PKCS12, PKCS12_R_UNSUPPORTED_PKCS12_MODE);
54 PKCS12 *PKCS12_init(int mode)
56 return PKCS12_init_ex(mode, NULL, NULL);
59 const PKCS7_CTX *ossl_pkcs12_get0_pkcs7ctx(const PKCS12 *p12)
61 if (p12 == NULL || p12->authsafes == NULL)
63 return &p12->authsafes->ctx;