/* * Get the friendly type corresponding to the given OID * (decimal-dotted representation). If no such type is known, * then the OID string is returned. */ public static string GetFriendlyType(string oid) { string ft; if (OID_TO_FT.TryGetValue(oid, out ft)) { return(ft); } return(oid); }
/* * Convert this element to a string. This uses RFC 4514 rules. */ public override string ToString() { StringBuilder sb = new StringBuilder(); string ft; if (OID_TO_FT.TryGetValue(OID, out ft) && IsString) { sb.Append(ft); sb.Append("="); byte[] buf = Encoding.UTF8.GetBytes(Value); for (int i = 0; i < buf.Length; i++) { byte b = buf[i]; if ((i == 0 && (b == ' ' || b == '#')) || (i == buf.Length - 1 && b == ' ') || MustEscape(b)) { switch ((char)b) { case ' ': case '"': case '#': case '+': case ',': case ';': case '<': case '=': case '>': case '\\': sb.Append('\\'); sb.Append((char)b); break; default: sb.AppendFormat("\\{0:X2}", b); break; } } else { sb.Append((char)b); } } } else { sb.Append(OID); sb.Append("=#"); foreach (byte b in AsnValue.Encode()) { sb.AppendFormat("{0:X2}", b); } } return(sb.ToString()); }
internal DNPart(string oid, AsnElt val) { OID_ = oid; AsnValue_ = val; encodedValue = val.Encode(); uint hc = (uint)oid.GetHashCode(); try { string s = val.GetString(); Value_ = s; s = s.ToUpperInvariant().ToLowerInvariant(); StringBuilder sb = new StringBuilder(); bool lwws = true; foreach (char c in s.Trim()) { if (IsControl(c)) { continue; } if (IsWS(c)) { if (lwws) { continue; } lwws = true; sb.Append(' '); } else { sb.Append(c); } } int n = sb.Length; if (n > 0 && sb[n - 1] == ' ') { sb.Length = n - 1; } normValue = sb.ToString(); hc += (uint)normValue.GetHashCode(); } catch { if (OID_TO_FT.ContainsKey(oid)) { throw; } Value_ = null; foreach (byte b in encodedValue) { hc = ((hc << 7) | (hc >> 25)) ^ (uint)b; } } hashCode = (int)hc; }