/*
* 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.
*/
/**
* Represent the Key Usage Extension.
*
* <p>This extension, if present, defines the purpose (e.g., encipherment,
* signature, certificate signing) of the key contained in the certificate.
* The usage restriction might be employed when a multipurpose key is to be
* restricted (e.g., when an RSA key should be used only for signing or only
* for key encipherment).
*
* @author Amit Kapoor
* @author Hemma Prafullchandra
* @see Extension
* @see CertAttrSet
*/
implements CertAttrSet<String> {
/**
* Identifier for this attribute, to be used with the
* get, set, delete methods of Certificate, x509 type.
*/
/**
* Attribute names.
*/
// Private data members
private boolean[] bitString;
// Encode this extension value
}
/**
* Check if bit is set.
*
* @param position the position in the bit string to check.
*/
}
/**
* Set the bit at the specified position.
*/
// enlarge bitString if necessary
}
}
/**
* Create a KeyUsageExtension with the passed bit settings. The criticality
* is set to true.
*
* @param bitString the bits to be set for the extension.
*/
this.bitString =
this.critical = true;
encodeThis();
}
/**
* Create a KeyUsageExtension with the passed bit settings. The criticality
* is set to true.
*
* @param bitString the bits to be set for the extension.
*/
this.critical = true;
encodeThis();
}
/**
* Create a KeyUsageExtension with the passed bit settings. The criticality
* is set to true.
*
* @param bitString the bits to be set for the extension.
*/
this.critical = true;
encodeThis();
}
/**
* Create the extension from the passed DER encoded value of the same.
* The DER encoded value may be wrapped in an OCTET STRING.
*
* @param critical true if the extension is to be treated as critical.
* @param value an array of DER encoded bytes of the actual value (possibly
* wrapped in an OCTET STRING).
* @exception ClassCastException if value is not an array of bytes
* @exception IOException on error.
*/
throws IOException {
/*
* The following check should be activated again after
* the PKIX profiling work becomes standard and the check
* is not a barrier to interoperability !
* if (!this.critical) {
* throw new IOException("KeyUsageExtension not marked critical,"
* + " invalid profile.");
* }
*/
} else {
this.extensionValue = extValue;
}
}
/**
* Create a default key usage.
*/
public KeyUsageExtension() {
critical = true;
bitString = new boolean[0];
}
/**
* Set the attribute value.
*/
throw new IOException("Attribute must be of type Boolean.");
}
} else {
throw new IOException("Attribute name not recognized by"
+ " CertAttrSet:KeyUsage.");
}
encodeThis();
}
/**
* Get the attribute value.
*/
} else {
throw new IOException("Attribute name not recognized by"
+ " CertAttrSet:KeyUsage.");
}
}
/**
* Delete the attribute value.
*/
set(0,false);
set(1,false);
set(2,false);
set(3,false);
set(4,false);
set(5,false);
set(6,false);
set(7,false);
set(8,false);
} else {
throw new IOException("Attribute name not recognized by"
+ " CertAttrSet:KeyUsage.");
}
encodeThis();
}
/**
* Returns a printable representation of the KeyUsage.
*/
try {
if (isSet(0)) {
s += " DigitalSignature\n";
}
if (isSet(1)) {
s += " Non_repudiation\n";
}
if (isSet(2)) {
s += " Key_Encipherment\n";
}
if (isSet(3)) {
s += " Data_Encipherment\n";
}
if (isSet(4)) {
s += " Key_Agreement\n";
}
if (isSet(5)) {
s += " Key_CertSign\n";
}
if (isSet(6)) {
s += " Crl_Sign\n";
}
if (isSet(7)) {
s += " Encipher_Only\n";
}
if (isSet(8)) {
s += " Decipher_Only\n";
}
} catch (ArrayIndexOutOfBoundsException ex) {}
s += "]\n";
return (s);
}
/**
* Write the extension to the DerOutputStream.
*
* @param out the DerOutputStream to write the extension to.
* @exception IOException on encoding errors.
*/
if (this.extensionValue == null) {
this.critical = true;
encodeThis();
}
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
}
public boolean[] getBits() {
}
/**
* Return the name of this attribute.
*/
return (NAME);
}
}