2015-01-22 03:40:55 +00:00
|
|
|
/*
|
2018-09-11 12:22:14 +00:00
|
|
|
* Copyright 1999-2018 The OpenSSL Project Authors. All Rights Reserved.
|
1999-03-28 23:17:34 +00:00
|
|
|
*
|
2016-05-17 18:52:22 +00:00
|
|
|
* Licensed under the OpenSSL license (the "License"). You may not use
|
|
|
|
* 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-28 23:17:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2015-05-14 14:56:48 +00:00
|
|
|
#include "internal/cryptlib.h"
|
1999-04-23 22:13:45 +00:00
|
|
|
#include <openssl/pkcs12.h>
|
2019-09-27 21:58:06 +00:00
|
|
|
#include "p12_local.h"
|
1999-03-28 23:17:34 +00:00
|
|
|
|
|
|
|
/* Initialise a PKCS12 structure to take data */
|
|
|
|
|
2005-05-11 03:45:39 +00:00
|
|
|
PKCS12 *PKCS12_init(int mode)
|
1999-03-28 23:17:34 +00:00
|
|
|
{
|
2015-01-22 03:40:55 +00:00
|
|
|
PKCS12 *pkcs12;
|
2015-05-06 17:43:59 +00:00
|
|
|
|
|
|
|
if ((pkcs12 = PKCS12_new()) == NULL) {
|
2015-01-22 03:40:55 +00:00
|
|
|
PKCS12err(PKCS12_F_PKCS12_INIT, ERR_R_MALLOC_FAILURE);
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-09-10 15:23:14 +00:00
|
|
|
if (!ASN1_INTEGER_set(pkcs12->version, 3))
|
|
|
|
goto err;
|
2015-01-22 03:40:55 +00:00
|
|
|
pkcs12->authsafes->type = OBJ_nid2obj(mode);
|
|
|
|
switch (mode) {
|
|
|
|
case NID_pkcs7_data:
|
2015-05-06 17:43:59 +00:00
|
|
|
if ((pkcs12->authsafes->d.data = ASN1_OCTET_STRING_new()) == NULL) {
|
2015-01-22 03:40:55 +00:00
|
|
|
PKCS12err(PKCS12_F_PKCS12_INIT, ERR_R_MALLOC_FAILURE);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PKCS12err(PKCS12_F_PKCS12_INIT, PKCS12_R_UNSUPPORTED_PKCS12_MODE);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
return pkcs12;
|
2015-04-11 20:32:54 +00:00
|
|
|
|
2015-01-22 03:40:55 +00:00
|
|
|
err:
|
2015-04-11 20:32:54 +00:00
|
|
|
PKCS12_free(pkcs12);
|
2015-01-22 03:40:55 +00:00
|
|
|
return NULL;
|
1999-03-28 23:17:34 +00:00
|
|
|
}
|