Path: blob/master/src/java.base/share/classes/sun/security/pkcs10/PKCS10Attribute.java
41159 views
/*1* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.security.pkcs10;2627import java.io.OutputStream;28import java.io.IOException;2930import sun.security.pkcs.PKCS9Attribute;31import sun.security.util.*;3233/**34* Represent a PKCS#10 Attribute.35*36* <p>Attributes are additonal information which can be inserted in a PKCS#1037* certificate request. For example a "Driving License Certificate" could have38* the driving license number as an attribute.39*40* <p>Attributes are represented as a sequence of the attribute identifier41* (Object Identifier) and a set of DER encoded attribute values.42*43* ASN.1 definition of Attribute:44* <pre>45* Attribute :: SEQUENCE {46* type AttributeType,47* values SET OF AttributeValue48* }49* AttributeType ::= OBJECT IDENTIFIER50* AttributeValue ::= ANY defined by type51* </pre>52*53* @author Amit Kapoor54* @author Hemma Prafullchandra55*/56public class PKCS10Attribute implements DerEncoder {5758protected ObjectIdentifier attributeId = null;59protected Object attributeValue = null;6061/**62* Constructs an attribute from a DER encoding.63* This constructor expects the value to be encoded as defined above,64* i.e. a SEQUENCE of OID and SET OF value(s), not a literal65* X.509 v3 extension. Only PKCS9 defined attributes are supported66* currently.67*68* @param derVal the der encoded attribute.69* @exception IOException on parsing errors.70*/71public PKCS10Attribute(DerValue derVal) throws IOException {72PKCS9Attribute attr = new PKCS9Attribute(derVal);73this.attributeId = attr.getOID();74this.attributeValue = attr.getValue();75}7677/**78* Constructs an attribute from individual components of79* ObjectIdentifier and the value (any java object).80*81* @param attributeId the ObjectIdentifier of the attribute.82* @param attributeValue an instance of a class that implements83* the attribute identified by the ObjectIdentifier.84*/85public PKCS10Attribute(ObjectIdentifier attributeId,86Object attributeValue) {87this.attributeId = attributeId;88this.attributeValue = attributeValue;89}9091/**92* Constructs an attribute from PKCS9 attribute.93*94* @param attr the PKCS9Attribute to create from.95*/96public PKCS10Attribute(PKCS9Attribute attr) {97this.attributeId = attr.getOID();98this.attributeValue = attr.getValue();99}100101/**102* DER encode this object onto an output stream.103* Implements the <code>DerEncoder</code> interface.104*105* @param out106* the OutputStream on which to write the DER encoding.107*108* @exception IOException on encoding errors.109*/110public void derEncode(OutputStream out) throws IOException {111PKCS9Attribute attr = new PKCS9Attribute(attributeId, attributeValue);112attr.derEncode(out);113}114115/**116* Returns the ObjectIdentifier of the attribute.117*/118public ObjectIdentifier getAttributeId() {119return (attributeId);120}121122/**123* Returns the attribute value.124*/125public Object getAttributeValue() {126return (attributeValue);127}128129/**130* Returns the attribute in user readable form.131*/132public String toString() {133return (attributeValue.toString());134}135}136137138