-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathMaterialsDescription.java
More file actions
111 lines (93 loc) · 3.03 KB
/
Copy pathMaterialsDescription.java
File metadata and controls
111 lines (93 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package software.amazon.encryption.s3.materials;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* This class is used to provide key-value pairs that describe the key material used with the Keyring, specifically for AES and RSA Keyrings.
* This will be useful during the re-encryption of instruction file.
* The stored Materials Description is immutable once created.
*/
public class MaterialsDescription implements Map<String, String> {
private final Map<String, String> materialsDescription;
private MaterialsDescription(Builder builder) {
this.materialsDescription = Collections.unmodifiableMap(new HashMap<>(builder.materialsDescription));
}
public static Builder builder() {
return new Builder();
}
public Map<String, String> getMaterialsDescription() {
return this.materialsDescription;
}
@Override
public int size() {
return materialsDescription.size();
}
@Override
public boolean isEmpty() {
return materialsDescription.isEmpty();
}
@Override
public boolean containsKey(Object key) {
return materialsDescription.containsKey(key);
}
@Override
public boolean containsValue(Object value) {
return materialsDescription.containsValue(value);
}
@Override
public String get(Object key) {
return materialsDescription.get(key);
}
@Override
public String put(String key, String value) {
throw new UnsupportedOperationException("This map is immutable");
}
@Override
public String remove(Object key) {
return materialsDescription.remove(key);
}
@Override
public void putAll(Map<? extends String, ? extends String> m) {
throw new UnsupportedOperationException("This map is immutable");
}
@Override
public void clear() {
materialsDescription.clear();
}
@Override
public Set<String> keySet() {
return materialsDescription.keySet();
}
@Override
public Collection<String> values() {
return materialsDescription.values();
}
@Override
public Set<Entry<String, String>> entrySet() {
return materialsDescription.entrySet();
}
public static class Builder {
private final Map<String, String> materialsDescription = new HashMap<>();
public Builder put(String key, String value) {
if (key == null || value == null) {
throw new IllegalArgumentException("Key and value must not be null");
}
materialsDescription.put(key, value);
return this;
}
public Builder putAll(Map<String, String> description) {
if (description == null) {
throw new IllegalArgumentException("Description must not be null");
}
materialsDescription.putAll(description);
return this;
}
public MaterialsDescription build() {
return new MaterialsDescription(this);
}
}
}