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/ContentCryptoScheme.h>
16#include <aws/core/utils/HashingUtils.h>
17#include <aws/core/utils/EnumParseOverflowContainer.h>
18#include <aws/core/Globals.h>
19
20using namespace Aws::Utils;
21
22namespace Aws
23{
24 namespace Utils
25 {
26 namespace Crypto
27 {
28 namespace ContentCryptoSchemeMapper
29 {
30 static const int cryptoScheme_CBC_HASH = HashingUtils::HashString("AES/CBC/PKCS5Padding");
31 static const int cryptoScheme_CTR_HASH = HashingUtils::HashString("AES/CTR/NoPadding");
32 static const int cryptoScheme_GCM_HASH = HashingUtils::HashString("AES/GCM/NoPadding");
33
34 ContentCryptoScheme GetContentCryptoSchemeForName(const Aws::String& name)
35 {
36 int hashcode = HashingUtils::HashString(name.c_str());
37 if (hashcode == cryptoScheme_CBC_HASH)
38 {
39 return ContentCryptoScheme::CBC;
40 }
41 else if (hashcode == cryptoScheme_CTR_HASH)
42 {
43 return ContentCryptoScheme::CTR;
44 }
45 else if (hashcode == cryptoScheme_GCM_HASH)
46 {
47 return ContentCryptoScheme::GCM;
48 }
49 assert(0);
50 return ContentCryptoScheme::NONE;
51 }
52
53 Aws::String GetNameForContentCryptoScheme(ContentCryptoScheme enumValue)
54 {
55 switch (enumValue)
56 {
57 case ContentCryptoScheme::CBC:
58 return "AES/CBC/PKCS5Padding";
59 case ContentCryptoScheme::CTR:
60 return "AES/CTR/NoPadding";
61 case ContentCryptoScheme::GCM:
62 return "AES/GCM/NoPadding";
63 default:
64 assert(0);
65 return "";
66 }
67 }
68 }//namespace ContentCryptoSchemeMapper
69 } //namespace Crypto
70 }//namespace Utils
71}//namespace Aws