All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.spongycastle.asn1.x509.NameConstraints Maven / Gradle / Ivy

Go to download

Spongy Castle is a package-rename (org.bouncycastle.* to org.spongycastle.*) of Bouncy Castle intended for Android. Android ships with a stripped-down version of Bouncy Castle - this causes classloader collisions if you try to add an alternative (updated/complete) Bouncy Castle jar. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5.

There is a newer version: 1.46.99.3-UNOFFICIAL-ROBERTO-RELEASE
Show newest version
package org.spongycastle.asn1.x509;

import java.util.Enumeration;
import java.util.Vector;

import org.spongycastle.asn1.ASN1Encodable;
import org.spongycastle.asn1.ASN1EncodableVector;
import org.spongycastle.asn1.ASN1Sequence;
import org.spongycastle.asn1.ASN1TaggedObject;
import org.spongycastle.asn1.DERObject;
import org.spongycastle.asn1.DERSequence;
import org.spongycastle.asn1.DERTaggedObject;

public class NameConstraints
    extends ASN1Encodable
{
    private ASN1Sequence permitted, excluded;

    public NameConstraints(ASN1Sequence seq)
    {
        Enumeration e = seq.getObjects();
        while (e.hasMoreElements())
        {
            ASN1TaggedObject o = ASN1TaggedObject.getInstance(e.nextElement());
            switch (o.getTagNo())
            {
            case 0:
                permitted = ASN1Sequence.getInstance(o, false);
                break;
            case 1:
                excluded = ASN1Sequence.getInstance(o, false);
                break;
            }
        }
    }

    /**
     * Constructor from a given details.
     * 
     * 

* permitted and excluded are Vectors of GeneralSubtree objects. * * @param permitted * Permitted subtrees * @param excluded * Excludes subtrees */ public NameConstraints( Vector permitted, Vector excluded) { if (permitted != null) { this.permitted = createSequence(permitted); } if (excluded != null) { this.excluded = createSequence(excluded); } } private DERSequence createSequence(Vector subtree) { ASN1EncodableVector vec = new ASN1EncodableVector(); Enumeration e = subtree.elements(); while (e.hasMoreElements()) { vec.add((GeneralSubtree)e.nextElement()); } return new DERSequence(vec); } public ASN1Sequence getPermittedSubtrees() { return permitted; } public ASN1Sequence getExcludedSubtrees() { return excluded; } /* * NameConstraints ::= SEQUENCE { permittedSubtrees [0] GeneralSubtrees * OPTIONAL, excludedSubtrees [1] GeneralSubtrees OPTIONAL } */ public DERObject toASN1Object() { ASN1EncodableVector v = new ASN1EncodableVector(); if (permitted != null) { v.add(new DERTaggedObject(false, 0, permitted)); } if (excluded != null) { v.add(new DERTaggedObject(false, 1, excluded)); } return new DERSequence(v); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy