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

se.idsec.x509cert.extensions.SubjectInformationAccess Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2020. IDsec Solutions AB
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package se.idsec.x509cert.extensions;

import lombok.Getter;
import org.bouncycastle.asn1.*;
import org.bouncycastle.asn1.x509.AccessDescription;
import org.bouncycastle.asn1.x509.Extension;
import org.bouncycastle.asn1.x509.Extensions;
import org.bouncycastle.asn1.x509.GeneralName;
import se.idsec.x509cert.extensions.data.OidName;

/**
 * SubjectInformationAccess X.509 extension implementation for extending Bouncycastle
 *
 * The AuthorityInformationAccess object.
 * 
 * id-pe-subjectInfoAccess OBJECT IDENTIFIER ::= { id-pe 11 }
 *
 * SubjectInfoAccessSyntax  ::=
 *      SEQUENCE SIZE (1..MAX) OF AccessDescription
 * AccessDescription  ::=  SEQUENCE {
 *       accessMethod          OBJECT IDENTIFIER,
 *       accessLocation        GeneralName  }
 *
 * 
* @author Martin Lindström ([email protected]) * @author Stefan Santesson ([email protected]) */ public class SubjectInformationAccess extends ASN1Object { public static final ASN1ObjectIdentifier caRepository = new ASN1ObjectIdentifier(OidName.id_pkix_ad_caRepository.getOid()); public static final ASN1ObjectIdentifier timeStamping = new ASN1ObjectIdentifier(OidName.id_pkix_ad_timestamping.getOid()); /** Access descriptions */ @Getter private AccessDescription[] accessDescriptions; /** * Creates an instance of SubjectInformationAccess extension * @param obj object holding extension data * @return {@link SubjectInformationAccess} extension */ public static SubjectInformationAccess getInstance( Object obj) { if (obj instanceof SubjectInformationAccess) { return (SubjectInformationAccess) obj; } if (obj != null) { return new SubjectInformationAccess(ASN1Sequence.getInstance(obj)); } return null; } /** * Creates an instance of SubjectInformationAccess extension * @param extensions extensions data * @return {@link SubjectInformationAccess} extension */ public static SubjectInformationAccess fromExtensions(Extensions extensions) { return SubjectInformationAccess.getInstance(extensions.getExtensionParsedValue(Extension.authorityInfoAccess)); } /** * Private constructor * @param seq ASN.1 sequence */ private SubjectInformationAccess( ASN1Sequence seq) { if (seq.size() < 1) { throw new IllegalArgumentException("sequence may not be empty"); } accessDescriptions = new AccessDescription[seq.size()]; for (int i = 0; i != seq.size(); i++) { accessDescriptions[i] = AccessDescription.getInstance(seq.getObjectAt(i)); } } /** * Constructor * @param description access description */ public SubjectInformationAccess( AccessDescription description) { this(new AccessDescription[]{description}); } /** * Constructor * @param accessDescriptions access descriptions */ public SubjectInformationAccess( AccessDescription[] accessDescriptions) { this.accessDescriptions = new AccessDescription[accessDescriptions.length]; System.arraycopy(accessDescriptions, 0, this.accessDescriptions, 0, accessDescriptions.length); } /** * create an AuthorityInformationAccess with the oid and location provided. * * @param oid OID * @param location location */ public SubjectInformationAccess( ASN1ObjectIdentifier oid, GeneralName location) { this(new AccessDescription(oid, location)); } public ASN1Primitive toASN1Primitive() { ASN1EncodableVector vec = new ASN1EncodableVector(); for (int i = 0; i != accessDescriptions.length; i++) { vec.add(accessDescriptions[i]); } return new DERSequence(vec); } /** {@inheritDoc} */ @Override public String toString() { return ("SubjectInformationAccess: Oid(" + this.accessDescriptions[0].getAccessMethod().getId() + ")"); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy