1 /*
2 * Copyright 2015-2020 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 package com.amazonaws.services.s3.model;
16
17 /**
18 * Server-side Encryption Algorithm.
19 */
20 public enum SSEAlgorithm {
21 AES256("AES256"),
22 KMS("aws:kms"),
23 ;
24
25 private final String algorithm;
26
27 public String getAlgorithm() {
28 return algorithm;
29 }
30
31 private SSEAlgorithm(String algorithm) {
32 this.algorithm = algorithm;
33 }
34
35 @Override
36 public String toString() {
37 return algorithm;
38 }
39
40 /**
41 * Returns the SSEAlgorithm enum corresponding to the given string;
42 * or null if and only if the given algorithm is null.
43 *
44 * @throws IllegalArgumentException if the specified algorithm is not
45 * supported.
46 */
47 public static SSEAlgorithm fromString(String algorithm) {
48 if (algorithm == null)
49 return null;
50 for (SSEAlgorithm e: values()) {
51 if (e.getAlgorithm().equals(algorithm))
52 return e;
53 }
54 throw new IllegalArgumentException("Unsupported algorithm " + algorithm);
55 }
56
57 /**
58 * Returns the default server side encryption algorithm, which is AES256.
59 */
60 public static SSEAlgorithm getDefault() {
61 return AES256;
62 }
63 }
64