iaik.cms
Class CertificateChoices

java.lang.Object
  extended by iaik.cms.CertificateChoices

public class CertificateChoices
extends java.lang.Object

This class implements the CMS type CertificateChoices. The Cryptographic Message Syntax (CMS) (RFC 5652) specifies the CertificateChoices type for modeling several certificate types to maybe included into a CertificateSet:

 CertificateSet ::= SET OF CertificateChoices
 
CertificateChoices ::= CHOICE { certificate Certificate, -- see X.509 extendedCertificate [0] IMPLICIT ExtendedCertificate, -- Obsolete; see PKCS#6 v1AttrCert [1] IMPLICIT AttributeCertificateV1, -- Obsolete; see X.509-1997 v2AttrCert [2] IMPLICIT AttributeCertificateV2, -- see X509-2000 other [3] IMPLICIT OtherCertificateFormat } OtherCertificateFormat ::= SEQUENCE { otherCertFormat OBJECT IDENTIFIER, otherCert ANY DEFINED BY otherCertFormat } CertificateSet ::= SET OF CertificateChoices
When creating a CertificateChoices object the certificate has to be given as X.509 public key certificate (instance of iaik.x509.X509Certificate), X.509 attribute certificate (instance of iaik.x509.attr.AttributeCertificate) or other certificate (instance of iaik.cms.OtherCertificate); PKCS#6 extended certificates are obsolete and therefore not supported, e.g.:
 CertificateSet certSet = new CertificateSet();
 X509Certificate x509Cert = ...;
 certSet.addCertificateChoices(new CertificateChoices(x509Cert));
 AttributeCertificate attCert = ...;
 certSet.addCertificateChoices(new CertificateChoices(attCert));
 OtherCertificate otherCert = ...;
 certSet.addCertificateChoices(new CertificateChoices(otherCert));
 
Note that it might be more convenient to add the certificate immediately to the CertificateSet without prior wrapping it into a CertificateChoices object:
 CertificateSet certSet = new CertificateSet();
 X509Certificate x509Cert = ...;
 certSet.addCertificate(x509Cert);
 AttributeCertificate attCert = ...;
 certSet.addCertificate(attCert);
 OtherCertificate otherCert = ...;
 certSet.addCertificate(otherCert);
 
Using CertificateChoices maybe of more interest on the parsing side when getting the CertificateChoices from a CertificateSet to obtain their (original, parsed) encoding:
 CertificateSet certSet = ...;
 CertificateChoices[] certificateChoices = certSet.getCertificateChoices();
 for (int i = 0; i < certificateChoices.length; i++) {
   byte[] encodedCertificateChoices = certificateChoices[i].getEncoded();
 }
 

See Also:
CertificateSet

Field Summary
static int TYPE_ATTRIBUTE_CERTIFICATE_V1
          CertificateChoices type AttributeCertificateV1 (obsolete).
static int TYPE_ATTRIBUTE_CERTIFICATE_V2
          CertificateChoices type AttributeCertificateV2.
static int TYPE_CERTIFICATE
          CertificateChoices type Certificate.
static int TYPE_EXTENDED_CERTIFICATE
          CertificateChoices type ExtendedCertificate (obsolete; not supported).
static int TYPE_OTHER_CERTIFICATE
          CertificateChoices type OtherCertificate.
 
Constructor Summary
CertificateChoices(byte[] array)
          Creates n CertificateChoices from an DER encoded CertificateChoices.
CertificateChoices(java.security.cert.Certificate certificate)
          Creates a CertificateChoices for the given certificate.
CertificateChoices(java.io.InputStream is)
          Creates a CertificateChoices from an input stream that supplies a DER encoded CertificateChoices.
 
Method Summary
 void clearEncoded()
          Clears the CertificateChoices encoding.
 java.security.cert.Certificate getCertificate()
          Gets the included certificate.
 byte[] getEncoded()
          Gets the encoding of this CertificateChoices.
 int getType()
          Gets the type of the CertificateChoices.
 ASN1Object toASN1Object()
          Returns this CertificateChoices as ASN1Object.
 java.lang.String toString()
          Returns a string giving some information about this CertificateChoices object.
 void writeTo(java.io.OutputStream os)
          Writes this CertificateChoices DER encoded to the given output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE_CERTIFICATE

public static final int TYPE_CERTIFICATE
CertificateChoices type Certificate.

See Also:
Constant Field Values

TYPE_EXTENDED_CERTIFICATE

public static final int TYPE_EXTENDED_CERTIFICATE
CertificateChoices type ExtendedCertificate (obsolete; not supported).

See Also:
Constant Field Values

TYPE_ATTRIBUTE_CERTIFICATE_V1

public static final int TYPE_ATTRIBUTE_CERTIFICATE_V1
CertificateChoices type AttributeCertificateV1 (obsolete).

See Also:
Constant Field Values

TYPE_ATTRIBUTE_CERTIFICATE_V2

public static final int TYPE_ATTRIBUTE_CERTIFICATE_V2
CertificateChoices type AttributeCertificateV2.

See Also:
Constant Field Values

TYPE_OTHER_CERTIFICATE

public static final int TYPE_OTHER_CERTIFICATE
CertificateChoices type OtherCertificate.

See Also:
Constant Field Values
Constructor Detail

CertificateChoices

public CertificateChoices(java.security.cert.Certificate certificate)
Creates a CertificateChoices for the given certificate.

Parameters:
certificate - the certificate
Throws:
java.lang.IllegalArgumentException - if the supplied certificate is not a iaik.x509.X509Certificate or iaik.x509.attr.AttributeCertificate or iaik.cms.OtherCertificate object

CertificateChoices

public CertificateChoices(byte[] array)
                   throws CMSParsingException
Creates n CertificateChoices from an DER encoded CertificateChoices.

The DER encoded byte array either represents the DER encoded X.509 Certificate or an implicitly tagged AttributeCertificate or OtherCertificateFormat:

 CertificateChoices ::= CHOICE {
   certificate Certificate,                               -- see X.509
   extendedCertificate [0] IMPLICIT ExtendedCertificate,  -- Obsolete; see PKCS#6
   v1AttrCert [1] IMPLICIT AttributeCertificateV1,        -- Obsolete; see X.509-1997
   v2AttrCert [2] IMPLICIT AttributeCertificateV2,        -- see X509-2000
   other [3] IMPLICIT OtherCertificateFormat }
 
   OtherCertificateFormat ::= SEQUENCE {
     otherCertFormat OBJECT IDENTIFIER,
     otherCert ANY DEFINED BY otherCertFormat }
 

Parameters:
array - the DER encoded CertificateChoices as byte array
Throws:
CMSParsingException - if an parsing error occurs
CMSParsingException - if the CertificateChoices cannot be parsed

CertificateChoices

public CertificateChoices(java.io.InputStream is)
                   throws CMSParsingException,
                          java.io.IOException
Creates a CertificateChoices from an input stream that supplies a DER encoded CertificateChoices.

The DER encoding read from the stream either represents the DER encoded X.509 Certificate or an implicitly tagged AttributeCertificate or OtherCertificateFormat:

 CertificateChoices ::= CHOICE {
   certificate Certificate,                               -- see X.509
   extendedCertificate [0] IMPLICIT ExtendedCertificate,  -- Obsolete; see PKCS#6
   v1AttrCert [1] IMPLICIT AttributeCertificateV1,        -- Obsolete; see X.509-1997
   v2AttrCert [2] IMPLICIT AttributeCertificateV2,        -- see X509-2000
   other [3] IMPLICIT OtherCertificateFormat }
 
   OtherCertificateFormat ::= SEQUENCE {
     otherCertFormat OBJECT IDENTIFIER,
     otherCert ANY DEFINED BY otherCertFormat }
 

Parameters:
is - the InputStream from which to read the DER encoded CertificateChoices
Throws:
java.io.IOException - if an I/O error occurs during reading from the InputStream
CMSParsingException - if an error occurs during the parsing procedure; e.g. the encoding is invalid, or any of the included RevocationInfos is not supported
Method Detail

getCertificate

public java.security.cert.Certificate getCertificate()
Gets the included certificate.

Returns:
the certificate

getType

public int getType()
Gets the type of the CertificateChoices.

Returns:
the type, either TYPE_CERTIFICATE, TYPE_EXTENDED_CERTIFICATE, TYPE_ATTRIBUTE_CERTIFICATE_V1, TYPE_ATTRIBUTE_CERTIFICATE_V2, or TYPE_OTHER_CERTIFICATE

toASN1Object

public ASN1Object toASN1Object()
                        throws CodingException
Returns this CertificateChoices as ASN1Object.

CMS ( RFC 5652) defines the CertificateChoices object as choice of certificate, extended certificate, attribute certificate v1 or v2, or other certificate. The ASN1Object returned by this method either represents the ASN.1 X.509 Certificate or an implicitly tagged AttributeCertificate or OtherCertificateFormat:

 CertificateChoices ::= CHOICE {
 certificate Certificate,                               -- see X.509
 extendedCertificate [0] IMPLICIT ExtendedCertificate,  -- Obsolete; see PKCS#6
 v1AttrCert [1] IMPLICIT AttributeCertificateV1,        -- Obsolete; see X.509-1997
 v2AttrCert [2] IMPLICIT AttributeCertificateV2,        -- see X509-2000
 other [3] IMPLICIT OtherCertificateFormat }
 
 OtherCertificateFormat ::= SEQUENCE {
  otherCertFormat OBJECT IDENTIFIER,
  otherCert ANY DEFINED BY otherCertFormat }
 

Returns:
this CertificateChoices as ASN1Object
Throws:
CodingException - if an error occurs while building the ASN.1 structure

getEncoded

public byte[] getEncoded()
                  throws CodingException
Gets the encoding of this CertificateChoices.

Returns:
the encoding of this CertificateChoices
Throws:
java.lang.Exception - if an error occurs during encoding the CertificateChoices
CodingException

clearEncoded

public void clearEncoded()
Clears the CertificateChoices encoding.
This method maybe called to clear the parsed encoding so that any following call to toASN1Object() or getEncoded() will build the internal ASN.1 structure anew. If this method is called but the internal ASN.1 structure has not been built so far, the ASN.1 parsing is done before clearing the encoding. For that reason this method may throw a CMSParsingException.


writeTo

public void writeTo(java.io.OutputStream os)
             throws java.io.IOException
Writes this CertificateChoices DER encoded to the given output stream.

Parameters:
os - the output stream to which this CertificateChoices shall be encoded
Throws:
java.io.IOException - if an error occurs when writing to the stream

toString

public java.lang.String toString()
Returns a string giving some information about this CertificateChoices object.

Overrides:
toString in class java.lang.Object
Returns:
the string representation

This Javadoc may contain text parts from text parts from IETF Internet Standard specifications (see copyright note).

IAIK-CMS 6.0, (c) 2002 IAIK, (c) 2003, 2023 SIC