Home | History | Annotate | Download | only in eap
      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 Credential implements AuthParam {
     12 
     13     public enum CredType {
     14         Reserved,
     15         SIM,
     16         USIM,
     17         NFC,
     18         HWToken,
     19         Softoken,
     20         Certificate,
     21         Username,
     22         None,
     23         Anonymous,
     24         VendorSpecific}
     25 
     26     private final EAP.AuthInfoID mAuthInfoID;
     27     private final CredType mCredType;
     28 
     29     public Credential(EAP.AuthInfoID infoID, int length, ByteBuffer payload)
     30             throws ProtocolException {
     31         if (length != 1) {
     32             throw new ProtocolException("Bad length: " + length);
     33         }
     34 
     35         mAuthInfoID = infoID;
     36         int typeID = payload.get() & BYTE_MASK;
     37 
     38         mCredType = typeID < CredType.values().length ?
     39                 CredType.values()[typeID] :
     40                 CredType.Reserved;
     41     }
     42 
     43     @Override
     44     public EAP.AuthInfoID getAuthInfoID() {
     45         return mAuthInfoID;
     46     }
     47 
     48     @Override
     49     public int hashCode() {
     50         return mAuthInfoID.hashCode() * 31 + mCredType.hashCode();
     51     }
     52 
     53     @Override
     54     public boolean equals(Object thatObject) {
     55         if (thatObject == this) {
     56             return true;
     57         } else if (thatObject == null || thatObject.getClass() != Credential.class) {
     58             return false;
     59         } else {
     60             return ((Credential) thatObject).getCredType() == getCredType();
     61         }
     62     }
     63 
     64     public CredType getCredType() {
     65         return mCredType;
     66     }
     67 
     68     @Override
     69     public String toString() {
     70         return "Auth method " + mAuthInfoID + " = " + mCredType + "\n";
     71     }
     72 }
     73