Example usage for org.bouncycastle.cert CertException CertException

List of usage examples for org.bouncycastle.cert CertException CertException

Introduction

In this page you can find the example usage for org.bouncycastle.cert CertException CertException.

Prototype

public CertException(String msg, Throwable cause) 

Source Link

Usage

From source file:com.vvote.datafiles.wbb.CertificatesFile.java

License:Open Source License

/**
 * Constructor for a certificates file//from  ww w  .java 2s . c  om
 * 
 * @param json
 * @throws CertException
 */
private CertificatesFile(JSONObject json) throws CertException {
    // set the json entry
    this.json = json;

    // check that the JSON entry is not null
    if (this.getJson() != null) {

        try {
            if (this.getJson().has(CertsConstants.JKS_PATH)) {
                this.jksFile = this.getJson().getString(CertsConstants.JKS_PATH);
            } else {
                this.jksFile = null;
            }

            this.peerCerts = new ArrayList<PeerCert>();
            this.peerMapping = new HashMap<String, Integer>();

            JSONObject currentObject = null;

            CertEntry certEntry = null;

            for (String key : JSONObject.getNames(this.getJson())) {
                if (this.getJson().has(key)) {
                    if (!key.equals(CertsConstants.JKS_PATH)) {
                        currentObject = this.getJson().getJSONObject(key);

                        certEntry = CertFactory.constructCertEntry(key, currentObject);

                        if (certEntry.isPeer()) {
                            if (certEntry instanceof PeerCert) {
                                this.peerCerts.add((PeerCert) certEntry);

                                this.peerMapping.put(this.getPeerString(certEntry.getId()),
                                        ((PeerCert) certEntry).getPublicKeyEntry().getSequenceNumber());
                            }
                        } else {
                            if (certEntry instanceof WBBCert) {
                                this.wbbCert = (WBBCert) certEntry;
                            }
                        }
                    }
                }
            }

        } catch (JSONException e) {
            logger.error("Unable to create a CertificatesFile. Error: {}", e);
            throw new CertException("Unable to create a CertificatesFile.", e);
        }
    } else {
        logger.error("A CertificatesFile object must be a valid JSON entry");
        throw new CertException("A CertificatesFile object must be a valid JSON entry");
    }
}