OssEncryptionClient.h 5.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright 2009-2017 Alibaba Cloud All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #pragma once
  17. #include <alibabacloud/oss/OssClient.h>
  18. #include <alibabacloud/oss/encryption/EncryptionMaterials.h>
  19. #include <alibabacloud/oss/encryption/CryptoConfiguration.h>
  20. #include <alibabacloud/oss/model/MultipartUploadCryptoContext.h>
  21. namespace AlibabaCloud
  22. {
  23. namespace OSS
  24. {
  25. class EncryptionResumableDownloader;
  26. class EncryptionResumableUploader;
  27. class ALIBABACLOUD_OSS_EXPORT OssEncryptionClient : public OssClient
  28. {
  29. public:
  30. OssEncryptionClient(const std::string& endpoint, const std::string& accessKeyId, const std::string& accessKeySecret,
  31. const ClientConfiguration& configuration,
  32. const std::shared_ptr<EncryptionMaterials>& encryptionMaterials, const CryptoConfiguration& cryptoConfig);
  33. OssEncryptionClient(const std::string& endpoint, const std::string& accessKeyId, const std::string& accessKeySecret, const std::string& securityToken,
  34. const ClientConfiguration& configuration,
  35. const std::shared_ptr<EncryptionMaterials>& encryptionMaterials, const CryptoConfiguration& cryptoConfig);
  36. OssEncryptionClient(const std::string& endpoint,
  37. const std::shared_ptr<CredentialsProvider>& credentialsProvider, const ClientConfiguration& configuration,
  38. const std::shared_ptr<EncryptionMaterials>& encryptionMaterials, const CryptoConfiguration& cryptoConfig);
  39. virtual ~OssEncryptionClient();
  40. /*Object*/
  41. GetObjectOutcome GetObject(const GetObjectRequest& request) const;
  42. GetObjectOutcome GetObject(const std::string &bucket, const std::string &key, const std::shared_ptr<std::iostream> &content) const;
  43. GetObjectOutcome GetObject(const std::string &bucket, const std::string &key, const std::string &fileToSave) const;
  44. PutObjectOutcome PutObject(const PutObjectRequest& request) const;
  45. PutObjectOutcome PutObject(const std::string &bucket, const std::string &key, const std::shared_ptr<std::iostream> &content) const;
  46. PutObjectOutcome PutObject(const std::string &bucket, const std::string &key, const std::string &fileToUpload) const;
  47. /*MultipartUpload*/
  48. InitiateMultipartUploadOutcome InitiateMultipartUpload(const InitiateMultipartUploadRequest& request, MultipartUploadCryptoContext& ctx) const;
  49. PutObjectOutcome UploadPart(const UploadPartRequest& request, const MultipartUploadCryptoContext& ctx) const;
  50. CompleteMultipartUploadOutcome CompleteMultipartUpload(const CompleteMultipartUploadRequest& request, const MultipartUploadCryptoContext& ctx) const;
  51. #if !defined(OSS_DISABLE_RESUAMABLE)
  52. /*Resumable Operation*/
  53. PutObjectOutcome ResumableUploadObject(const UploadObjectRequest& request) const;
  54. GetObjectOutcome ResumableDownloadObject(const DownloadObjectRequest& request) const;
  55. #endif
  56. /*Aysnc APIs*/
  57. void GetObjectAsync(const GetObjectRequest& request, const GetObjectAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
  58. void PutObjectAsync(const PutObjectRequest& request, const PutObjectAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
  59. void UploadPartAsync(const UploadPartRequest& request, const UploadPartAsyncHandler& handler, const MultipartUploadCryptoContext& cryptoCtx, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
  60. /*Callable APIs*/
  61. GetObjectOutcomeCallable GetObjectCallable(const GetObjectRequest& request) const;
  62. PutObjectOutcomeCallable PutObjectCallable(const PutObjectRequest& request) const;
  63. PutObjectOutcomeCallable UploadPartCallable(const UploadPartRequest& request, const MultipartUploadCryptoContext& cryptoCtx) const;
  64. protected:
  65. AppendObjectOutcome AppendObject(const AppendObjectRequest& request) const;
  66. UploadPartCopyOutcome UploadPartCopy(const UploadPartCopyRequest& request, const MultipartUploadCryptoContext& ctx) const;
  67. void UploadPartCopyAsync(const UploadPartCopyRequest& request, const UploadPartCopyAsyncHandler& handler, const MultipartUploadCryptoContext& cryptoCtx, const std::shared_ptr<const AsyncCallerContext>& context = nullptr) const;
  68. UploadPartCopyOutcomeCallable UploadPartCopyCallable(const UploadPartCopyRequest& request, const MultipartUploadCryptoContext& cryptoCtx) const;
  69. CopyObjectOutcome ResumableCopyObject(const MultiCopyObjectRequest& request) const;
  70. GetObjectOutcome GetObjectByUrl(const GetObjectByUrlRequest& request) const;
  71. PutObjectOutcome PutObjectByUrl(const PutObjectByUrlRequest& request) const;
  72. private:
  73. friend class EncryptionResumableDownloader;
  74. friend class EncryptionResumableUploader;
  75. GetObjectOutcome GetObjectInternal(const GetObjectRequest& request, const ObjectMetaData& meta) const;
  76. private:
  77. std::shared_ptr<EncryptionMaterials> encryptionMaterials_;
  78. CryptoConfiguration cryptoConfig_;
  79. };
  80. }
  81. }