Java 类org.bouncycastle.asn1.DERBoolean 实例源码

项目:ipack    文件:X509Extensions.java   
/**
 * Constructor from ASN1Sequence.
 *
 * the extensions are a list of constructed sequences, either with (OID, OctetString) or (OID, Boolean, OctetString)
 */
public X509Extensions(
    ASN1Sequence  seq)
{
    Enumeration e = seq.getObjects();

    while (e.hasMoreElements())
    {
        ASN1Sequence            s = ASN1Sequence.getInstance(e.nextElement());

        if (s.size() == 3)
        {
            extensions.put(s.getObjectAt(0), new X509Extension(DERBoolean.getInstance(s.getObjectAt(1)), ASN1OctetString.getInstance(s.getObjectAt(2))));
        }
        else if (s.size() == 2)
        {
            extensions.put(s.getObjectAt(0), new X509Extension(false, ASN1OctetString.getInstance(s.getObjectAt(1))));
        }
        else
        {
            throw new IllegalArgumentException("Bad sequence size: " + s.size());
        }

        ordering.addElement(s.getObjectAt(0));
    }
}
项目:ipack    文件:X509Extensions.java   
/**
 * <pre>
 *     Extensions        ::=   SEQUENCE SIZE (1..MAX) OF Extension
 *
 *     Extension         ::=   SEQUENCE {
 *        extnId            EXTENSION.&amp;id ({ExtensionSet}),
 *        critical          BOOLEAN DEFAULT FALSE,
 *        extnValue         OCTET STRING }
 * </pre>
 */
public ASN1Primitive toASN1Primitive()
{
    ASN1EncodableVector     vec = new ASN1EncodableVector();
    Enumeration             e = ordering.elements();

    while (e.hasMoreElements())
    {
        ASN1ObjectIdentifier    oid = (ASN1ObjectIdentifier)e.nextElement();
        X509Extension           ext = (X509Extension)extensions.get(oid);
        ASN1EncodableVector     v = new ASN1EncodableVector();

        v.add(oid);

        if (ext.isCritical())
        {
            v.add(DERBoolean.TRUE);
        }

        v.add(ext.getValue());

        vec.add(new DERSequence(v));
    }

    return new DERSequence(vec);
}
项目:AcademicTorrents-Downloader    文件:X509Extensions.java   
/**
 * Constructor from ASN1Sequence.
 *
 * the extensions are a list of constructed sequences, either with (OID, OctetString) or (OID, Boolean, OctetString)
 */
public X509Extensions(
    ASN1Sequence  seq)
{
    Enumeration e = seq.getObjects();

    while (e.hasMoreElements())
    {
        ASN1Sequence            s = ASN1Sequence.getInstance(e.nextElement());

        if (s.size() == 3)
        {
            extensions.put(s.getObjectAt(0), new X509Extension(DERBoolean.getInstance(s.getObjectAt(1)), ASN1OctetString.getInstance(s.getObjectAt(2))));
        }
        else if (s.size() == 2)
        {
            extensions.put(s.getObjectAt(0), new X509Extension(false, ASN1OctetString.getInstance(s.getObjectAt(1))));
        }
        else
        {
            throw new IllegalArgumentException("Bad sequence size: " + s.size());
        }

        ordering.addElement(s.getObjectAt(0));
    }
}
项目:AcademicTorrents-Downloader    文件:X509Extensions.java   
/**
 * <pre>
 *     Extensions        ::=   SEQUENCE SIZE (1..MAX) OF Extension
 *
 *     Extension         ::=   SEQUENCE {
 *        extnId            EXTENSION.&amp;id ({ExtensionSet}),
 *        critical          BOOLEAN DEFAULT FALSE,
 *        extnValue         OCTET STRING }
 * </pre>
 */
