📄 x500distinguishedname.java
字号:
} } return true; } public String toString() { if (fixed && stringRep != null) return stringRep; StringBuffer str = new StringBuffer(); for (Iterator it = components.iterator(); it.hasNext(); ) { Map m = (Map) it.next(); for (Iterator it2 = m.entrySet().iterator(); it2.hasNext(); ) { Map.Entry entry = (Map.Entry) it2.next(); OID oid = (OID) entry.getKey(); String value = (String) entry.getValue(); if (oid.equals(CN)) str.append("CN"); else if (oid.equals(C)) str.append("C"); else if (oid.equals(L)) str.append("L"); else if (oid.equals(ST)) str.append("ST"); else if (oid.equals(STREET)) str.append("STREET"); else if (oid.equals(O)) str.append("O"); else if (oid.equals(OU)) str.append("OU"); else if (oid.equals(T)) str.append("T"); else if (oid.equals(DNQ)) str.append("DNQ"); else if (oid.equals(NAME)) str.append("NAME"); else str.append(oid.toString()); str.append('='); str.append(value); if (it2.hasNext()) str.append("+"); } if (it.hasNext()) str.append(','); } return (stringRep = str.toString()); } public byte[] getDer() { if (fixed && encoded != null) return (byte[]) encoded.clone(); ArrayList name = new ArrayList(components.size()); for (Iterator it = components.iterator(); it.hasNext(); ) { Map m = (Map) it.next(); if (m.isEmpty()) continue; Set rdn = new HashSet(); for (Iterator it2 = m.entrySet().iterator(); it2.hasNext(); ) { Map.Entry e = (Map.Entry) it.next(); ArrayList atav = new ArrayList(2); atav.add(new DERValue(DER.OBJECT_IDENTIFIER, e.getKey())); atav.add(new DERValue(DER.UTF8_STRING, e.getValue())); rdn.add(new DERValue(DER.SEQUENCE|DER.CONSTRUCTED, atav)); } name.add(new DERValue(DER.SET|DER.CONSTRUCTED, rdn)); } DERValue val = new DERValue(DER.SEQUENCE|DER.CONSTRUCTED, name); return (byte[]) (encoded = val.getEncoded()).clone(); } // Own methods. // ------------------------------------------------------------------------- private int sep; private void parseString(String str) throws IOException { Reader in = new StringReader(str); while (true) { String key = readAttributeType(in); if (key == null) break; String value = readAttributeValue(in); putComponent(key, value); if (sep == ',') newRelativeDistinguishedName(); } setUnmodifiable(); } private String readAttributeType(Reader in) throws IOException { StringBuffer buf = new StringBuffer(); int ch; while ((ch = in.read()) != '=') { if (ch == -1) { if (buf.length() > 0) throw new EOFException(); return null; } if (ch > 127) throw new IOException("Invalid char: " + (char) ch); if (Character.isLetterOrDigit((char) ch) || ch == '-' || ch == '.') buf.append((char) ch); else throw new IOException("Invalid char: " + (char) ch); } return buf.toString(); } private String readAttributeValue(Reader in) throws IOException { StringBuffer buf = new StringBuffer(); int ch = in.read(); if (ch == '#') { while (true) { ch = in.read(); if (('a' <= ch && ch <= 'f') || ('A' <= ch && ch <= 'F') || Character.isDigit((char) ch)) buf.append((char) ch); else if (ch == '+' || ch == ',') { sep = ch; String hex = buf.toString(); return new String(Util.toByteArray(hex)); } else throw new IOException("illegal character: " + (char) ch); } } else if (ch == '"') { while (true) { ch = in.read(); if (ch == '"') break; else if (ch == '\\') { ch = in.read(); if (ch == -1) throw new EOFException(); if (('a' <= ch && ch <= 'f') || ('A' <= ch && ch <= 'F') || Character.isDigit((char) ch)) { int i = Character.digit((char) ch, 16) << 4; ch = in.read(); if (!(('a' <= ch && ch <= 'f') || ('A' <= ch && ch <= 'F') || Character.isDigit((char) ch))) throw new IOException("illegal hex char"); i |= Character.digit((char) ch, 16); buf.append((char) i); } else buf.append((char) ch); } else buf.append((char) ch); } sep = in.read(); if (sep != '+' || sep != ',') throw new IOException("illegal character: " + (char) ch); return buf.toString(); } else { while (true) { switch (ch) { case '+': case ',': sep = ch; return buf.toString(); case '\\': ch = in.read(); if (ch == -1) throw new EOFException(); if (('a' <= ch && ch <= 'f') || ('A' <= ch && ch <= 'F') || Character.isDigit((char) ch)) { int i = Character.digit((char) ch, 16) << 4; ch = in.read(); if (!(('a' <= ch && ch <= 'f') || ('A' <= ch && ch <= 'F') || Character.isDigit((char) ch))) throw new IOException("illegal hex char"); i |= Character.digit((char) ch, 16); buf.append((char) i); } else buf.append((char) ch); break; case '=': case '<': case '>': case '#': case ';': throw new IOException("illegal character: " + (char) ch); case -1: throw new EOFException(); default: buf.append((char) ch); } } } } private void parseDer(DERReader der) throws IOException { DERValue name = der.read(); if (!name.isConstructed()) throw new IOException("malformed Name"); encoded = name.getEncoded(); int len = 0; while (len < name.getLength()) { DERValue rdn = der.read(); if (!rdn.isConstructed()) throw new IOException("badly formed RDNSequence"); int len2 = 0; while (len2 < rdn.getLength()) { DERValue atav = der.read(); if (!atav.isConstructed()) throw new IOException("badly formed AttributeTypeAndValue"); DERValue val = der.read(); if (val.getTag() != DER.OBJECT_IDENTIFIER) throw new IOException("badly formed AttributeTypeAndValue"); OID oid = (OID) val.getValue(); val = der.read(); if (!(val.getValue() instanceof String)) throw new IOException("badly formed AttributeTypeAndValue"); String value = (String) val.getValue(); putComponent(oid, value); len2 += atav.getEncodedLength(); } len += rdn.getEncodedLength(); if (len < name.getLength()) newRelativeDistinguishedName(); } setUnmodifiable(); } private static String compressWS(String str) { StringBuffer buf = new StringBuffer(); char lastChar = 0; for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (Character.isWhitespace(c)) { if (!Character.isWhitespace(lastChar)) buf.append(' '); } else buf.append(c); lastChar = c; } return buf.toString().trim(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -