Search in sources :

Example 1 with ASN1Template

use of org.mozilla.jss.asn1.ASN1Template 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();
}
Also used : ASN1Template(org.mozilla.jss.asn1.ASN1Template) UTF8String(org.mozilla.jss.asn1.UTF8String) PrintableString(org.mozilla.jss.asn1.PrintableString) TeletexString(org.mozilla.jss.asn1.TeletexString) ASN1Value(org.mozilla.jss.asn1.ASN1Value) IA5String(org.mozilla.jss.asn1.IA5String) Tag(org.mozilla.jss.asn1.Tag) UniversalString(org.mozilla.jss.asn1.UniversalString) BMPString(org.mozilla.jss.asn1.BMPString)

Aggregations

ASN1Template (org.mozilla.jss.asn1.ASN1Template)1 ASN1Value (org.mozilla.jss.asn1.ASN1Value)1 BMPString (org.mozilla.jss.asn1.BMPString)1 IA5String (org.mozilla.jss.asn1.IA5String)1 PrintableString (org.mozilla.jss.asn1.PrintableString)1 Tag (org.mozilla.jss.asn1.Tag)1 TeletexString (org.mozilla.jss.asn1.TeletexString)1 UTF8String (org.mozilla.jss.asn1.UTF8String)1 UniversalString (org.mozilla.jss.asn1.UniversalString)1