/** * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0. */ #include #include #include namespace Aws { namespace S3Encryption { namespace Modules { static const char* const ALLOCATION_TAG = "CryptoModuleFactory"; CryptoModuleFactory::CryptoModuleFactory() { m_cryptoFactories.insert(std::pair < CryptoMode, std::shared_ptr>(CryptoModuleFactoryEO().HandlesMode(), Aws::MakeShared(ALLOCATION_TAG, CryptoModuleFactoryEO()))); m_cryptoFactories.insert(std::pair < CryptoMode, std::shared_ptr>(CryptoModuleFactoryAE().HandlesMode(), Aws::MakeShared(ALLOCATION_TAG, CryptoModuleFactoryAE()))); m_cryptoFactories.insert(std::pair < CryptoMode, std::shared_ptr>(CryptoModuleFactoryStrictAE().HandlesMode(), Aws::MakeShared(ALLOCATION_TAG, CryptoModuleFactoryStrictAE()))); } std::shared_ptr CryptoModuleFactory::FetchCryptoModule(const std::shared_ptr& encryptionMaterials, const CryptoConfiguration& cryptoConfig) const { auto entry = m_cryptoFactories.find(cryptoConfig.GetCryptoMode()); std::shared_ptr factory = entry->second; return factory->CreateModule(encryptionMaterials, cryptoConfig); } CryptoModuleFactoryEO::CryptoModuleFactoryEO() { } std::shared_ptr CryptoModuleFactoryEO::CreateModule(const std::shared_ptr& encryptionMaterials, const CryptoConfiguration& cryptoConfig) { return Aws::MakeShared(ALLOCATION_TAG, encryptionMaterials, cryptoConfig); } CryptoMode CryptoModuleFactoryEO::HandlesMode() const { return CryptoMode::ENCRYPTION_ONLY; } CryptoModuleFactoryAE::CryptoModuleFactoryAE() { } std::shared_ptr CryptoModuleFactoryAE::CreateModule(const std::shared_ptr& encryptionMaterials, const CryptoConfiguration& cryptoConfig) { return Aws::MakeShared(ALLOCATION_TAG, encryptionMaterials, cryptoConfig); } CryptoMode CryptoModuleFactoryAE::HandlesMode() const { return CryptoMode::AUTHENTICATED_ENCRYPTION; } CryptoModuleFactoryStrictAE::CryptoModuleFactoryStrictAE() { } std::shared_ptr CryptoModuleFactoryStrictAE::CreateModule(const std::shared_ptr& encryptionMaterials, const CryptoConfiguration& cryptoConfig) { return Aws::MakeShared(ALLOCATION_TAG, encryptionMaterials, cryptoConfig); } CryptoMode CryptoModuleFactoryStrictAE::HandlesMode() const { return CryptoMode::STRICT_AUTHENTICATED_ENCRYPTION; } } //namespace Modules } //namespace S3Encryption } //namespace Aws