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 17 package com.android.internal.net.eap.message.simaka; 18 19 import android.annotation.NonNull; 20 21 import com.android.internal.annotations.VisibleForTesting; 22 import com.android.internal.net.eap.message.EapMessage; 23 import com.android.internal.net.eap.message.simaka.EapSimAkaAttribute.AtClientErrorCode; 24 25 import java.util.LinkedHashMap; 26 import java.util.List; 27 28 /** 29 * EapAkaPrimeTypeData represents the Type Data for an {@link EapMessage} during an EAP-AKA' 30 * session. 31 */ 32 public class EapAkaPrimeTypeData extends EapAkaTypeData { 33 private static final EapAkaPrimeTypeDataDecoder sTypeDataDecoder = 34 new EapAkaPrimeTypeDataDecoder(); 35 36 @VisibleForTesting EapAkaPrimeTypeData(int eapSubType, LinkedHashMap<Integer, EapSimAkaAttribute> attributeMap)37 EapAkaPrimeTypeData(int eapSubType, LinkedHashMap<Integer, EapSimAkaAttribute> attributeMap) { 38 super(eapSubType, attributeMap); 39 } 40 EapAkaPrimeTypeData( int eapSubType, LinkedHashMap<Integer, EapSimAkaAttribute> attributeMap, byte[] reservedBytes)41 private EapAkaPrimeTypeData( 42 int eapSubType, 43 LinkedHashMap<Integer, EapSimAkaAttribute> attributeMap, 44 byte[] reservedBytes) { 45 super(eapSubType, attributeMap, reservedBytes); 46 } 47 48 /** 49 * Creates and returns an EapAkaPrimeTypeData instance with the given subtype and attributes. 50 * 51 * @param eapSubtype the subtype for the EAP-AKA type data 52 * @param attributes the List of EapSimAkaAttributes to be included in this type data 53 */ EapAkaPrimeTypeData(int eapSubtype, List<EapSimAkaAttribute> attributes)54 public EapAkaPrimeTypeData(int eapSubtype, List<EapSimAkaAttribute> attributes) { 55 super(eapSubtype, attributes); 56 } 57 getEapAkaPrimeTypeDataDecoder()58 public static EapAkaPrimeTypeDataDecoder getEapAkaPrimeTypeDataDecoder() { 59 return sTypeDataDecoder; 60 } 61 62 /** 63 * EapAkaTypeDataDecoder will be used for decoding {@link EapAkaPrimeTypeData} objects. 64 */ 65 public static class EapAkaPrimeTypeDataDecoder 66 extends EapSimAkaTypeDataDecoder<EapAkaTypeData> { 67 private static final String TAG = EapAkaPrimeTypeDataDecoder.class.getSimpleName(); 68 private static final String EAP_METHOD = "EAP-AKA'"; 69 EapAkaPrimeTypeDataDecoder()70 protected EapAkaPrimeTypeDataDecoder() { 71 super( 72 TAG, 73 EAP_METHOD, 74 SUPPORTED_SUBTYPES, 75 EapAkaPrimeAttributeFactory.getInstance(), 76 EAP_AKA_SUBTYPE_STRING); 77 } 78 79 /** 80 * Decodes the given byte-array into a DecodeResult object. 81 * 82 * <p>Note that <b>only 1 KDF value</b> is allowed. If multiple AT_KDF attributes are 83 * supplied, a {@link DecodeResult} wrapping a {@link AtClientErrorCode#UNABLE_TO_PROCESS} 84 * will be returned. 85 * 86 * @param typeData the byte-encoding of the EapAkaPrimeTypeData to be parsed 87 * @return a DecodeResult object. If the decoding is successful, this will encapsulate an 88 * EapAkaPrimeTypeData instance representing the data stored in typeData. Otherwise, it 89 * will contain the relevant AtClientErrorCode for the decoding error. 90 */ decode(@onNull byte[] typeData)91 public DecodeResult<EapAkaTypeData> decode(@NonNull byte[] typeData) { 92 return super.decode(typeData); 93 } 94 95 @Override getInstance( int eapSubtype, LinkedHashMap<Integer, EapSimAkaAttribute> attributeMap, byte[] reservedBytes)96 protected EapAkaPrimeTypeData getInstance( 97 int eapSubtype, 98 LinkedHashMap<Integer, EapSimAkaAttribute> attributeMap, 99 byte[] reservedBytes) { 100 return new EapAkaPrimeTypeData(eapSubtype, attributeMap, reservedBytes); 101 } 102 } 103 } 104