public DERObject toASN1Object()
{
    ASN1EncodableVector     vec = new ASN1EncodableVector();
    Enumeration             e = ordering.elements();

    while (e.hasMoreElements())
    {
        DERObjectIdentifier     oid = (DERObjectIdentifier)e.nextElement();
        X509Extension           ext = (X509Extension)extensions.get(oid);
        ASN1EncodableVector     v = new ASN1EncodableVector();

        v.add(oid);

        if (ext.isCritical())
        {
            v.add(new DERBoolean(true));
        }

        v.add(ext.getValue());

        vec.add(new DERSequence(v));
    }

    return new DERSequence(vec);
}
项目:AcademicTorrents-Downloader    文件:BasicConstraints.java   
/**
 * @deprecated use one of the other two unambigous constructors.
 * @param cA
 * @param pathLenConstraint
 */
public BasicConstraints(
    boolean cA,
    int     pathLenConstraint)
{
    if (cA)
    {
        this.cA = new DERBoolean(cA);
        this.pathLenConstraint = new DERInteger(pathLenConstraint);
    }
    else
    {
        this.cA = null;
        this.pathLenConstraint = null;
    }
}
项目:CryptMeme    文件:X509Extensions.java   
/**
 * Constructor from ASN1Sequence.
 *
 * the extensions are a list of constructed sequences, either with (OID, OctetString) or (OID, Boolean, OctetString)
 */
public X509Extensions(
    ASN1Sequence  seq)
{
    Enumeration e = seq.getObjects();

    while (e.hasMoreElements())
    {
        ASN1Sequence            s = ASN1Sequence.getInstance(e.nextElement());

        if (s.size() == 3)
        {
            extensions.put(s.getObjectAt(0), new X509Extension(DERBoolean.getInstance(s.getObjectAt(1)), ASN1OctetString.getInstance(s.getObjectAt(2))));
        }
        else if (s.size() == 2)
        {
            extensions.put(s.getObjectAt(0), new X509Extension(false, ASN1OctetString.getInstance(s.getObjectAt(1))));
        }
        else
        {
            throw new IllegalArgumentException("Bad sequence size: " + s.size());
        }

        ordering.addElement(s.getObjectAt(0));
    }
}
项目:CryptMeme    文件:X509Extensions.java   
/**
 * <pre>
 *     Extensions        ::=   SEQUENCE SIZE (1..MAX) OF Extension
 *
 *     Extension         ::=   SEQUENCE {
 *        extnId            EXTENSION.&amp;id ({ExtensionSet}),
 *        critical          BOOLEAN DEFAULT FALSE,
 *        extnValue         OCTET STRING }
 * </pre>
 */
public ASN1Primitive toASN1Primitive()
{
    ASN1EncodableVector     vec = new ASN1EncodableVector();
    Enumeration             e = ordering.elements();

    while (e.hasMoreElements())
    {
        ASN1ObjectIdentifier    oid = (ASN1ObjectIdentifier)e.nextElement();
        X509Extension           ext = (X509Extension)extensions.get(oid);
        ASN1EncodableVector     v = new ASN1EncodableVector();

        v.add(oid);

        if (ext.isCritical())
        {
            v.add(DERBoolean.TRUE);
        }

        v.add(ext.getValue());

        vec.add(new DERSequence(v));
    }

    return new DERSequence(vec);
}
项目:irma_future_id    文件:X509Extensions.java   
/**
 * Constructor from ASN1Sequence.
 *
 * the extensions are a list of constructed sequences, either with (OID, OctetString) or (OID, Boolean, OctetString)
 */
