001/**
002 * Copyright 2010-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.common.util.encrypt.openssl;
017
018import static com.google.common.collect.Lists.newArrayList;
019import static org.kuali.common.util.base.Precondition.checkNotNull;
020
021import java.util.List;
022
023import com.google.common.collect.ImmutableList;
024
025public final class OpenSSLEncryptedContext {
026
027        private final ImmutableList<Byte> salt;
028        private final ImmutableList<Byte> key;
029        private final ImmutableList<Byte> initVector;
030
031        private OpenSSLEncryptedContext(Builder builder) {
032                this.salt = ImmutableList.copyOf(builder.salt);
033                this.key = ImmutableList.copyOf(builder.key);
034                this.initVector = ImmutableList.copyOf(builder.initVector);
035        }
036
037        public static Builder builder() {
038                return new Builder();
039        }
040
041        public static class Builder implements org.apache.commons.lang3.builder.Builder<OpenSSLEncryptedContext> {
042
043                private List<Byte> salt = newArrayList();
044                private List<Byte> key = newArrayList();
045                private List<Byte> initVector = newArrayList();
046
047                public Builder withSalt(List<Byte> salt) {
048                        this.salt = salt;
049                        return this;
050                }
051
052                public Builder withKey(List<Byte> key) {
053                        this.key = key;
054                        return this;
055                }
056
057                public Builder withInitVector(List<Byte> initVector) {
058                        this.initVector = initVector;
059                        return this;
060                }
061
062                @Override
063                public OpenSSLEncryptedContext build() {
064                        return validate(new OpenSSLEncryptedContext(this));
065                }
066
067                private static OpenSSLEncryptedContext validate(OpenSSLEncryptedContext instance) {
068                        checkNotNull(instance.salt, "salt");
069                        checkNotNull(instance.key, "key");
070                        checkNotNull(instance.initVector, "initVector");
071                        return instance;
072                }
073
074        }
075
076        public List<Byte> getSalt() {
077                return salt;
078        }
079
080        public List<Byte> getKey() {
081                return key;
082        }
083
084        public List<Byte> getInitVector() {
085                return initVector;
086        }
087}