use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.
the class SignerInfo method derEncode.
/**
* DER encode this object onto an output stream.
* Implements the <code>DerEncoder</code> interface.
*
* @param out
* the output stream on which to write the DER encoding.
*
* @exception IOException on encoding error.
*/
@Override
public void derEncode(OutputStream out) throws IOException {
try (DerOutputStream tmp = new DerOutputStream()) {
DerOutputStream seq = new DerOutputStream();
seq.putInteger(version);
DerOutputStream issuerAndSerialNumber = new DerOutputStream();
issuerName.encode(issuerAndSerialNumber);
issuerAndSerialNumber.putInteger(certificateSerialNumber);
seq.write(DerValue.tag_Sequence, issuerAndSerialNumber);
digestAlgorithmId.encode(seq);
// encode authenticated attributes if there are any
if (authenticatedAttributes != null)
authenticatedAttributes.encode((byte) 0xA0, seq);
digestEncryptionAlgorithmId.encode(seq);
seq.putOctetString(encryptedDigest);
// encode unauthenticated attributes if there are any
if (unauthenticatedAttributes != null)
unauthenticatedAttributes.encode((byte) 0xA1, seq);
tmp.write(DerValue.tag_Sequence, seq);
out.write(tmp.toByteArray());
}
}
use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.
the class SubjectInfoAccessExtension method encodeThis.
private void encodeThis() throws IOException {
try (DerOutputStream seq = new DerOutputStream();
DerOutputStream tmp = new DerOutputStream()) {
for (int i = 0; i < mDesc.size(); i++) {
DerOutputStream tmp0 = new DerOutputStream();
AccessDescription ad = mDesc.elementAt(i);
tmp0.putOID(ad.getMethod());
ad.getLocation().encode(tmp0);
tmp.write(DerValue.tag_Sequence, tmp0);
}
seq.write(DerValue.tag_Sequence, tmp);
this.extensionValue = seq.toByteArray();
}
}
use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.
the class SubjectInfoAccessExtension 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) {
encodeThis();
}
super.encode(tmp);
out.write(tmp.toByteArray());
}
use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.
the class PKCS10Attribute method encode.
/**
* Write the output to the DerOutputStream.
*
* @param out the OutputStream to write the attribute to.
* @exception CertificateException on certificate encoding errors.
* @exception IOException on encoding errors.
*/
public void encode(OutputStream out) throws CertificateException, IOException {
try (DerOutputStream tmp = new DerOutputStream()) {
// Encode the attribute value
DerOutputStream outAttrValue = new DerOutputStream();
attributeValue.encode(outAttrValue);
// Wrap the encoded attribute value into a SET
DerValue outAttrValueSet = new DerValue(DerValue.tag_Set, outAttrValue.toByteArray());
// Create the attribute
DerOutputStream outAttr = new DerOutputStream();
outAttr.putOID(attributeId);
outAttr.putDerValue(outAttrValueSet);
// Wrap the OID and the set of attribute values into a SEQUENCE
tmp.write(DerValue.tag_Sequence, outAttr);
// write the results to out
out.write(tmp.toByteArray());
}
}
use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.
the class PKCS10Attributes method derEncode.
/**
* Encode the attributes in DER form to the stream.
* Implements the <code>DerEncoder</code> interface.
*
* @param out the OutputStream to marshal the contents to.
* @exception IOException on encoding errors.
*/
@Override
public void derEncode(OutputStream out) throws IOException {
try (DerOutputStream attrOut = new DerOutputStream()) {
// first copy the elements into an array
PKCS10Attribute[] attribs = new PKCS10Attribute[size()];
copyInto(attribs);
attrOut.putOrderedSetOf(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0), attribs);
out.write(attrOut.toByteArray());
} catch (IOException e) {
throw e;
}
}
Aggregations