make errro handling via exception
[YkNeoCR.git] / src / org / average / nfcauthcr / Check.java
index c3738f7fc4f80dbe2c799925d522beaa0ea62153..1fc5ceaf00f36d497b5cae113390f2361d4d7bf6 100644 (file)
@@ -14,6 +14,7 @@ import android.util.Log;
 import android.widget.Toast;
 
 import org.average.nfcauthcr.YkNeo;
+import org.average.nfcauthcr.CRException;
 
 public class Check extends Activity {
 
@@ -61,12 +62,16 @@ public class Check extends Activity {
                Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
                if (tag == null) return;
                IsoDep isoTag = IsoDep.get(tag);
-               byte[] response = YkNeo.doChallengeYubiKey(
+               try {
+                       byte[] response = YkNeo.doChallengeYubiKey(
                                                isoTag, slot, challenge);
-               if (response != null) {
                        Intent data = getIntent();
                        data.putExtra("response", response);
                        setResult(RESULT_OK, data);
+               } catch (CRException e) {
+                       Log.v(TAG, e.getMessage());
+                       Toast.makeText(this, e.getMessage(),
+                                       Toast.LENGTH_LONG).show();
                }
                finish();
        }