2
0

p12_init.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright 1999-2018 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_local.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. if (!ASN1_INTEGER_set(pkcs12->version, 3))
  22. goto err;
  23. pkcs12->authsafes->type = OBJ_nid2obj(mode);
  24. switch (mode) {
  25. case NID_pkcs7_data:
  26. if ((pkcs12->authsafes->d.data = ASN1_OCTET_STRING_new()) == NULL) {
  27. PKCS12err(PKCS12_F_PKCS12_INIT, ERR_R_MALLOC_FAILURE);
  28. goto err;
  29. }
  30. break;
  31. default:
  32. PKCS12err(PKCS12_F_PKCS12_INIT, PKCS12_R_UNSUPPORTED_PKCS12_MODE);
  33. goto err;
  34. }
  35. return pkcs12;
  36. err:
  37. PKCS12_free(pkcs12);
  38. return NULL;
  39. }