• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 com.android.internal.net.ipsec.ike.ike3gpp;
17 
18 import android.net.ipsec.ike.exceptions.InvalidSyntaxException;
19 
20 import java.nio.ByteBuffer;
21 
22 /**
23  * Ike3gppBackoffTimerUtils contains functions needed to support 3GPP-specific Backoff Timer
24  * functionality.
25  *
26  * <p>This class is package-private.
27  */
28 class Ike3gppBackoffTimerUtils {
29     private static final int BACKOFF_TIMER_DATA_LEN = 2;
30     private static final byte BACKOFF_TIMER_LEN = (byte) 1;
31 
32     /**
33      * Get the backoff timer byte from the specified Notify Data.
34      *
35      * @see TS 124 302 Section 8.2.9.1 for specification of BACKOFF_TIMER Notify payload.
36      * @param notifyData The Notify-Data payload from which the backoff timer value will be parsed.
37      * @return the parsed backoff timer value
38      * @throws InvalidSyntaxException if the BACKOFF_TIMER's notifyData is encoded incorrectly
39      */
getBackoffTimerfromNotifyData(byte[] notifyData)40     static byte getBackoffTimerfromNotifyData(byte[] notifyData) throws InvalidSyntaxException {
41         ByteBuffer buffer = ByteBuffer.wrap(notifyData);
42 
43         if (buffer.remaining() != BACKOFF_TIMER_DATA_LEN || buffer.get() != BACKOFF_TIMER_LEN) {
44             throw new InvalidSyntaxException("BACKOFF_TIMER payload with an invalid encoding");
45         }
46 
47         return buffer.get();
48     }
49 }
50