public X509Extensions(
    ASN1Sequence  seq)
{
    Enumeration e = seq.getObjects();

    while (e.hasMoreElements())
    {
        ASN1Sequence            s = ASN1Sequence.getInstance(e.nextElement());

        if (s.size() == 3)
        {
            extensions.put(s.getObjectAt(0), new X509Extension(DERBoolean.getInstance(s.getObjectAt(1)), ASN1OctetString.getInstance(s.getObjectAt(2))));
        }
        else if (s.size() == 2)
        {
            extensions.put(s.getObjectAt(0), new X509Extension(false, ASN1OctetString.getInstance(s.getObjectAt(1))));
        }
        else
        {
            throw new IllegalArgumentException("Bad sequence size: " + s.size());
        }

        ordering.addElement(s.getObjectAt(0));
    }
}
项目:irma_future_id    文件:X509Extensions.java   
/**
 * <pre>
 *     Extensions        ::=   SEQUENCE SIZE (1..MAX) OF Extension
 *
 *     Extension         ::=   SEQUENCE {
 *        extnId            EXTENSION.&amp;id ({ExtensionSet}),
 *        critical          BOOLEAN DEFAULT FALSE,
 *        extnValue         OCTET STRING }
 * </pre>
 */
public ASN1Primitive toASN1Primitive()
{
    ASN1EncodableVector     vec = new ASN1EncodableVector();
    Enumeration             e = ordering.elements();

    while (e.hasMoreElements())
    {
        ASN1ObjectIdentifier    oid = (ASN1ObjectIdentifier)e.nextElement();
        X509Extension           ext = (X509Extension)extensions.get(oid);
        ASN1EncodableVector     v = new ASN1EncodableVector();

        v.add(oid);

        if (ext.isCritical())
        {
            v.add(DERBoolean.TRUE);
        }

        v.add(ext.getValue());

        vec.add(new DERSequence(v));
    }

    return new DERSequence(vec);
}
项目:bc-java    文件:X509Extensions.java   
/**
 * Constructor from ASN1Sequence.
 *
 * the extensions are a list of constructed sequences, either with (OID, OctetString) or (OID, Boolean, OctetString)
 */
public X509Extensions(
    ASN1Sequence  seq)
{
    Enumeration e = seq.getObjects();

    while (e.hasMoreElements())
    {
        ASN1Sequence            s = ASN1Sequence.getInstance(e.nextElement());

        if (s.size() == 3)
        {
            extensions.put(s.getObjectAt(0), new X509Extension(DERBoolean.getInstance(s.getObjectAt(1)), ASN1OctetString.getInstance(s.getObjectAt(2))));
        }
        else if (s.size() == 2)
        {
            extensions.put(s.getObjectAt(0), new X509Extension(false, ASN1OctetString.getInstance(s.getObjectAt(1))));
        }
        else
        {
            throw new IllegalArgumentException("Bad sequence size: " + s.size());
        }

        ordering.addElement(s.getObjectAt(0));
    }
}
项目:bc-java    文件:X509Extensions.java   
/**
 * <pre>
 *     Extensions        ::=   SEQUENCE SIZE (1..MAX) OF Extension
 *
 *     Extension         ::=   SEQUENCE {
 *        extnId            EXTENSION.&amp;id ({ExtensionSet}),
 *        critical          BOOLEAN DEFAULT FALSE,
 *        extnValue         OCTET STRING }
 * </pre>
 */
public ASN1Primitive toASN1Primitive()
{
    ASN1EncodableVector     vec = new ASN1EncodableVector();
    Enumeration             e = ordering.elements();

    while (e.hasMoreElements())
    {
        ASN1ObjectIdentifier    oid = (ASN1ObjectIdentifier)e.nextElement();
        X509Extension           ext = (X509Extension)extensions.get(oid);
        ASN1EncodableVector     v = new ASN1EncodableVector();

        v.add(oid);

        if (ext.isCritical())
        {
            v.add(DERBoolean.TRUE);
        }

        v.add(ext.getValue());

        vec.add(new DERSequence(v));
    }

    return new DERSequence(vec);
}
项目:cagrid-general    文件:BouncyCastleUtil.java   
/**
    * Creates a <code>BasicConstraints</code> object from given
    * extension.
    *
    * @param ext the extension.
    * @return the <code>BasicConstraints</code> object.
    * @exception IOException if something fails.
    */
   public static BasicConstraints getBasicConstraints(X509Extension ext) 
