• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 package android.net.ipsec.ike.exceptions;
17 
18 import android.annotation.NonNull;
19 import android.net.ipsec.ike.ChildSessionCallback;
20 import android.net.ipsec.ike.IkeSessionCallback;
21 
22 import java.util.Objects;
23 
24 /**
25  * This exception represents an unrecognized error notification in a received response.
26  *
27  * @see <a href="https://tools.ietf.org/html/rfc7296#section-3.10.1">RFC 7296, Internet Key Exchange
28  *     Protocol Version 2 (IKEv2)</a>
29  * @hide
30  */
31 // When receiving an unrecognized error notification in a response, IKE Session MUST assume that
32 // the corresponding request has failed entirely. If it is in a request, IKE Session MUST ignore it.
33 public final class UnrecognizedIkeProtocolException extends IkeProtocolException {
34     private final byte[] mUnrecognizedErrorData;
35     /**
36      * Constructs an instance of UnrecognizedIkeProtocolException
37      *
38      * <p>Except for testing, IKE library users normally do not instantiate this object themselves
39      * but instead get a reference via {@link IkeSessionCallback} or {@link ChildSessionCallback}.
40      *
41      * @param errorType the error type
42      * @param errorData the error data in bytes
43      */
UnrecognizedIkeProtocolException(int errorType, @NonNull byte[] errorData)44     public UnrecognizedIkeProtocolException(int errorType, @NonNull byte[] errorData) {
45         super(errorType, errorData);
46         Objects.requireNonNull(errorData, "errorData is null");
47         mUnrecognizedErrorData = errorData.clone();
48     }
49 
50     /** Returns the included error data of this UnrecognizedIkeProtocolException */
51     @NonNull
getUnrecognizedErrorData()52     public byte[] getUnrecognizedErrorData() {
53         return mUnrecognizedErrorData;
54     }
55 
56     /** @hide */
57     @Override
isValidDataLength(int dataLen)58     protected boolean isValidDataLength(int dataLen) {
59         // Unrecognized error does not have an expected error data length. Any non-negative length
60         // is valid
61         return dataLen >= 0;
62     }
63 }
64