1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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 
17 package android.net.ipsec.ike;
18 
19 import android.annotation.NonNull;
20 
21 import java.util.Objects;
22 
23 /**
24  * IkeTunnelConnectionParams contains IKEv2 configurations to establish an IKE/IPsec tunnel.
25  *
26  * <p>This class containing IKEv2-specific configuration, authentication and authorization
27  * parameters to establish an IKE/IPsec tunnel.
28  */
29 public final class IkeTunnelConnectionParams {
30     private final IkeSessionParams mIkeParams;
31     private final TunnelModeChildSessionParams mChildParams;
32 
33     /**
34      * Construct an IkeTunnelConnectionParams instance.
35      *
36      * @param ikeParams the IKE Session configuration
37      * @param childParams the Tunnel mode Child Session configuration
38      */
IkeTunnelConnectionParams( @onNull IkeSessionParams ikeParams, @NonNull TunnelModeChildSessionParams childParams)39     public IkeTunnelConnectionParams(
40             @NonNull IkeSessionParams ikeParams,
41             @NonNull TunnelModeChildSessionParams childParams) {
42         Objects.requireNonNull(ikeParams, "ikeParams was null");
43         Objects.requireNonNull(childParams, "childParams was null");
44 
45         mIkeParams = ikeParams;
46         mChildParams = childParams;
47     }
48 
49     /** Returns the IKE Session configuration. */
50     @NonNull
getIkeSessionParams()51     public IkeSessionParams getIkeSessionParams() {
52         return mIkeParams;
53     }
54 
55     /** Returns the Tunnel mode Child Session configuration. */
56     @NonNull
getTunnelModeChildSessionParams()57     public TunnelModeChildSessionParams getTunnelModeChildSessionParams() {
58         return mChildParams;
59     }
60 
61     /** @hide */
62     @Override
hashCode()63     public int hashCode() {
64         return Objects.hash(mIkeParams, mChildParams);
65     }
66 
67     /** @hide */
68     @Override
equals(Object o)69     public boolean equals(Object o) {
70         if (!(o instanceof IkeTunnelConnectionParams)) {
71             return false;
72         }
73 
74         IkeTunnelConnectionParams other = (IkeTunnelConnectionParams) o;
75 
76         return Objects.equals(mIkeParams, other.mIkeParams)
77                 && Objects.equals(mChildParams, other.mChildParams);
78     }
79 }
80