throws IOException {
DERObject obj = BouncyCastleUtil.getExtensionObject(ext);
if (obj instanceof ASN1Sequence) {
    ASN1Sequence seq = (ASN1Sequence)obj;
    int size = seq.size();
    if (size == 0) {
    return new BasicConstraints(false);
    } else if (size == 1) {
    DEREncodable value = seq.getObjectAt(0);
    if (value instanceof DERInteger) {
        int length = ((DERInteger)value).getValue().intValue();
        return new BasicConstraints(false, length);
    } else if (value instanceof DERBoolean) {
        boolean ca = ((DERBoolean)value).isTrue();
        return new BasicConstraints(ca);
    }
    } 
}
return BasicConstraints.getInstance(obj);
   }
项目:ipack    文件:BasicConstraints.java   
private BasicConstraints(
    ASN1Sequence   seq)
{
    if (seq.size() == 0)
    {
        this.cA = null;
        this.pathLenConstraint = null;
    }
    else
    {
        if (seq.getObjectAt(0) instanceof DERBoolean)
        {
            this.cA = DERBoolean.getInstance(seq.getObjectAt(0));
        }
        else
        {
            this.cA = null;
            this.pathLenConstraint = ASN1Integer.getInstance(seq.getObjectAt(0));
        }
        if (seq.size() > 1)
        {
            if (this.cA != null)
            {
                this.pathLenConstraint = ASN1Integer.getInstance(seq.getObjectAt(1));
            }
            else
            {
                throw new IllegalArgumentException("wrong sequence in constructor");
            }
        }
    }
}
项目:ipack    文件:X509Extension.java   
public X509Extension(
    DERBoolean              critical,
    ASN1OctetString         value)
{
    this.critical = critical.isTrue();
    this.value = value;
}
项目:Direct-File-Downloader    文件:X509Extension.java   
public X509Extension(
    DERBoolean              critical,
    ASN1OctetString         value)
{
    this.critical = critical.isTrue();
    this.value = value;
}
项目:AcademicTorrents-Downloader    文件:IssuingDistributionPoint.java   
/**
 * Constructor from ASN1Sequence
 */
public IssuingDistributionPoint(
    ASN1Sequence seq)
{
    this.seq = seq;

    for (int i = 0; i != seq.size(); i++)
    {
        ASN1TaggedObject o = ASN1TaggedObject.getInstance(seq.getObjectAt(i));

        switch (o.getTagNo())
        {
        case 0:
                                                // CHOICE so explicit
            distributionPoint = DistributionPointName.getInstance(o, true);
            break;
        case 1:
            onlyContainsUserCerts = DERBoolean.getInstance(o, false).isTrue();
            break;
        case 2:
            onlyContainsCACerts = DERBoolean.getInstance(o, false).isTrue();
            break;
        case 3:
            onlySomeReasons = new ReasonFlags(ReasonFlags.getInstance(o, false));
            break;
        case 4:
            indirectCRL = DERBoolean.getInstance(o, false).isTrue();
            break;
        case 5:
            onlyContainsAttributeCerts = DERBoolean.getInstance(o, false).isTrue();
            break;
        default:
            throw new IllegalArgumentException(
                    "unknown tag in IssuingDistributionPoint");
        }
    }
}
项目:AcademicTorrents-Downloader    文件:BasicConstraints.java   
public BasicConstraints(
    ASN1Sequence   seq)
{
    if (seq.size() == 0)
    {
        this.cA = null;
        this.pathLenConstraint = null;
    }
    else
    {
        if (seq.getObjectAt(0) instanceof DERBoolean)
        {
            this.cA = DERBoolean.getInstance(seq.getObjectAt(0));
        }
        else
        {
            this.cA = null;
            this.pathLenConstraint = DERInteger.getInstance(seq.getObjectAt(0));
        }
        if (seq.size() > 1)
        {
            if (this.cA != null)
            {
                this.pathLenConstraint = DERInteger.getInstance(seq.getObjectAt(1));
            }
            else
            {
                throw new IllegalArgumentException("wrong sequence in constructor");
            }
        }
    }
}
项目:AcademicTorrents-Downloader    文件:BasicConstraints.java   
public BasicConstraints(
    boolean cA)
{
    if (cA)
    {
        this.cA = new DERBoolean(true);
    }
    else
    {
        this.cA = null;
    }
    this.pathLenConstraint = null;
}
项目:AcademicTorrents-Downloader    文件:BasicConstraints.java   
/**
 * create a cA=true object for the given path length constraint.
 * 
 * @param pathLenConstraint
 */
