Search in sources :

Example 51 with DerOutputStream

use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.

the class CertificateIssuerUniqueIdentity method encode.

/**
 * Encode the identity in DER form to the stream.
 *
 * @param out the DerOutputStream to marshal the contents to.
 * @exception IOException on errors.
 */
@Override
public void encode(OutputStream out) throws IOException {
    DerOutputStream tmp = new DerOutputStream();
    id.encode(tmp, DerValue.createTag(DerValue.TAG_CONTEXT, false, (byte) 1));
    out.write(tmp.toByteArray());
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream)

Example 52 with DerOutputStream

use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.

the class HoldInstructionExtension method encodeThis.

// Encode this extension value
private void encodeThis() throws IOException {
    if (holdInstructionCodeOID == null)
        throw new IOException("Unintialized hold instruction extension");
    try (DerOutputStream os = new DerOutputStream()) {
        os.putOID(holdInstructionCodeOID);
        this.extensionValue = os.toByteArray();
    }
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) IOException(java.io.IOException)

Example 53 with DerOutputStream

use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.

the class GeneralNames method encode.

/**
 * Write the extension to the DerOutputStream.
 *
 * @param out the DerOutputStream to write the extension to.
 * @exception GeneralNamesException on encoding error.
 * @exception IOException on error.
 */
public void encode(DerOutputStream out) throws IOException, GeneralNamesException {
    if (size() == 0) {
        return;
    }
    Enumeration<GeneralNameInterface> names = elements();
    DerOutputStream temp = new DerOutputStream();
    while (names.hasMoreElements()) {
        Object obj = names.nextElement();
        if (!(obj instanceof GeneralNameInterface)) {
            throw new GeneralNamesException("Element in GeneralNames " + "not of type GeneralName.");
        }
        GeneralNameInterface intf = (GeneralNameInterface) obj;
        if (obj instanceof GeneralName) {
            intf.encode(temp);
        } else {
            DerOutputStream gname = new DerOutputStream();
            intf.encode(gname);
            int nameType = intf.getType();
            // constructed form
            if (nameType == GeneralNameInterface.NAME_ANY || nameType == GeneralNameInterface.NAME_X400 || nameType == GeneralNameInterface.NAME_EDI) {
                temp.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) nameType), gname);
            } else if (nameType == GeneralNameInterface.NAME_DIRECTORY) {
                // EXPLICIT tag because directoryName is a CHOICE
                temp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) nameType), gname);
            } else
                // primitive form
                temp.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT, false, (byte) nameType), gname);
        }
    }
    out.write(DerValue.tag_Sequence, temp);
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream)

Example 54 with DerOutputStream

use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.

the class KeyUsageExtension method encode.

/**
 * Write the extension to the DerOutputStream.
 *
 * @param out the DerOutputStream to write the extension to.
 * @exception IOException on encoding errors.
 */
@Override
public void encode(OutputStream out) throws IOException {
    DerOutputStream tmp = new DerOutputStream();
    if (this.extensionValue == null) {
        this.extensionId = PKIXExtensions.KeyUsage_Id;
        this.critical = true;
        encodeThis();
    }
    super.encode(tmp);
    out.write(tmp.toByteArray());
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream)

Example 55 with DerOutputStream

use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.

the class NameConstraintsExtension method encode.

/**
 * Write the extension to the OutputStream.
 *
 * @param out the OutputStream to write the extension to.
 * @exception IOException on encoding errors.
 */
@Override
public void encode(OutputStream out) throws IOException {
    DerOutputStream tmp = new DerOutputStream();
    if (this.extensionValue == null) {
        this.extensionId = PKIXExtensions.NameConstraints_Id;
        encodeThis();
    }
    super.encode(tmp);
    out.write(tmp.toByteArray());
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream)

Aggregations

DerOutputStream (org.mozilla.jss.netscape.security.util.DerOutputStream)141 IOException (java.io.IOException)37 BigInt (org.mozilla.jss.netscape.security.util.BigInt)13 DerValue (org.mozilla.jss.netscape.security.util.DerValue)8 ObjectIdentifier (org.mozilla.jss.netscape.security.util.ObjectIdentifier)8 CRLException (java.security.cert.CRLException)7 CertificateException (java.security.cert.CertificateException)7 InvalidKeyException (java.security.InvalidKeyException)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 ANY (org.mozilla.jss.asn1.ANY)5 InvalidBERException (org.mozilla.jss.asn1.InvalidBERException)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 KeyFactory (java.security.KeyFactory)3 SignatureException (java.security.SignatureException)3 CertificateEncodingException (java.security.cert.CertificateEncodingException)3 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)3 NoSuchProviderException (java.security.NoSuchProviderException)2 Provider (java.security.Provider)2 PublicKey (java.security.PublicKey)2