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

The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider for the Bouncy Castle Cryptography APIs for JDK 1.5 to JDK 1.7.

There is a newer version: 1.47.0.3
Show newest version
package org.spongycastle.asn1.x509;

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

import org.spongycastle.asn1.ASN1EncodableVector;
import org.spongycastle.asn1.ASN1Object;
import org.spongycastle.asn1.ASN1Primitive;
import org.spongycastle.asn1.ASN1Sequence;
import org.spongycastle.asn1.ASN1TaggedObject;
import org.spongycastle.asn1.DERSequence;
import org.spongycastle.asn1.DERTaggedObject;

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

    public static NameConstraints getInstance(Object obj)
    {
        if (obj instanceof NameConstraints)
        {
            return (NameConstraints)obj;
        }
        if (obj != null)
        {
            return new NameConstraints(ASN1Sequence.getInstance(obj));
        }

        return null;
    }

    private 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 ASN1Primitive toASN1Primitive() { 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