/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* A set of attributes of class PKCS9Attribute.
*
* @author Douglas Hoover
*/
public class PKCS9Attributes {
/**
* Attributes in this set indexed by OID.
*/
/**
* The keys of this hashtable are the OIDs of permitted attributes.
*/
/**
* The DER encoding of this attribute set. The tag byte must be
* DerValue.tag_SetOf.
*/
private final byte[] derEncoding;
/*
* Contols how attributes, which are not recognized by the PKCS9Attribute
* class, are handled during parsing.
*/
private boolean ignoreUnsupportedAttributes = false;
/**
* Construct a set of PKCS9 Attributes from its
* DER encoding on a DerInputStream, accepting only attributes
* with OIDs on the given
* list. If the array is null, accept all attributes supported by
* class PKCS9Attribute.
*
* @param permittedAttributes
* Array of attribute OIDs that will be accepted.
* @param in
* the contents of the DER encoding of the attribute set.
*
* @exception IOException
* on i/o error, encoding syntax error, unacceptable or
* unsupported attribute, or duplicate attribute.
*
* @see PKCS9Attribute
*/
if (permittedAttributes != null) {
this.permittedAttributes =
permittedAttributes[i]);
} else {
this.permittedAttributes = null;
}
// derEncoding initialized in <code>decode()</code>
}
/**
* Construct a set of PKCS9 Attributes from the contents of its
* DER encoding on a DerInputStream. Accept all attributes
* supported by class PKCS9Attribute and reject any unsupported
* attributes.
*
* @param in the contents of the DER encoding of the attribute set.
* @exception IOException
* on i/o error, encoding syntax error, or unsupported or
* duplicate attribute.
*
* @see PKCS9Attribute
*/
this(in, false);
}
/**
* Construct a set of PKCS9 Attributes from the contents of its
* DER encoding on a DerInputStream. Accept all attributes
* supported by class PKCS9Attribute and ignore any unsupported
* attributes, if directed.
*
* @param in the contents of the DER encoding of the attribute set.
* @param ignoreUnsupportedAttributes If true then any attributes
* not supported by the PKCS9Attribute class are ignored. Otherwise
* unsupported attributes cause an exception to be thrown.
* @exception IOException
* on i/o error, encoding syntax error, or unsupported or
* duplicate attribute.
*
* @see PKCS9Attribute
*/
boolean ignoreUnsupportedAttributes) throws IOException {
// derEncoding initialized in <code>decode()</code>
}
/**
* Construct a set of PKCS9 Attributes from the given array of
* PKCS9 attributes.
* DER encoding on a DerInputStream. All attributes in
* <code>attribs</code> must be
* supported by class PKCS9Attribute.
*
* @exception IOException
* on i/o error, encoding syntax error, or unsupported or
* duplicate attribute.
*
* @see PKCS9Attribute
*/
throws IllegalArgumentException, IOException {
throw new IllegalArgumentException(
" duplicated while constructing " +
"PKCS9Attributes.");
}
}
/**
* Decode this set of PKCS9 attributes from the contents of its
* DER encoding. Ignores unsupported attributes when directed.
*
* @param in
* the contents of the DER encoding of the attribute set.
*
* @exception IOException
* on i/o error, encoding syntax error, unacceptable or
* unsupported attribute, or duplicate attribute.
*/
// save the DER encoding with its proper tag byte.
boolean reuseEncoding = true;
try {
} catch (ParsingException e) {
if (ignoreUnsupportedAttributes) {
reuseEncoding = false; // cannot reuse supplied DER encoding
continue; // skip
} else {
throw e;
}
}
if (permittedAttributes != null &&
" not permitted in this attribute set");
}
}
/**
* Put the DER encoding of this PKCS9 attribute set on an
* DerOutputStream, tagged with the given implicit tag.
*
* @param tag the implicit tag to use in the DER encoding.
* @param out the output stream on which to put the DER encoding.
*
* @exception IOException on output error.
*/
}
return out.toByteArray();
}
/**
* Return the DER encoding of this attribute set, tagged with
* DerValue.tag_SetOf.
*/
return derEncoding.clone();
}
/**
* Get an attribute from this set.
*/
}
/**
* Get an attribute from this set.
*/
}
/**
* Get an array of all attributes in this set, in order of OID.
*/
int j = 0;
j++;
}
return attribs;
}
/**
* Get an attribute value by OID.
*/
throws IOException {
try {
return value;
} catch (NullPointerException ex) {
}
}
/**
* Get an attribute value by type name.
*/
" not recognized or not supported.");
return getAttributeValue(oid);
}
/**
* Returns the PKCS9 block in a printable string form.
*/
boolean first = true;
// we have a value; print it
if (first)
first = false;
else
}
}
/**
* Cast an object array whose components are
* <code>DerEncoder</code>s to <code>DerEncoder[]</code>.
*/
return encoders;
}
}