View Javadoc
1   /**
2    * Copyright 2010-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.util.encrypt.openssl;
17  
18  import static com.google.common.collect.Lists.newArrayList;
19  import static org.kuali.common.util.base.Precondition.checkNotNull;
20  
21  import java.util.List;
22  
23  import com.google.common.collect.ImmutableList;
24  
25  public final class OpenSSLEncryptedContext {
26  
27  	private final ImmutableList<Byte> salt;
28  	private final ImmutableList<Byte> key;
29  	private final ImmutableList<Byte> initVector;
30  
31  	private OpenSSLEncryptedContext(Builder builder) {
32  		this.salt = ImmutableList.copyOf(builder.salt);
33  		this.key = ImmutableList.copyOf(builder.key);
34  		this.initVector = ImmutableList.copyOf(builder.initVector);
35  	}
36  
37  	public static Builder builder() {
38  		return new Builder();
39  	}
40  
41  	public static class Builder implements org.apache.commons.lang3.builder.Builder<OpenSSLEncryptedContext> {
42  
43  		private List<Byte> salt = newArrayList();
44  		private List<Byte> key = newArrayList();
45  		private List<Byte> initVector = newArrayList();
46  
47  		public Builder withSalt(List<Byte> salt) {
48  			this.salt = salt;
49  			return this;
50  		}
51  
52  		public Builder withKey(List<Byte> key) {
53  			this.key = key;
54  			return this;
55  		}
56  
57  		public Builder withInitVector(List<Byte> initVector) {
58  			this.initVector = initVector;
59  			return this;
60  		}
61  
62  		@Override
63  		public OpenSSLEncryptedContext build() {
64  			return validate(new OpenSSLEncryptedContext(this));
65  		}
66  
67  		private static OpenSSLEncryptedContext validate(OpenSSLEncryptedContext instance) {
68  			checkNotNull(instance.salt, "salt");
69  			checkNotNull(instance.key, "key");
70  			checkNotNull(instance.initVector, "initVector");
71  			return instance;
72  		}
73  
74  	}
75  
76  	public List<Byte> getSalt() {
77  		return salt;
78  	}
79  
80  	public List<Byte> getKey() {
81  		return key;
82  	}
83  
84  	public List<Byte> getInitVector() {
85  		return initVector;
86  	}
87  }