Example usage for org.bouncycastle.asn1.x509 BasicConstraints getEncoded

List of usage examples for org.bouncycastle.asn1.x509 BasicConstraints getEncoded

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.x509 BasicConstraints getEncoded.

Prototype

public byte[] getEncoded(String encoding) throws IOException 

Source Link

Document

Return either the default for "BER" or a DER encoding if "DER" is specified.

Usage

From source file:net.sf.keystore_explorer.gui.dialogs.extensions.DBasicConstraints.java

License:Open Source License

private void okPressed() {
    boolean ca = jcbSubjectIsCa.isSelected();

    int pathLengthConstraint = -1;

    String pathLengthConstraintStr = jtfPathLengthConstraint.getText().trim();

    if (pathLengthConstraintStr.length() > 0) {
        try {/*w ww. ja  v  a  2s.  com*/
            pathLengthConstraint = Integer.parseInt(pathLengthConstraintStr);
        } catch (NumberFormatException ex) {
            JOptionPane.showMessageDialog(this, res.getString("DBasicConstraints.InvalidLengthValue.message"),
                    getTitle(), JOptionPane.WARNING_MESSAGE);
            return;
        }

        if (pathLengthConstraint < 0) {
            JOptionPane.showMessageDialog(this, res.getString("DBasicConstraints.InvalidLengthValue.message"),
                    getTitle(), JOptionPane.WARNING_MESSAGE);
            return;
        }
    }

    BasicConstraints basicConstraints;

    if (pathLengthConstraint != -1) {
        // pathLengthConstraint set automatically means ca=true
        basicConstraints = new BasicConstraints(pathLengthConstraint);
    } else {
        basicConstraints = new BasicConstraints(ca);
    }

    try {
        value = basicConstraints.getEncoded(ASN1Encoding.DER);
    } catch (IOException ex) {
        DError dError = new DError(this, ex);
        dError.setLocationRelativeTo(this);
        dError.setVisible(true);
        return;
    }

    closeDialog();
}