use of org.mozilla.jss.asn1.Tag in project jss by dogtagpki.
the class JSSUtil method decode.
public static String decode(byte tag, byte[] bytes) throws Exception {
ASN1Template template;
switch(tag) {
case DerValue.tag_BMPString:
template = new BMPString.Template();
break;
case DerValue.tag_IA5String:
template = new IA5String.Template();
break;
case DerValue.tag_PrintableString:
template = new PrintableString.Template();
break;
case DerValue.tag_T61String:
template = new TeletexString.Template();
break;
case DerValue.tag_UniversalString:
template = new UniversalString.Template();
break;
case DerValue.tag_UTF8String:
template = new UTF8String.Template();
break;
default:
throw new Exception("Unsupported tag: " + tag);
}
ASN1Value asnValue = ASN1Util.decode(new Tag(Tag.UNIVERSAL, tag), template, bytes);
if (asnValue == null) {
throw new Exception("Cannot decode the given bytes.");
}
return asnValue.toString();
}
use of org.mozilla.jss.asn1.Tag in project jss by dogtagpki.
the class CertReqMsg method encode.
/**
* Encodes this <i>CertReqMsg</i> to the given OutputStream using
* DER encoding, with the given implicit tag.
*/
@Override
public void encode(Tag implicit, OutputStream ostream) throws IOException {
// Assert.notYetImplemented("CertReqMsg encoding");
SEQUENCE sequence = new SEQUENCE();
sequence.addElement(certReq);
if (pop != null)
sequence.addElement(pop);
if (regInfo != null)
sequence.addElement(regInfo);
sequence.encode(implicit, ostream);
}
use of org.mozilla.jss.asn1.Tag 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.Tag in project jss by dogtagpki.
the class AVA method encode.
@Override
public void encode(Tag implicit, OutputStream ostream) throws IOException {
SEQUENCE seq = new SEQUENCE();
seq.addElement(oid);
seq.addElement(value);
seq.encode(implicit, ostream);
}
use of org.mozilla.jss.asn1.Tag in project jss by dogtagpki.
the class Attribute method encode.
@Override
public void encode(Tag implicit, OutputStream ostream) throws IOException {
SEQUENCE seq = new SEQUENCE();
seq.addElement(type);
seq.addElement(values);
seq.encode(implicit, ostream);
}
Aggregations