Home | History | Annotate | Download | only in eap
      1 /*
      2  * Copyright (C) 2016 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.server.wifi.hotspot2.anqp.eap;
     18 
     19 import com.android.internal.annotations.VisibleForTesting;
     20 
     21 import java.nio.BufferUnderflowException;
     22 import java.nio.ByteBuffer;
     23 import java.util.Arrays;
     24 
     25 /**
     26  * The Vendor Specific authentication parameter, IEEE802.11-2012, table 8-188.
     27  *
     28  * Format:
     29  * | Data |
     30  * variable
     31  */
     32 public class VendorSpecificAuth extends AuthParam {
     33     private final byte[] mData;
     34 
     35     @VisibleForTesting
     36     public VendorSpecificAuth(byte[] data) {
     37         super(AuthParam.PARAM_TYPE_VENDOR_SPECIFIC);
     38         mData = data;
     39     }
     40 
     41     /**
     42      * Parse a VendorSpecificAuth from the given buffer.
     43      *
     44      * @param payload The byte buffer to read from
     45      * @param length The length of the data
     46      * @return {@link VendorSpecificAuth}
     47      * @throws BufferUnderflowException
     48      */
     49     public static VendorSpecificAuth parse(ByteBuffer payload, int length) {
     50         byte[] data = new byte[length];
     51         payload.get(data);
     52         return new VendorSpecificAuth(data);
     53     }
     54 
     55     public byte[] getData() {
     56         return mData;
     57     }
     58 
     59     @Override
     60     public boolean equals(Object thatObject) {
     61         if (thatObject == this) {
     62             return true;
     63         }
     64         if (!(thatObject instanceof VendorSpecificAuth)) {
     65             return false;
     66         }
     67         VendorSpecificAuth that = (VendorSpecificAuth) thatObject;
     68         return Arrays.equals(mData, that.mData);
     69     }
     70 
     71     @Override
     72     public int hashCode() {
     73         return Arrays.hashCode(mData);
     74     }
     75 
     76     @Override
     77     public String toString() {
     78         return "VendorSpecificAuth{mData=" + Arrays.toString(mData) + "}";
     79     }
     80 }
     81