| 1 | /* |
|---|---|
| 2 | * Copyright 2010-2017 Amazon.com, Inc. or its affiliates. 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 | * A copy of the License is located at |
| 7 | * |
| 8 | * http://aws.amazon.com/apache2.0 |
| 9 | * |
| 10 | * or in the "license" file accompanying this file. This file is distributed |
| 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | * express or implied. See the License for the specific language governing |
| 13 | * permissions and limitations under the License. |
| 14 | */ |
| 15 | #include <aws/core/utils/crypto/KeyWrapAlgorithm.h> |
| 16 | #include <aws/core/utils/HashingUtils.h> |
| 17 | #include <aws/core/utils/EnumParseOverflowContainer.h> |
| 18 | #include <aws/core/Globals.h> |
| 19 | |
| 20 | using namespace Aws::Utils; |
| 21 | |
| 22 | namespace Aws |
| 23 | { |
| 24 | namespace Utils |
| 25 | { |
| 26 | namespace Crypto |
| 27 | { |
| 28 | namespace KeyWrapAlgorithmMapper |
| 29 | { |
| 30 | static const int keyWrapAlgorithm_KMS_HASH = HashingUtils::HashString("kms"); |
| 31 | static const int keyWrapAlgorithm_KeyWrap_HASH = HashingUtils::HashString("AESWrap"); |
| 32 | |
| 33 | KeyWrapAlgorithm GetKeyWrapAlgorithmForName(const Aws::String& name) |
| 34 | { |
| 35 | int hashcode = HashingUtils::HashString(name.c_str()); |
| 36 | if (hashcode == keyWrapAlgorithm_KMS_HASH) |
| 37 | { |
| 38 | return KeyWrapAlgorithm::KMS; |
| 39 | } |
| 40 | else if (hashcode == keyWrapAlgorithm_KeyWrap_HASH) |
| 41 | { |
| 42 | return KeyWrapAlgorithm::AES_KEY_WRAP; |
| 43 | } |
| 44 | assert(0); |
| 45 | return KeyWrapAlgorithm::NONE; |
| 46 | } |
| 47 | |
| 48 | Aws::String GetNameForKeyWrapAlgorithm(KeyWrapAlgorithm enumValue) |
| 49 | { |
| 50 | switch (enumValue) |
| 51 | { |
| 52 | case KeyWrapAlgorithm::KMS: |
| 53 | return "kms"; |
| 54 | case KeyWrapAlgorithm::AES_KEY_WRAP: |
| 55 | return "AESWrap"; |
| 56 | default: |
| 57 | assert(0); |
| 58 | } |
| 59 | return ""; |
| 60 | } |
| 61 | }//namespace KeyWrapAlgorithmMapper |
| 62 | }//namespace Crypto |
| 63 | }//namespace Utils |
| 64 | }//namespace Aws |