use of org.mozilla.jss.asn1.EXPLICIT in project jss by dogtagpki.
the class CertTemplate method encode.
@Override
public void encode(Tag t, OutputStream ostream) throws IOException {
SEQUENCE seq = new SEQUENCE();
seq.addElement(Tag.get(0), version);
seq.addElement(Tag.get(1), serialNumber);
seq.addElement(Tag.get(2), signingAlg);
if (issuer != null) {
// issuer is a CHOICE, so it must be EXPLICITly tagged
seq.addElement(new EXPLICIT(Tag.get(3), issuer));
}
if (notBefore != null || notAfter != null) {
SEQUENCE optionalVal = new SEQUENCE();
// notBefore & notAfter are CHOICES, so must be EXPLICITly tagged
if (notBefore != null) {
optionalVal.addElement(new EXPLICIT(Tag.get(0), dateToASN1(notBefore)));
}
if (notAfter != null) {
optionalVal.addElement(new EXPLICIT(Tag.get(1), dateToASN1(notAfter)));
}
seq.addElement(Tag.get(4), optionalVal);
}
if (subject != null) {
// subject is a CHOICE, so it must be EXPLICITly tagged
seq.addElement(new EXPLICIT(Tag.get(5), subject));
}
seq.addElement(Tag.get(6), publicKey);
seq.addElement(Tag.get(7), issuerUID);
seq.addElement(Tag.get(8), subjectUID);
seq.addElement(Tag.get(9), extensions);
seq.encode(t, ostream);
}
use of org.mozilla.jss.asn1.EXPLICIT in project jss by dogtagpki.
the class CertificateInfo method encode.
@Override
public void encode(Tag implicitTag, OutputStream ostream) throws IOException {
SEQUENCE seq = new SEQUENCE();
if (version != v1) {
// v1 is the default
seq.addElement(new EXPLICIT(new Tag(0), new INTEGER(version.getNumber())));
}
seq.addElement(serialNumber);
seq.addElement(signatureAlgId);
seq.addElement(issuer);
SEQUENCE validity = new SEQUENCE();
validity.addElement(encodeValidityDate(notBefore));
validity.addElement(encodeValidityDate(notAfter));
seq.addElement(validity);
seq.addElement(subject);
seq.addElement(subjectPublicKeyInfo);
if (issuerUniqueIdentifier != null) {
seq.addElement(new Tag(1), issuerUniqueIdentifier);
}
if (subjectUniqueIdentifier != null) {
seq.addElement(new Tag(2), subjectUniqueIdentifier);
}
if (extensions.size() > 0) {
seq.addElement(new EXPLICIT(new Tag(3), extensions));
}
seq.encode(implicitTag, ostream);
}
use of org.mozilla.jss.asn1.EXPLICIT in project jss by dogtagpki.
the class SafeBag method encode.
@Override
public void encode(Tag implicitTag, OutputStream ostream) throws IOException {
SEQUENCE seq = new SEQUENCE();
seq.addElement(bagType);
seq.addElement(new EXPLICIT(new Tag(0), bagContent));
if (bagAttributes != null) {
seq.addElement(bagAttributes);
}
seq.encode(implicitTag, ostream);
}
use of org.mozilla.jss.asn1.EXPLICIT in project jss by dogtagpki.
the class CRLDistributionPoint method encode.
@Override
public void encode(Tag implicitTag, OutputStream ostream) throws IOException {
SEQUENCE seq = new SEQUENCE();
DerOutputStream derOut;
try {
// is a CHOICE, the [0] tag is forced to be EXPLICIT.
if (fullName != null) {
EXPLICIT distPoint = new EXPLICIT(Tag.get(0), fullNameEncoding);
seq.addElement(distPoint);
} else if (relativeName != null) {
derOut = new DerOutputStream();
relativeName.encode(derOut);
ANY rn = new ANY(derOut.toByteArray());
EXPLICIT raw = new EXPLICIT(Tag.get(1), rn);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
raw.encode(bos);
ANY distPointName = new ANY(bos.toByteArray());
EXPLICIT distPoint = new EXPLICIT(Tag.get(0), distPointName);
seq.addElement(distPoint);
}
// Encodes the ReasonFlags.
if (reasons != null) {
derOut = new DerOutputStream();
derOut.putUnalignedBitString(reasons);
ANY raw = new ANY(derOut.toByteArray());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
raw.encodeWithAlternateTag(Tag.get(1), bos);
ANY reasonEncoding = new ANY(bos.toByteArray());
seq.addElement(Tag.get(1), reasonEncoding);
}
// Encodes the CRLIssuer
if (CRLIssuer != null) {
seq.addElement(Tag.get(2), CRLIssuerEncoding);
}
seq.encode(implicitTag, ostream);
} catch (InvalidBERException e) {
// the Sun encoding classes
throw new IOException(e.toString());
}
}
use of org.mozilla.jss.asn1.EXPLICIT in project jss by dogtagpki.
the class IssuingDistributionPoint method encode.
@Override
public void encode(Tag implicitTag, OutputStream ostream) throws IOException {
SEQUENCE seq = new SEQUENCE();
DerOutputStream derOut;
try {
// is a CHOICE, the [0] tag is forced to be EXPLICIT.
if (fullName != null) {
EXPLICIT distPoint = new EXPLICIT(Tag.get(0), fullNameEncoding);
seq.addElement(distPoint);
} else if (relativeName != null) {
derOut = new DerOutputStream();
relativeName.encode(derOut);
ANY raw = new ANY(derOut.toByteArray());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
raw.encodeWithAlternateTag(Tag.get(1), bos);
ANY distPointName = new ANY(bos.toByteArray());
EXPLICIT distPoint = new EXPLICIT(Tag.get(0), distPointName);
seq.addElement(distPoint);
}
if (onlyContainsUserCerts != false) {
seq.addElement(Tag.get(1), new BOOLEAN(true));
}
if (onlyContainsCACerts != false) {
seq.addElement(Tag.get(2), new BOOLEAN(true));
}
// Encodes the ReasonFlags.
if (onlySomeReasons != null) {
derOut = new DerOutputStream();
derOut.putUnalignedBitString(onlySomeReasons);
ANY raw = new ANY(derOut.toByteArray());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
raw.encodeWithAlternateTag(Tag.get(3), bos);
ANY reasonEncoding = new ANY(bos.toByteArray());
seq.addElement(reasonEncoding);
}
if (indirectCRL != false) {
seq.addElement(Tag.get(4), new BOOLEAN(true));
}
seq.encode(implicitTag, ostream);
} catch (InvalidBERException e) {
// the Sun encoding classes
throw new IOException(e.toString());
}
}
Aggregations