p12_init.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (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
  8. */
  9. #include <stdio.h>
  10. #include "internal/cryptlib.h"
  11. #include <openssl/pkcs12.h>
  12. #include "p12_lcl.h"
  13. /* Initialise a PKCS12 structure to take data */
  14. PKCS12 *PKCS12_init(int mode)
  15. {
  16. PKCS12 *pkcs12;
  17. if ((pkcs12 = PKCS12_new()) == NULL) {
  18. PKCS12err(PKCS12_F_PKCS12_INIT, ERR_R_MALLOC_FAILURE);
  19. return NULL;
  20. }
  21. ASN1_INTEGER_set(pkcs12->version, 3);
  22. pkcs12->authsafes->type = OBJ_nid2obj(mode);
  23. switch (mode) {
  24. case NID_pkcs7_data:
  25. if ((pkcs12->authsafes->d.data = ASN1_OCTET_STRING_new()) == NULL) {
  26. PKCS12err(PKCS12_F_PKCS12_INIT, ERR_R_MALLOC_FAILURE);
  27. goto err;
  28. }
  29. break;
  30. default:
  31. PKCS12err(PKCS12_F_PKCS12_INIT, PKCS12_R_UNSUPPORTED_PKCS12_MODE);
  32. goto err;
  33. }
  34. return pkcs12;
  35. err:
  36. PKCS12_free(pkcs12);
  37. return NULL;
  38. }