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
|
//--- BEGIN COPYRIGHT BLOCK ---
//This program is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; version 2 of the License.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License along
//with this program; if not, write to the Free Software Foundation, Inc.,
//51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
//(C) 2014 Red Hat, Inc.
//All rights reserved.
//--- END COPYRIGHT BLOCK ---
package com.netscape.certsrv.key;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import com.netscape.certsrv.base.ResourceMessage;
/**
* Class to define the common attributes and methods used by
* SymKeyGenerationRequest and AsymKeyGenerationRequest
* @author akoneru
*
*/
public class KeyGenerationRequest extends ResourceMessage{
protected static final String CLIENT_KEY_ID = "clientKeyID";
protected static final String KEY_SIZE = "keySize";
protected static final String KEY_ALGORITHM = "keyAlgorithm";
protected static final String KEY_USAGE = "keyUsage";
protected static final String TRANS_WRAPPED_SESSION_KEY = "transWrappedSessionKey";
public List<String> getUsages() {
String usageString = attributes.get(KEY_USAGE);
if (!StringUtils.isBlank(usageString)) {
return new ArrayList<String>(Arrays.asList(usageString.split(",")));
}
return new ArrayList<String>();
}
public void setUsages(List<String> usages) {
attributes.put(KEY_USAGE, StringUtils.join(usages, ","));
}
public void addUsage(String usage) {
List<String> usages = getUsages();
for (String u : usages) {
if (u.equals(usage))
return;
}
usages.add(usage);
setUsages(usages);
}
/**
* @return the clientKeyId
*/
public String getClientKeyId() {
return attributes.get(CLIENT_KEY_ID);
}
/**
* @param clientKeyId the clientKeyId to set
*/
public void setClientKeyId(String clientKeyId) {
attributes.put(CLIENT_KEY_ID, clientKeyId);
}
/**
* @return the keySize
*/
public Integer getKeySize() {
try {
return new Integer(attributes.get(KEY_SIZE));
} catch (NumberFormatException e) {
return null;
}
}
/**
* @param keySize the key size to set
*/
public void setKeySize(Integer keySize) {
attributes.put(KEY_SIZE, keySize.toString());
}
/**
* @return the keyAlgorithm
*/
public String getKeyAlgorithm() {
return attributes.get(KEY_ALGORITHM);
}
/**
* @param keyAlgorithm the key algorithm to set
*/
public void setKeyAlgorithm(String keyAlgorithm) {
attributes.put(KEY_ALGORITHM, keyAlgorithm);
}
/**
* @return the transWrappedSessionKey
*/
public String getTransWrappedSessionKey() {
return attributes.get(TRANS_WRAPPED_SESSION_KEY);
}
/**
* @param transWrappedSessionKey the wrapped seesion key to set
*/
public void setTransWrappedSessionKey(String transWrappedSessionKey) {
attributes.put(TRANS_WRAPPED_SESSION_KEY, transWrappedSessionKey);
}
}
|