Example usage for org.bouncycastle.asn1 ASN1Boolean isTrue

List of usage examples for org.bouncycastle.asn1 ASN1Boolean isTrue

Introduction

In this page you can find the example usage for org.bouncycastle.asn1 ASN1Boolean isTrue.

Prototype

public boolean isTrue() 

Source Link

Usage

From source file:ca.trustpoint.m2m.M2mCertificateFactory.java

License:Apache License

/**
 * Parses ASN.1 sequence to set up X.509 extentions of a {@link M2mCertificate} object.
 *
 * @param seq An ASN.1 sequence containing X.509 extentions.
 * @param cert A {@link M2mCertificate} object to be filled.
 * @throw IOException if parsing error or data invalid.
 *///w w w.  j a va 2  s .c  o m
private void parseX509extensions(ASN1Sequence seq, M2mCertificate cert) throws IOException {
    if (seq.size() < 1) {
        throw new IOException("not X.509 extension data in sequence");
    }

    for (int i = 0; i < seq.size(); i++) {
        ASN1Sequence extSeq = (ASN1Sequence) seq.getObjectAt(i);

        if (extSeq.size() < 2) {
            throw new IOException("no enough data fields for X.509 extension in sequence");
        } else if (extSeq.size() > 3) {
            throw new IOException("too many data fields for X.509 extension in sequence");
        }

        String oid = null;
        boolean isCritical = false;
        byte[] value = null;

        for (int j = 0; j < extSeq.size(); j++) {
            ASN1TaggedObject obj = (ASN1TaggedObject) extSeq.getObjectAt(j);

            switch (obj.getTagNo()) {
            case 0: // oid
                ASN1ObjectIdentifier oidObj = ASN1ObjectIdentifier.getInstance(obj, false);
                oid = oidObj.getId();
                break;
            case 1: // isCritical
                ASN1Boolean isCriticalObj = ASN1Boolean.getInstance(obj, false);
                isCritical = isCriticalObj.isTrue();
                break;
            case 2: // value
                ASN1OctetString valueObj = ASN1OctetString.getInstance(obj, false);
                value = valueObj.getOctets();
                break;
            default:
                throw new IOException("unknown x509extension ID: " + obj.getTagNo());
            }
        }

        cert.addExtension(oid, isCritical, value);
    }
}

From source file:com.guardtime.asn1.TstInfo.java

License:Apache License

/**
 * Class constructor./*from  w  w  w .  java  2 s  .  c  o m*/
 *
 * @param obj ASN.1 representation of TST info.
 *
 * @throws Asn1FormatException if provided ASN.1 object has invalid format.
 */
TstInfo(ASN1Encodable obj) throws Asn1FormatException {
    try {
        tstInfo = TSTInfo.getInstance(obj);

        // Extract and check version
        BigInteger ver = tstInfo.getVersion().getValue();
        if (!ver.equals(BigInteger.valueOf(VERSION))) {
            throw new Asn1FormatException("invalid TST info version: " + ver);
        }
        version = ver.intValue();

        // Extract policy
        policy = tstInfo.getPolicy().getId();

        // Extract message imprint
        messageImprint = new MessageImprint(tstInfo.getMessageImprint().toASN1Primitive());

        // Extract serial number
        //
        // As `DERInteger` can be constructed out of `ASN1OctetString`
        // without any error, here we have no option to determine
        // if the serial number is actually an INTEGER or OCTET STRING.
        //
        // Possible solutions is to rewrite BouncyCastle `TSTInfo` class
        // adding more strict checks.
        serialNumber = tstInfo.getSerialNumber().getValue();

        // Extract request time
        //
        // Current BouncyCastle implementation can parse the time string
        // that does not omit trailing zeros in second fraction part.
        // RFC 3161 requires that such time string is labeled invalid.
        genTime = tstInfo.getGenTime().getDate();

        // Extract optional fields

        ASN1Encodable acc = tstInfo.getAccuracy();
        accuracy = ((acc == null) ? null : new Accuracy(acc.toASN1Primitive()));

        ASN1Boolean ord = tstInfo.getOrdering();
        ordering = (ord != null && ord.isTrue());

        ASN1Integer nnc = tstInfo.getNonce();
        nonce = ((nnc == null) ? null : nnc.getValue());

        GeneralName tsaName = tstInfo.getTsa();
        tsa = ((tsaName == null) ? null : tsaName.toString());

        Extensions exts = tstInfo.getExtensions();
        if (exts != null) {
            // check for critical extensions
            Asn1Util.checkExtensions(exts);
            extensions = exts.getEncoded(ASN1Encoding.DER);
        }
    } catch (Asn1FormatException e) {
        throw e;
    } catch (Exception e) {
        throw new Asn1FormatException("TST info has invalid format", e);
    }
}

From source file:de.carne.certmgr.store.provider.bouncycastle.BouncyCastleASN1Decoder.java

License:Open Source License

@Override
public boolean asn1DecodeBoolean() throws IOException {
    ASN1Boolean booleanObject = ensureType(ASN1Boolean.class);

    return booleanObject.isTrue();
}

From source file:net.sf.keystore_explorer.utilities.asn1.Asn1Dump.java

License:Open Source License

private String dumpBoolean(ASN1Boolean asn1Boolean) {
    StringBuilder sb = new StringBuilder();

    sb.append(indentSequence.toString(indentLevel));
    sb.append("BOOLEAN=");
    sb.append(asn1Boolean.isTrue());
    sb.append(NEWLINE);//w w  w  . j a va2  s.c  o  m

    return sb.toString();
}