use of org.bouncycastle.asn1.ASN1PrintableString in project keystore-explorer by kaikramer.
the class X509Ext method getDeclarationOfMajorityStringValue.
private static String getDeclarationOfMajorityStringValue(byte[] octets) {
// @formatter:off
/*
DeclarationOfMajoritySyntax ::= CHOICE
{
notYoungerThan [0] IMPLICIT INTEGER,
fullAgeAtCountry [1] IMPLICIT SEQUENCE {
fullAge BOOLEAN DEFAULT TRUE,
country PrintableString (SIZE(2))
},
dateOfBirth [2] IMPLICIT GeneralizedTime
}
*/
// @formatter:on
StringBuilder sb = new StringBuilder();
DeclarationOfMajority declarationOfMajority = DeclarationOfMajority.getInstance(octets);
int notYoungerThan = declarationOfMajority.notYoungerThan();
ASN1Sequence fullAgeAtCountry = declarationOfMajority.fullAgeAtCountry();
ASN1GeneralizedTime dateOfBirth = declarationOfMajority.getDateOfBirth();
if (notYoungerThan != -1) {
sb.append(MessageFormat.format(res.getString("DeclarationOfMajority.notYoungerThan"), notYoungerThan));
sb.append(NEWLINE);
}
if (fullAgeAtCountry != null) {
ASN1Boolean fullAge = ASN1Boolean.getInstance(fullAgeAtCountry.getObjectAt(0));
ASN1PrintableString country = ASN1PrintableString.getInstance(fullAgeAtCountry.getObjectAt(1));
sb.append(MessageFormat.format(res.getString("DeclarationOfMajority.fullAgeAtCountry"), country.toString(), fullAge.toString()));
sb.append(NEWLINE);
}
if (dateOfBirth != null) {
sb.append(MessageFormat.format(res.getString("DeclarationOfMajority.dateOfBirth"), dateOfBirth));
sb.append(NEWLINE);
}
return sb.toString();
}
use of org.bouncycastle.asn1.ASN1PrintableString in project LinLong-Java by zhenwei1108.
the class ASN1Dump method _dumpAsString.
/**
* dump a DER object as a formatted string with indentation
*
* @param obj the ASN1Primitive to be dumped out.
*/
static void _dumpAsString(String indent, boolean verbose, ASN1Primitive obj, StringBuffer buf) {
String nl = Strings.lineSeparator();
if (obj instanceof ASN1Null) {
buf.append(indent);
buf.append("NULL");
buf.append(nl);
} else if (obj instanceof ASN1Sequence) {
buf.append(indent);
if (obj instanceof BERSequence) {
buf.append("BER Sequence");
} else if (obj instanceof DERSequence) {
buf.append("DER Sequence");
} else {
buf.append("Sequence");
}
buf.append(nl);
ASN1Sequence sequence = (ASN1Sequence) obj;
String elementsIndent = indent + TAB;
for (int i = 0, count = sequence.size(); i < count; ++i) {
_dumpAsString(elementsIndent, verbose, sequence.getObjectAt(i).toASN1Primitive(), buf);
}
} else if (obj instanceof ASN1Set) {
buf.append(indent);
if (obj instanceof BERSet) {
buf.append("BER Set");
} else if (obj instanceof DERSet) {
buf.append("DER Set");
} else {
buf.append("Set");
}
buf.append(nl);
ASN1Set set = (ASN1Set) obj;
String elementsIndent = indent + TAB;
for (int i = 0, count = set.size(); i < count; ++i) {
_dumpAsString(elementsIndent, verbose, set.getObjectAt(i).toASN1Primitive(), buf);
}
} else if (obj instanceof ASN1ApplicationSpecific) {
_dumpAsString(indent, verbose, ((ASN1ApplicationSpecific) obj).getTaggedObject(), buf);
} else if (obj instanceof ASN1TaggedObject) {
buf.append(indent);
if (obj instanceof BERTaggedObject) {
buf.append("BER Tagged ");
} else if (obj instanceof DERTaggedObject) {
buf.append("DER Tagged ");
} else {
buf.append("Tagged ");
}
ASN1TaggedObject o = (ASN1TaggedObject) obj;
buf.append(ASN1Util.getTagText(o));
if (!o.isExplicit()) {
buf.append(" IMPLICIT ");
}
buf.append(nl);
String baseIndent = indent + TAB;
_dumpAsString(baseIndent, verbose, o.getBaseObject().toASN1Primitive(), buf);
} else if (obj instanceof ASN1OctetString) {
ASN1OctetString oct = (ASN1OctetString) obj;
if (obj instanceof BEROctetString) {
buf.append(indent + "BER Constructed Octet String" + "[" + oct.getOctets().length + "] ");
} else {
buf.append(indent + "DER Octet String" + "[" + oct.getOctets().length + "] ");
}
if (verbose) {
buf.append(dumpBinaryDataAsString(indent, oct.getOctets()));
} else {
buf.append(nl);
}
} else if (obj instanceof ASN1ObjectIdentifier) {
buf.append(indent + "ObjectIdentifier(" + ((ASN1ObjectIdentifier) obj).getId() + ")" + nl);
} else if (obj instanceof ASN1RelativeOID) {
buf.append(indent + "RelativeOID(" + ((ASN1RelativeOID) obj).getId() + ")" + nl);
} else if (obj instanceof ASN1Boolean) {
buf.append(indent + "Boolean(" + ((ASN1Boolean) obj).isTrue() + ")" + nl);
} else if (obj instanceof ASN1Integer) {
buf.append(indent + "Integer(" + ((ASN1Integer) obj).getValue() + ")" + nl);
} else if (obj instanceof ASN1BitString) {
ASN1BitString bitString = (ASN1BitString) obj;
byte[] bytes = bitString.getBytes();
int padBits = bitString.getPadBits();
if (bitString instanceof DERBitString) {
buf.append(indent + "DER Bit String" + "[" + bytes.length + ", " + padBits + "] ");
} else if (bitString instanceof DLBitString) {
buf.append(indent + "DL Bit String" + "[" + bytes.length + ", " + padBits + "] ");
} else {
buf.append(indent + "BER Bit String" + "[" + bytes.length + ", " + padBits + "] ");
}
if (verbose) {
buf.append(dumpBinaryDataAsString(indent, bytes));
} else {
buf.append(nl);
}
} else if (obj instanceof ASN1IA5String) {
buf.append(indent + "IA5String(" + ((ASN1IA5String) obj).getString() + ") " + nl);
} else if (obj instanceof ASN1UTF8String) {
buf.append(indent + "UTF8String(" + ((ASN1UTF8String) obj).getString() + ") " + nl);
} else if (obj instanceof ASN1NumericString) {
buf.append(indent + "NumericString(" + ((ASN1NumericString) obj).getString() + ") " + nl);
} else if (obj instanceof ASN1PrintableString) {
buf.append(indent + "PrintableString(" + ((ASN1PrintableString) obj).getString() + ") " + nl);
} else if (obj instanceof ASN1VisibleString) {
buf.append(indent + "VisibleString(" + ((ASN1VisibleString) obj).getString() + ") " + nl);
} else if (obj instanceof ASN1BMPString) {
buf.append(indent + "BMPString(" + ((ASN1BMPString) obj).getString() + ") " + nl);
} else if (obj instanceof ASN1T61String) {
buf.append(indent + "T61String(" + ((ASN1T61String) obj).getString() + ") " + nl);
} else if (obj instanceof ASN1GraphicString) {
buf.append(indent + "GraphicString(" + ((ASN1GraphicString) obj).getString() + ") " + nl);
} else if (obj instanceof ASN1VideotexString) {
buf.append(indent + "VideotexString(" + ((ASN1VideotexString) obj).getString() + ") " + nl);
} else if (obj instanceof ASN1UTCTime) {
buf.append(indent + "UTCTime(" + ((ASN1UTCTime) obj).getTime() + ") " + nl);
} else if (obj instanceof ASN1GeneralizedTime) {
buf.append(indent + "GeneralizedTime(" + ((ASN1GeneralizedTime) obj).getTime() + ") " + nl);
} else if (obj instanceof ASN1Enumerated) {
ASN1Enumerated en = (ASN1Enumerated) obj;
buf.append(indent + "DER Enumerated(" + en.getValue() + ")" + nl);
} else if (obj instanceof ASN1ObjectDescriptor) {
ASN1ObjectDescriptor od = (ASN1ObjectDescriptor) obj;
buf.append(indent + "ObjectDescriptor(" + od.getBaseGraphicString().getString() + ") " + nl);
} else if (obj instanceof ASN1External) {
ASN1External ext = (ASN1External) obj;
buf.append(indent + "External " + nl);
String tab = indent + TAB;
if (ext.getDirectReference() != null) {
buf.append(tab + "Direct Reference: " + ext.getDirectReference().getId() + nl);
}
if (ext.getIndirectReference() != null) {
buf.append(tab + "Indirect Reference: " + ext.getIndirectReference().toString() + nl);
}
if (ext.getDataValueDescriptor() != null) {
_dumpAsString(tab, verbose, ext.getDataValueDescriptor(), buf);
}
buf.append(tab + "Encoding: " + ext.getEncoding() + nl);
_dumpAsString(tab, verbose, ext.getExternalContent(), buf);
} else {
buf.append(indent + obj.toString() + nl);
}
}
use of org.bouncycastle.asn1.ASN1PrintableString in project openkeystore by cyberphone.
the class RelativeDistinguishedName method add.
private void add(String nameOrOID, String value) throws IOException {
if (nameOrOID.indexOf('.') < 0) {
String t = name2OID(nameOrOID);
if (t == null) {
StringBuilder s = new StringBuilder();
s.append("Unknown attribute '").append(nameOrOID).append("', select among the following:");
Enumeration<String> e = name2OID.keys();
while (e.hasMoreElements()) {
String key = e.nextElement();
s.append("\n ").append(key).append(" [").append(name2OID.get(key)).append("]");
}
throw new IOException(s.toString());
}
nameOrOID = t;
}
// e-mail and dc as IA5String, all others as Printable or UTF-8
// (if contatining non-printable characters).
add(nameOrOID, (nameOrOID.equals("1.2.840.113549.1.9.1") || nameOrOID.equals("0.9.2342.19200300.100.1.25")) ? (ASN1String) new ASN1IA5String(value) : ASN1PrintableString.isPrintableString(value) ? (ASN1String) new ASN1PrintableString(value) : (ASN1String) new ASN1UTF8String(value));
}
use of org.bouncycastle.asn1.ASN1PrintableString in project SpringRemote by HaleyWang.
the class AttributeTypeAndValue method valueAsString.
private String valueAsString() {
ASN1Object vo = value.getValue();
String vs = "<unknown>";
if (vo instanceof DirectoryString) {
vs = ((DirectoryString) vo).getString();
} else if (vo instanceof ASN1CharString) {
vs = ((ASN1CharString) vo).getValue();
} else if (vo instanceof ASN1PrintableString) {
vs = ((ASN1PrintableString) vo).getValue();
} else if (vo instanceof ASN1BitString) {
vs = ((ASN1BitString) vo).toPrintableString();
}
return vs;
}
use of org.bouncycastle.asn1.ASN1PrintableString in project LinLong-Java by zhenwei1108.
the class Iso4217CurrencyCode method getInstance.
public static Iso4217CurrencyCode getInstance(Object obj) {
if (obj == null || obj instanceof Iso4217CurrencyCode) {
return (Iso4217CurrencyCode) obj;
}
if (obj instanceof ASN1Integer) {
ASN1Integer numericobj = ASN1Integer.getInstance(obj);
int numeric = numericobj.intValueExact();
return new Iso4217CurrencyCode(numeric);
} else if (obj instanceof ASN1PrintableString) {
ASN1PrintableString alphabetic = ASN1PrintableString.getInstance(obj);
return new Iso4217CurrencyCode(alphabetic.getString());
}
throw new IllegalArgumentException("unknown object in getInstance");
}
Aggregations