Example usage for org.bouncycastle.asn1 ASN1Boolean getInstance

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

Introduction

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

Prototype

public static ASN1Boolean getInstance(int value) 

Source Link

Document

Return an ASN1Boolean from the passed in value.

Usage

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

License:Open Source License

@Override
public void asn1EncodeBoolean(boolean b) {
    asn1Encode(ASN1Boolean.getInstance(b));
}

From source file:net.sf.keystore_explorer.crypto.x509.X509Ext.java

License:Open Source License

private String getLiabilityLimitationFlagStringValue(byte[] octets) {

    /*   LiabilityLimitationFlagSyntax ::= BOOLEAN */

    ASN1Boolean asn1Boolean = ASN1Boolean.getInstance(octets);
    return asn1Boolean.toString();
}

From source file:net.sf.keystore_explorer.crypto.x509.X509Ext.java

License:Open Source License

private String getDeclarationOfMajorityStringValue(byte[] octets) {

    // @formatter:off

    /*//from  w ww .ja v a 2 s .co  m
       DeclarationOfMajoritySyntax ::= CHOICE
       {
    notYoungerThan [0] IMPLICIT INTEGER,
    fullAgeAtCountry [1] IMPLICIT SEQUENCE {
       fullAge BOOLEAN DEFAULT TRUE,
       country PrintableString (SIZE(2))
    },
    dateOfBirth [2] IMPLICIT GeneralizedTime
       }
     */

    // @formatter:on

    StringBuilder sb = new StringBuilder();

    DeclarationOfMajority declarationOfMajority = DeclarationOfMajority.getInstance(octets);
    int notYoungerThan = declarationOfMajority.notYoungerThan();
    ASN1Sequence fullAgeAtCountry = declarationOfMajority.fullAgeAtCountry();
    ASN1GeneralizedTime dateOfBirth = declarationOfMajority.getDateOfBirth();

    if (notYoungerThan != -1) {
        sb.append(MessageFormat.format(res.getString("DeclarationOfMajority.notYoungerThan"), notYoungerThan));
        sb.append(NEWLINE);
    }

    if (fullAgeAtCountry != null) {
        ASN1Boolean fullAge = ASN1Boolean.getInstance(fullAgeAtCountry.getObjectAt(0));
        DERPrintableString country = DERPrintableString.getInstance(fullAgeAtCountry.getObjectAt(1));

        sb.append(MessageFormat.format(res.getString("DeclarationOfMajority.fullAgeAtCountry"),
                country.toString(), fullAge.toString()));
        sb.append(NEWLINE);
    }

    if (dateOfBirth != null) {
        sb.append(MessageFormat.format(res.getString("DeclarationOfMajority.dateOfBirth"), dateOfBirth));
        sb.append(NEWLINE);
    }

    return sb.toString();
}

From source file:org.cryptoworkshop.ximix.common.asn1.message.ChallengeLogMessage.java

License:Apache License

private ChallengeLogMessage(ASN1Sequence seq) {
    this.index = ASN1Integer.getInstance(seq.getObjectAt(0)).getValue().intValue();
    this.sequenceNo = ASN1Integer.getInstance(seq.getObjectAt(1)).getValue().intValue();
    this.hasPassed = ASN1Boolean.getInstance(seq.getObjectAt(2)).isTrue();
    this.keyInfo = SubjectPublicKeyInfo.getInstance(seq.getObjectAt(3));

    ECPublicKeyParameters ecKey;/*ww  w . ja v  a  2 s  .c  o m*/
    try {
        ecKey = (ECPublicKeyParameters) PublicKeyFactory.createKey(keyInfo);
    } catch (IOException e) {
        throw new IllegalArgumentException("Unable to create EC key from keyInfo in sequence.");
    }

    ECCurve curve = ecKey.getParameters().getCurve();

    this.sourceMessage = PointSequence.getInstance(curve, ASN1Sequence.getInstance(seq.getObjectAt(4)))
            .getECPoints();

    ASN1Sequence proofS = ASN1Sequence.getInstance(seq.getObjectAt(5));
    decryptionProofs = new ECDecryptionProof[proofS.size()];

    for (int i = 0; i != decryptionProofs.length; i++) {
        ASN1Sequence proof = ASN1Sequence.getInstance(proofS.getObjectAt(i));
        decryptionProofs[i] = new ECDecryptionProof(
                curve.decodePoint(ASN1OctetString.getInstance(proof.getObjectAt(0)).getOctets()),
                curve.decodePoint(ASN1OctetString.getInstance(proof.getObjectAt(1)).getOctets()),
                ASN1Integer.getInstance(proof.getObjectAt(2)).getValue());
    }
}