public BasicConstraints(
    int     pathLenConstraint)
{
    this.cA = new DERBoolean(true);
    this.pathLenConstraint = new DERInteger(pathLenConstraint);
}
项目:AcademicTorrents-Downloader    文件:X509Extension.java   
public X509Extension(
    DERBoolean              critical,
    ASN1OctetString         value)
{
    this.critical = critical.isTrue();
    this.value = value;
}
项目:CryptMeme    文件:BasicConstraints.java   
private BasicConstraints(
    ASN1Sequence   seq)
{
    if (seq.size() == 0)
    {
        this.cA = null;
        this.pathLenConstraint = null;
    }
    else
    {
        if (seq.getObjectAt(0) instanceof DERBoolean)
        {
            this.cA = DERBoolean.getInstance(seq.getObjectAt(0));
        }
        else
        {
            this.cA = null;
            this.pathLenConstraint = ASN1Integer.getInstance(seq.getObjectAt(0));
        }
        if (seq.size() > 1)
        {
            if (this.cA != null)
            {
                this.pathLenConstraint = ASN1Integer.getInstance(seq.getObjectAt(1));
            }
            else
            {
                throw new IllegalArgumentException("wrong sequence in constructor");
            }
        }
    }
}
项目:CryptMeme    文件:X509Extension.java   
public X509Extension(
    DERBoolean              critical,
    ASN1OctetString         value)
{
    this.critical = critical.isTrue();
    this.value = value;
}
项目:irma_future_id    文件:BasicConstraints.java   
private BasicConstraints(
    ASN1Sequence   seq)
{
    if (seq.size() == 0)
    {
        this.cA = null;
        this.pathLenConstraint = null;
    }
    else
    {
        if (seq.getObjectAt(0) instanceof DERBoolean)
        {
            this.cA = DERBoolean.getInstance(seq.getObjectAt(0));
        }
        else
        {
            this.cA = null;
            this.pathLenConstraint = ASN1Integer.getInstance(seq.getObjectAt(0));
        }
        if (seq.size() > 1)
        {
            if (this.cA != null)
            {
                this.pathLenConstraint = ASN1Integer.getInstance(seq.getObjectAt(1));
            }
            else
            {
                throw new IllegalArgumentException("wrong sequence in constructor");
            }
        }
    }
}
项目:irma_future_id    文件:X509Extension.java   
public X509Extension(
    DERBoolean              critical,
    ASN1OctetString         value)
{
    this.critical = critical.isTrue();
    this.value = value;
}
项目:irma_future_id    文件:SetTest.java   
private void checkedSortedSet(int attempt, ASN1Set s)
{
    if (s.getObjectAt(0) instanceof DERBoolean
        && s.getObjectAt(1) instanceof DERInteger
        && s.getObjectAt(2) instanceof DERBitString
        && s.getObjectAt(3) instanceof DEROctetString)
    {
        return;
    }

    fail("sorting failed on attempt: " + attempt);
}
项目:bc-java    文件:BasicConstraints.java   
private BasicConstraints(
    ASN1Sequence   seq)
{
    if (seq.size() == 0)
    {
        this.cA = null;
        this.pathLenConstraint = null;
    }
    else
    {
        if (seq.getObjectAt(0) instanceof DERBoolean)
        {
            this.cA = DERBoolean.getInstance(seq.getObjectAt(0));
        }
        else
        {
            this.cA = null;
            this.pathLenConstraint = ASN1Integer.getInstance(seq.getObjectAt(0));
        }
        if (seq.size() > 1)
        {
            if (this.cA != null)
            {
                this.pathLenConstraint = ASN1Integer.getInstance(seq.getObjectAt(1));
            }
            else
            {
                throw new IllegalArgumentException("wrong sequence in constructor");
            }
        }
    }
}
项目:bc-java    文件:X509Extension.java   
public X509Extension(
    DERBoolean              critical,
    ASN1OctetString         value)
{
    this.critical = critical.isTrue();
    this.value = value;
}
项目:bc-java    文件:SetTest.java   
private void checkedSortedSet(int attempt, ASN1Set s)
{
    if (s.getObjectAt(0) instanceof DERBoolean
        && s.getObjectAt(1) instanceof DERInteger
        && s.getObjectAt(2) instanceof DERBitString
        && s.getObjectAt(3) instanceof DEROctetString)
    {
        return;
    }

    fail("sorting failed on attempt: " + attempt);
}
项目:AcademicTorrents-Downloader    文件:IssuingDistributionPoint.java   
/**
 * Constructor from given details.
 * 
 * @param distributionPoint
 *            May contain an URI as pointer to most current CRL.
 * @param onlyContainsUserCerts Covers revocation information for end certificates.
 * @param onlyContainsCACerts Covers revocation information for CA certificates.
 * 
 * @param onlySomeReasons
 *            Which revocation reasons does this point cover.
 * @param indirectCRL
 *            If <code>true</code> then the CRL contains revocation
 *            information about certificates ssued by other CAs.
 * @param onlyContainsAttributeCerts Covers revocation information for attribute certificates.
 */
