2015-01-22 11:40:55 +08:00
|
|
|
/*
|
2020-11-26 22:18:57 +08:00
|
|
|
* Copyright 1999-2020 The OpenSSL Project Authors. All Rights Reserved.
|
1999-03-29 07:17:34 +08:00
|
|
|
*
|
2018-12-06 20:49:51 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:52:22 +08:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
1999-03-29 07:17:34 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-05-14 22:56:48 +08:00
|
|
|
#include "internal/cryptlib.h"
|
1999-04-24 06:13:45 +08:00
|
|
|
#include <openssl/pkcs12.h>
|
2019-09-28 06:45:40 +08:00
|
|
|
#include "p12_local.h"
|
1999-03-29 07:17:34 +08:00
|
|
|
|
|
|
|
/* Initialise a PKCS12 structure to take data */
|
|
|
|
|
2005-05-11 11:45:39 +08:00
|
|
|
PKCS12 *PKCS12_init(int mode)
|
1999-03-29 07:17:34 +08:00
|
|
|
{
|
2015-01-22 11:40:55 +08:00
|
|
|
PKCS12 *pkcs12;
|
2015-05-07 01:43:59 +08:00
|
|
|
|
|
|
|
if ((pkcs12 = PKCS12_new()) == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_PKCS12, ERR_R_MALLOC_FAILURE);
|
2015-01-22 11:40:55 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2018-09-10 23:23:14 +08:00
|
|
|
if (!ASN1_INTEGER_set(pkcs12->version, 3))
|
|
|
|
goto err;
|
2015-01-22 11:40:55 +08:00
|
|
|
pkcs12->authsafes->type = OBJ_nid2obj(mode);
|
|
|
|
switch (mode) {
|
|
|
|
case NID_pkcs7_data:
|
2015-05-07 01:43:59 +08:00
|
|
|
if ((pkcs12->authsafes->d.data = ASN1_OCTET_STRING_new()) == NULL) {
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_PKCS12, ERR_R_MALLOC_FAILURE);
|
2015-01-22 11:40:55 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2020-11-04 19:23:19 +08:00
|
|
|
ERR_raise(ERR_LIB_PKCS12, PKCS12_R_UNSUPPORTED_PKCS12_MODE);
|
2015-01-22 11:40:55 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
return pkcs12;
|
2015-04-12 04:32:54 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
err:
|
2015-04-12 04:32:54 +08:00
|
|
|
PKCS12_free(pkcs12);
|
2015-01-22 11:40:55 +08:00
|
|
|
return NULL;
|
1999-03-29 07:17:34 +08:00
|
|
|
}
|