From source file:org.cryptoworkshop.ximix.common.asn1.message.ChallengeLogMessage.java

License:Apache License

@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(new ASN1Integer(index));
    v.add(new ASN1Integer(sequenceNo));
    v.add(ASN1Boolean.getInstance(hasPassed));
    v.add(keyInfo);//  w  w  w.  j a v  a 2  s.com
    v.add(new PointSequence(sourceMessage));

    ASN1EncodableVector dv = new ASN1EncodableVector();
    for (ECDecryptionProof proof : decryptionProofs) {
        ASN1EncodableVector proofV = new ASN1EncodableVector();

        proofV.add(new DEROctetString(proof.getA().getEncoded(true)));
        proofV.add(new DEROctetString(proof.getB().getEncoded(true)));
        proofV.add(new ASN1Integer(proof.getR()));

        dv.add(new DERSequence(proofV));
    }

    v.add(new DERSequence(dv));

    return new DERSequence(v);
}

From source file:org.cryptoworkshop.ximix.common.asn1.message.DecryptShuffledBoardMessage.java

License:Apache License

private DecryptShuffledBoardMessage(ASN1Sequence seq) {
    this.keyID = DERUTF8String.getInstance(seq.getObjectAt(0)).getString();
    this.boardName = DERUTF8String.getInstance(seq.getObjectAt(1)).getString();
    this.isWithPairing = ASN1Boolean.getInstance(seq.getObjectAt(2)).isTrue();
}

From source file:org.cryptoworkshop.ximix.common.asn1.message.DecryptShuffledBoardMessage.java

License:Apache License

@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(new DERUTF8String(keyID));
    v.add(new DERUTF8String(boardName));
    v.add(ASN1Boolean.getInstance(isWithPairing));

    return new DERSequence(v);
}

From source file:org.cryptoworkshop.ximix.common.asn1.message.TranscriptDownloadMessage.java

License:Apache License

private TranscriptDownloadMessage(ASN1Sequence seq) {
    this.queryID = ASN1Integer.getInstance(seq.getObjectAt(0)).getValue().longValue();
    this.operationNumber = ASN1Integer.getInstance(seq.getObjectAt(1)).getValue().longValue();
    this.stepNo = ASN1Integer.getInstance(seq.getObjectAt(2)).getValue().intValue();
    this.type = TranscriptType.values()[ASN1Integer.getInstance(seq.getObjectAt(3)).getValue().intValue()];
    this.maxNumberOfMessages = ASN1Integer.getInstance(seq.getObjectAt(4)).getValue().intValue();
    this.withPairing = ASN1Boolean.getInstance(seq.getObjectAt(5)).isTrue();

    if (seq.size() > 6) {
        this.seed = ASN1OctetString.getInstance(seq.getObjectAt(6)).getOctets();
    } else {/* w  ww  .ja  v a  2s .co m*/
        this.seed = null;
    }
}

From source file:org.cryptoworkshop.ximix.common.asn1.message.TranscriptDownloadMessage.java

License:Apache License

@Override
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(new ASN1Integer(queryID));
    v.add(new ASN1Integer(operationNumber));
    v.add(new ASN1Integer(stepNo));
    v.add(new ASN1Integer(type.ordinal()));
    v.add(new ASN1Integer(maxNumberOfMessages));
    v.add(ASN1Boolean.getInstance(withPairing));

    if (seed != null) {
        v.add(new DEROctetString(seed));
    }/*from ww  w  .  j ava 2 s .  c  o  m*/

    return new DERSequence(v);
}

From source file:org.jruby.ext.openssl.X509ExtensionFactory.java

License:LGPL

private static DLSequence parseBasicConstrains(final String valuex) {
    final String[] val = valuex.split(",");
    final ASN1EncodableVector vec = new ASN1EncodableVector();
    for (int i = 0; i < val.length; i++) {
        final String value = val[i] = val[i].trim();
        if (value.length() > 3 && value.substring(0, 3).equalsIgnoreCase("CA:")) {
            boolean isTrue = "true".equalsIgnoreCase(value.substring(3).trim());
            vec.add(ASN1Boolean.getInstance(isTrue));
        }//from   w w w .ja va  2s . c  o  m
    }
    for (int i = 0; i < val.length; i++) {
        final String value = val[i];
        if (value.length() > 8 && value.substring(0, 8).equalsIgnoreCase("pathlen:")) {
            int pathlen = Integer.parseInt(value.substring(8).trim());
            vec.add(new ASN1Integer(BigInteger.valueOf(pathlen)));
        }
    }
    return new DLSequence(vec);
}