cms_cd.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  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
  8. */
  9. #include "internal/cryptlib.h"
  10. #include <openssl/asn1t.h>
  11. #include <openssl/pem.h>
  12. #include <openssl/x509v3.h>
  13. #include <openssl/err.h>
  14. #include <openssl/cms.h>
  15. #include <openssl/bio.h>
  16. #include <openssl/comp.h>
  17. #include "cms_lcl.h"
  18. #ifdef ZLIB
  19. /* CMS CompressedData Utilities */
  20. CMS_ContentInfo *cms_CompressedData_create(int comp_nid)
  21. {
  22. CMS_ContentInfo *cms;
  23. CMS_CompressedData *cd;
  24. /*
  25. * Will need something cleverer if there is ever more than one
  26. * compression algorithm or parameters have some meaning...
  27. */
  28. if (comp_nid != NID_zlib_compression) {
  29. CMSerr(CMS_F_CMS_COMPRESSEDDATA_CREATE,
  30. CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM);
  31. return NULL;
  32. }
  33. cms = CMS_ContentInfo_new();
  34. if (cms == NULL)
  35. return NULL;
  36. cd = M_ASN1_new_of(CMS_CompressedData);
  37. if (cd == NULL)
  38. goto err;
  39. cms->contentType = OBJ_nid2obj(NID_id_smime_ct_compressedData);
  40. cms->d.compressedData = cd;
  41. cd->version = 0;
  42. X509_ALGOR_set0(cd->compressionAlgorithm,
  43. OBJ_nid2obj(NID_zlib_compression), V_ASN1_UNDEF, NULL);
  44. cd->encapContentInfo->eContentType = OBJ_nid2obj(NID_pkcs7_data);
  45. return cms;
  46. err:
  47. CMS_ContentInfo_free(cms);
  48. return NULL;
  49. }
  50. BIO *cms_CompressedData_init_bio(const CMS_ContentInfo *cms)
  51. {
  52. CMS_CompressedData *cd;
  53. const ASN1_OBJECT *compoid;
  54. if (OBJ_obj2nid(cms->contentType) != NID_id_smime_ct_compressedData) {
  55. CMSerr(CMS_F_CMS_COMPRESSEDDATA_INIT_BIO,
  56. CMS_R_CONTENT_TYPE_NOT_COMPRESSED_DATA);
  57. return NULL;
  58. }
  59. cd = cms->d.compressedData;
  60. X509_ALGOR_get0(&compoid, NULL, NULL, cd->compressionAlgorithm);
  61. if (OBJ_obj2nid(compoid) != NID_zlib_compression) {
  62. CMSerr(CMS_F_CMS_COMPRESSEDDATA_INIT_BIO,
  63. CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM);
  64. return NULL;
  65. }
  66. return BIO_new(BIO_f_zlib());
  67. }
  68. #endif