1 package com.android.anqp.eap;
2 
3 import java.net.ProtocolException;
4 import java.nio.ByteBuffer;
5 
6 import static com.android.anqp.Constants.BYTE_MASK;
7 
8 /**
9  * An EAP authentication parameter, IEEE802.11-2012, table 8-188
10  */
11 public class InnerAuthEAP implements AuthParam {
12 
13     private final EAP.EAPMethodID mEapMethodID;
14 
InnerAuthEAP(int length, ByteBuffer payload)15     public InnerAuthEAP(int length, ByteBuffer payload) throws ProtocolException {
16         if (length != 1) {
17             throw new ProtocolException("Bad length: " + length);
18         }
19         int typeID = payload.get() & BYTE_MASK;
20         mEapMethodID = EAP.mapEAPMethod(typeID);
21     }
22 
InnerAuthEAP(EAP.EAPMethodID eapMethodID)23     public InnerAuthEAP(EAP.EAPMethodID eapMethodID) {
24         mEapMethodID = eapMethodID;
25     }
26 
27     @Override
getAuthInfoID()28     public EAP.AuthInfoID getAuthInfoID() {
29         return EAP.AuthInfoID.InnerAuthEAPMethodType;
30     }
31 
getEAPMethodID()32     public EAP.EAPMethodID getEAPMethodID() {
33         return mEapMethodID;
34     }
35 
36     @Override
hashCode()37     public int hashCode() {
38         return mEapMethodID != null ? mEapMethodID.hashCode() : 0;
39     }
40 
41     @Override
equals(Object thatObject)42     public boolean equals(Object thatObject) {
43         if (thatObject == this) {
44             return true;
45         } else if (thatObject == null || thatObject.getClass() != InnerAuthEAP.class) {
46             return false;
47         } else {
48             return ((InnerAuthEAP) thatObject).getEAPMethodID() == getEAPMethodID();
49         }
50     }
51 
52     @Override
toString()53     public String toString() {
54         return "Auth method InnerAuthEAP, inner = " + mEapMethodID + '\n';
55     }
56 }
57