Android Open Source - android-pkpass-viewer Manifest Service






From Project

Back to project page android-pkpass-viewer.

License

The source code is released under:

MIT License

If you think the Android project android-pkpass-viewer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.manso.mytickets.services;
//from   w  w w.j ava  2s  .co  m
import java.io.File;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import com.manso.mytickets.utils.FileReader;
import com.manso.mytickets.utils.Sha1;

public class ManifestService {
  
  public boolean check(File dir) {      
    String json;
    Sha1 sha1 = new Sha1();
    try {
      json = new FileReader().readTextFile(new File(dir, "manifest.json"));
    } catch (IOException e) {
      e.printStackTrace();
      return false;
    }
    
    JSONParser jsonParser = new JSONParser();
    
    JSONObject root;
    try {
      Object rootAux = jsonParser.parse(json);
      root = (JSONObject) rootAux;
    
      for (Object keyAux : root.keySet()) {
        String key = (String)keyAux;
        File file = new File(dir, key);
        String hash = sha1.fromFile(file);
        String hashFromManifest = (String) root.get(key);
        if (!hash.equals(hashFromManifest))
        {
          return false;
        }
      }
    } catch (ParseException e) {
      e.printStackTrace();
      return false;
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
      return false;
    } catch (IOException e) {
      e.printStackTrace();
      return false;
    }
    
    return true;
  }
}




Java Source Code List

com.manso.mytickets.HandleIntentAsyncTask.java
com.manso.mytickets.TicketBackFragment.java
com.manso.mytickets.TicketFrontFragment.java
com.manso.mytickets.ViewTicketFrontActivity.java
com.manso.mytickets.services.EventTicketPassStrategy.java
com.manso.mytickets.services.IPassStrategy.java
com.manso.mytickets.services.ManifestService.java
com.manso.mytickets.services.PassReadingService.java
com.manso.mytickets.services.PassStorageService.java
com.manso.mytickets.services.PassStrategyService.java
com.manso.mytickets.services.PassTypes.java
com.manso.mytickets.utils.BarcodeEncoder.java
com.manso.mytickets.utils.FileReader.java
com.manso.mytickets.utils.ImageUtils.java
com.manso.mytickets.utils.RandomNameGenerator.java
com.manso.mytickets.utils.Sha1.java