public IssuingDistributionPoint(
    DistributionPointName distributionPoint,
    boolean onlyContainsUserCerts,
    boolean onlyContainsCACerts,
    ReasonFlags onlySomeReasons,
    boolean indirectCRL,
    boolean onlyContainsAttributeCerts)
{
    this.distributionPoint = distributionPoint;
    this.indirectCRL = indirectCRL;
    this.onlyContainsAttributeCerts = onlyContainsAttributeCerts;
    this.onlyContainsCACerts = onlyContainsCACerts;
    this.onlyContainsUserCerts = onlyContainsUserCerts;
    this.onlySomeReasons = onlySomeReasons;

    ASN1EncodableVector vec = new ASN1EncodableVector();
    if (distributionPoint != null)
    {                                    // CHOICE item so explicitly tagged
        vec.add(new DERTaggedObject(true, 0, distributionPoint));
    }
    if (!onlyContainsUserCerts)
    {
        vec.add(new DERTaggedObject(false, 1, new DERBoolean(true)));
    }
    if (!onlyContainsCACerts)
    {
        vec.add(new DERTaggedObject(false, 2, new DERBoolean(true)));
    }
    if (onlySomeReasons != null)
    {
        vec.add(new DERTaggedObject(false, 3, onlySomeReasons));
    }
    if (!indirectCRL)
    {
        vec.add(new DERTaggedObject(false, 4, new DERBoolean(true)));
    }
    if (!onlyContainsAttributeCerts)
    {
        vec.add(new DERTaggedObject(false, 5, new DERBoolean(true)));
    }

    seq = new DERSequence(vec);
}
项目:irma_future_id    文件:EqualsAndHashCodeTest.java   
public TestResult perform()
{
    byte[]    data = { 0, 1, 0, 1, 0, 0, 1 };

    ASN1Primitive    values[] = {
            new BERConstructedOctetString(data),
            new BERSequence(new DERPrintableString("hello world")),
            new BERSet(new DERPrintableString("hello world")),
            new BERTaggedObject(0, new DERPrintableString("hello world")),
            new DERApplicationSpecific(0, data),
            new DERBitString(data),
            new DERBMPString("hello world"),
            new DERBoolean(true),
            new DERBoolean(false),
            new DEREnumerated(100),
            new DERGeneralizedTime("20070315173729Z"),
            new DERGeneralString("hello world"),
            new DERIA5String("hello"),
            new DERInteger(1000),
            new DERNull(),
            new DERNumericString("123456"),
            new DERObjectIdentifier("1.1.1.10000.1"),
            new DEROctetString(data),
            new DERPrintableString("hello world"),
            new DERSequence(new DERPrintableString("hello world")),
            new DERSet(new DERPrintableString("hello world")),
            new DERT61String("hello world"),
            new DERTaggedObject(0, new DERPrintableString("hello world")),
            new DERUniversalString(data),
            new DERUTCTime(new Date()),
            new DERUTF8String("hello world"),
            new DERVisibleString("hello world")
        };

    try
    {
        ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
        ASN1OutputStream        aOut = new ASN1OutputStream(bOut);

        for (int i = 0; i != values.length; i++)
        {
            aOut.writeObject(values[i]);
        }

        ASN1Primitive[] readValues = new ASN1Primitive[values.length];

        ByteArrayInputStream    bIn = new ByteArrayInputStream(bOut.toByteArray());
        ASN1InputStream         aIn = new ASN1InputStream(bIn);

        for (int i = 0; i != values.length; i++)
        {
            ASN1Primitive o = aIn.readObject();
            if (!o.equals(values[i]))
            {
                return new SimpleTestResult(false, getName() + ": Failed equality test for " + o.getClass());
            }

            if (o.hashCode() != values[i].hashCode())
            {
                return new SimpleTestResult(false, getName() + ": Failed hashCode test for " + o.getClass());
            }
        }
    }
    catch (Exception e)
    {
        return new SimpleTestResult(false, getName() + ": Failed - exception " + e.toString(), e);
    }

    return new SimpleTestResult(true, getName() + ": Okay");
}
项目:bc-java    文件:EqualsAndHashCodeTest.java   
public TestResult perform()
{
    byte[]    data = { 0, 1, 0, 1, 0, 0, 1 };

    ASN1Primitive    values[] = {
            new BERConstructedOctetString(data),
            new BERSequence(new DERPrintableString("hello world")),
            new BERSet(new DERPrintableString("hello world")),
            new BERTaggedObject(0, new DERPrintableString("hello world")),
            new DERApplicationSpecific(0, data),
            new DERBitString(data),
            new DERBMPString("hello world"),
            new DERBoolean(true),
            new DERBoolean(false),
            new DEREnumerated(100),
            new DERGeneralizedTime("20070315173729Z"),
            new DERGeneralString("hello world"),
            new DERIA5String("hello"),
            new DERInteger(1000),
            new DERNull(),
            new DERNumericString("123456"),
            new DERObjectIdentifier("1.1.1.10000.1"),
            new DEROctetString(data),
            new DERPrintableString("hello world"),
            new DERSequence(new DERPrintableString("hello world")),
            new DERSet(new DERPrintableString("hello world")),
            new DERT61String("hello world"),
            new DERTaggedObject(0, new DERPrintableString("hello world")),
            new DERUniversalString(data),
            new DERUTCTime(new Date()),
            new DERUTF8String("hello world"),
            new DERVisibleString("hello world")
        };

    try
    {
        ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
        ASN1OutputStream        aOut = new ASN1OutputStream(bOut);

        for (int i = 0; i != values.length; i++)
        {
            aOut.writeObject(values[i]);
        }

        ASN1Primitive[] readValues = new ASN1Primitive[values.length];

        ByteArrayInputStream    bIn = new ByteArrayInputStream(bOut.toByteArray());
        ASN1InputStream         aIn = new ASN1InputStream(bIn);

        for (int i = 0; i != values.length; i++)
        {
            ASN1Primitive o = aIn.readObject();
            if (!o.equals(values[i]))
            {
                return new SimpleTestResult(false, getName() + ": Failed equality test for " + o.getClass());
            }

            if (o.hashCode() != values[i].hashCode())
            {
                return new SimpleTestResult(false, getName() + ": Failed hashCode test for " + o.getClass());
            }
        }
    }
    catch (Exception e)
    {
        return new SimpleTestResult(false, getName() + ": Failed - exception " + e.toString(), e);
    }

    return new SimpleTestResult(true, getName() + ": Okay");
}
项目:vbrowser    文件:VOMSAttributeCertificate.java   
private void setExtensions() throws Exception
{
    try
    {
        Vector<DERObjectIdentifier> myOIDs = new Vector<DERObjectIdentifier>() ;
        Hashtable<DERObjectIdentifier,X509Extension> myExtensions = new Hashtable<DERObjectIdentifier,X509Extension>() ;

        //--------------------------------------------------------------------------
        // id-ce-noRevAvail

        ByteArrayOutputStream a = new ByteArrayOutputStream() ;
        new DEROutputStream( a ).writeObject( ( new DERNull() ).toASN1Object() ) ; 
        ASN1OctetString nraOctetString = ASN1OctetString.getInstance( new DEROctetString( a.toByteArray() ) ) ;

        X509Extension nraExtension = new X509Extension( new DERBoolean( false ) , nraOctetString ) ;
        DERObjectIdentifier nraOID = new DERObjectIdentifier( "2.5.29.56" ) ;

        myOIDs.add( nraOID ) ;
        myExtensions.put( nraOID , nraExtension ) ;

        //--------------------------------------------------------------------------
        // AuthorityKeyIdentifier
        myLogger.warn("VOMSAttributeCertificate verification not implemented yet.");

        //      String issuerDN = this.getIssuer() ;
        //
        //      String serverName = "unknown" ;
        //      //serverName = VirtualOrganisation.getServer( issuerDN ) ;
        //
        //      if( ! serverName.equals( "unknown" ) )
        //      {
        //        String vomsServerCredentialLocation = new String( System.getProperty( "user.home" ) + "/gridsecurity/certificates/voms-server-certificates/" + serverName ) ;
        //
        //        X509Certificate vomsServerCredential = CertUtil.loadCertificate( vomsServerCredentialLocation ) ;
        //
        //        PublicKey pk = vomsServerCredential.getPublicKey() ;
        //
        //        SubjectPublicKeyInfo spki = new SubjectPublicKeyInfo( (ASN1Sequence) new ASN1InputStream( new ByteArrayInputStream( pk.getEncoded() ) ).readObject() ) ;
        //        AuthorityKeyIdentifier aki = new AuthorityKeyIdentifier( spki ) ;
        //
        //        // not clear why this does not work...
        //        // DEROctetString akiOctetString = (DEROctetString) DEROctetString.getInstance( akiSequence.getDERObject() ) ;
        //
        //        // These three lines get to the desired result...
        //        ByteArrayOutputStream b = new ByteArrayOutputStream() ;
        //        new DEROutputStream( b ).writeObject( aki.toASN1Object() ) ; 
        //        ASN1OctetString akiOctetString = ASN1OctetString.getInstance( new DEROctetString( b.toByteArray() ) ) ;
        //
        //        X509Extension akiExtension = new X509Extension( new DERBoolean( false ) , akiOctetString ) ;
        //        DERObjectIdentifier akiOID = new DERObjectIdentifier( "2.5.29.35" ) ;
        //
        //        myOIDs.add( akiOID ) ;
        //        myExtensions.put( akiOID , akiExtension ) ;
        //
        //        this.extensions = new X509Extensions( myOIDs , myExtensions ) ;
        //
        //      }


    }
    catch( Exception e ) 
    { 
        myLogger.error(e);
        //e.printStackTrace() ; 
    } 

}