-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathContentMetadata.java
More file actions
141 lines (108 loc) · 4.14 KB
/
Copy pathContentMetadata.java
File metadata and controls
141 lines (108 loc) · 4.14 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package software.amazon.encryption.s3.internal;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import software.amazon.encryption.s3.algorithms.AlgorithmSuite;
import software.amazon.encryption.s3.materials.EncryptedDataKey;
import java.util.Collections;
import java.util.Map;
public class ContentMetadata {
private final AlgorithmSuite _algorithmSuite;
private final EncryptedDataKey _encryptedDataKey;
private final String _encryptedDataKeyAlgorithm;
/**
* This field stores either encryption context or material description.
* We use a single field to store both in order to maintain backwards
* compatibility with V2, which treated both as the same.
*/
private final Map<String, String> _encryptionContextOrMatDesc;
private final byte[] _contentIv;
private final String _contentCipher;
private final String _contentCipherTagLength;
private final String _contentRange;
private ContentMetadata(Builder builder) {
_algorithmSuite = builder._algorithmSuite;
_encryptedDataKey = builder._encryptedDataKey;
_encryptedDataKeyAlgorithm = builder._encryptedDataKeyAlgorithm;
_encryptionContextOrMatDesc = builder._encryptionContextOrMatDesc;
_contentIv = builder._contentIv;
_contentCipher = builder._contentCipher;
_contentCipherTagLength = builder._contentCipherTagLength;
_contentRange = builder._contentRange;
}
public static Builder builder() {
return new Builder();
}
public AlgorithmSuite algorithmSuite() {
return _algorithmSuite;
}
public EncryptedDataKey encryptedDataKey() {
return _encryptedDataKey;
}
public String encryptedDataKeyAlgorithm() {
return _encryptedDataKeyAlgorithm;
}
/**
* Note that the underlying implementation uses a Collections.unmodifiableMap which is
* immutable.
*/
@SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "False positive; underlying"
+ " implementation is immutable")
public Map<String, String> encryptedDataKeyContext() {
return _encryptionContextOrMatDesc;
}
public byte[] contentIv() {
if (_contentIv == null) {
return null;
}
return _contentIv.clone();
}
public String contentCipher() {
return _contentCipher;
}
public String contentCipherTagLength() {
return _contentCipherTagLength;
}
public String contentRange() {
return _contentRange;
}
public static class Builder {
private AlgorithmSuite _algorithmSuite;
private EncryptedDataKey _encryptedDataKey;
private String _encryptedDataKeyAlgorithm;
private Map<String, String> _encryptionContextOrMatDesc;
private byte[] _contentIv;
private String _contentCipher;
private String _contentCipherTagLength;
public String _contentRange;
private Builder() {
}
public Builder algorithmSuite(AlgorithmSuite algorithmSuite) {
_algorithmSuite = algorithmSuite;
return this;
}
public Builder encryptedDataKey(EncryptedDataKey encryptedDataKey) {
_encryptedDataKey = encryptedDataKey;
return this;
}
public Builder encryptedDataKeyAlgorithm(String encryptedDataKeyAlgorithm) {
_encryptedDataKeyAlgorithm = encryptedDataKeyAlgorithm;
return this;
}
public Builder encryptionContextOrMatDesc(Map<String, String> encryptionContextOrMatDesc) {
_encryptionContextOrMatDesc = Collections.unmodifiableMap(encryptionContextOrMatDesc);
return this;
}
public Builder contentIv(byte[] contentIv) {
_contentIv = contentIv.clone();
return this;
}
public Builder contentRange(String contentRange) {
_contentRange = contentRange;
return this;
}
public ContentMetadata build() {
return new ContentMetadata(this);
}
}
}