本文整理汇总了C#中KeePassLib.Utility.CharStream类的典型用法代码示例。如果您正苦于以下问题:C# CharStream类的具体用法?C# CharStream怎么用?C# CharStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CharStream类属于KeePassLib.Utility命名空间,在下文中一共展示了CharStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: JsonArray
public JsonArray(CharStream csDataSource)
{
if(csDataSource == null) throw new ArgumentNullException("csDataSource");
char chInit = csDataSource.ReadChar(true);
if(chInit != '[') throw new JsonFormatException();
List<JsonValue> lValues = new List<JsonValue>();
while(true)
{
char chNext = csDataSource.PeekChar(true);
if(chNext == ']') break;
lValues.Add(new JsonValue(csDataSource));
chNext = csDataSource.PeekChar(true);
if(chNext == ',') csDataSource.ReadChar(true);
}
char chTerminator = csDataSource.ReadChar(true);
if(chTerminator != ']') throw new JsonFormatException();
m_values = lValues.ToArray();
}
示例2: JsonObject
public JsonObject(CharStream csDataSource)
{
if(csDataSource == null) throw new ArgumentNullException("csDataSource");
char chInit = csDataSource.ReadChar(true);
if(chInit != '{') throw new JsonFormatException();
while(true)
{
string strName = (new JsonString(csDataSource)).Value;
char chSeparator = csDataSource.ReadChar(true);
if(chSeparator != ':') throw new JsonFormatException();
JsonValue jValue = new JsonValue(csDataSource);
m_dict[strName] = jValue;
char chNext = csDataSource.PeekChar(true);
if(chNext == '}') break;
else if(chNext == ',') csDataSource.ReadChar(true);
else throw new JsonFormatException();
}
char chTerminator = csDataSource.ReadChar(true);
if(chTerminator != '}') throw new JsonFormatException();
}
示例3: ParseRepl
internal static Dictionary<string, string> ParseRepl(string str)
{
Dictionary<string, string> d = new Dictionary<string, string>();
if(str == null) { Debug.Assert(false); return d; }
CharStream cs = new CharStream(str + ",,");
StringBuilder sb = new StringBuilder();
string strKey = string.Empty;
bool bValue = false;
while(true)
{
char ch = cs.ReadChar();
if(ch == char.MinValue) break;
if(ch == ',')
{
if(!bValue)
{
strKey = sb.ToString();
sb.Remove(0, sb.Length);
}
if(strKey.Length > 0) d[strKey] = sb.ToString();
sb.Remove(0, sb.Length);
bValue = false;
}
else if(ch == '>')
{
strKey = sb.ToString();
sb.Remove(0, sb.Length);
bValue = true;
}
else if(ch == '\\')
{
char chSub = cs.ReadChar();
if(chSub == 'n') sb.Append('\n');
else if(chSub == 'r') sb.Append('\r');
else if(chSub == 't') sb.Append('\t');
else sb.Append(chSub);
}
else sb.Append(ch);
}
return d;
}
示例4: Import
public override void Import(PwDatabase pwStorage, Stream sInput,
IStatusLogger slLogger)
{
StreamReader sr = new StreamReader(sInput, Encoding.UTF8);
string strContent = sr.ReadToEnd();
sr.Close();
if(strContent.Length == 0) return;
CharStream cs = new CharStream(strContent);
JsonObject jRoot = new JsonObject(cs);
AddObject(pwStorage.RootGroup, jRoot, pwStorage, false);
Debug.Assert(cs.PeekChar(true) == char.MinValue);
}
示例5: Import
public override void Import(PwDatabase pwStorage, Stream sInput,
IStatusLogger slLogger)
{
StreamReader sr = new StreamReader(sInput, Encoding.UTF8);
string strFileContents = sr.ReadToEnd();
sr.Close();
CharStream csSource = new CharStream(strFileContents);
while(true)
{
if(ReadEntry(pwStorage, csSource) == false)
break;
}
}
示例6: ReadEntry
private static bool ReadEntry(PwDatabase pwStorage, CharStream csSource)
{
PwEntry pe = new PwEntry(true, true);
string strTitle = ReadCsvField(csSource);
if(strTitle == null) return false; // No entry available
string strUser = ReadCsvField(csSource);
if(strUser == null) throw new InvalidDataException();
string strPassword = ReadCsvField(csSource);
if(strPassword == null) throw new InvalidDataException();
string strUrl = ReadCsvField(csSource);
if(strUrl == null) throw new InvalidDataException();
string strNotes = ReadCsvField(csSource);
if(strNotes == null) throw new InvalidDataException();
if((strTitle == "Account") && (strUser == "Login Name") &&
(strPassword == "Password") && (strUrl == "Web Site") &&
(strNotes == "Comments"))
{
return true; // Ignore header entry
}
pe.Strings.Set(PwDefs.TitleField, new ProtectedString(
pwStorage.MemoryProtection.ProtectTitle, strTitle));
pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(
pwStorage.MemoryProtection.ProtectUserName, strUser));
pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(
pwStorage.MemoryProtection.ProtectPassword, strPassword));
pe.Strings.Set(PwDefs.UrlField, new ProtectedString(
pwStorage.MemoryProtection.ProtectUrl, strUrl));
pe.Strings.Set(PwDefs.NotesField, new ProtectedString(
pwStorage.MemoryProtection.ProtectNotes, strNotes));
pwStorage.RootGroup.AddEntry(pe, true);
return true;
}
示例7: Import
public override void Import(PwDatabase pwStorage, Stream sInput,
IStatusLogger slLogger)
{
StreamReader sr = new StreamReader(sInput, StrUtil.Utf8);
string strContent = sr.ReadToEnd();
sr.Close();
if(string.IsNullOrEmpty(strContent)) return;
CharStream cs = new CharStream(strContent);
Dictionary<string, List<string>> dTags =
new Dictionary<string, List<string>>();
List<PwEntry> lCreatedEntries = new List<PwEntry>();
JsonObject jRoot = new JsonObject(cs);
AddObject(pwStorage.RootGroup, jRoot, pwStorage, false, dTags,
lCreatedEntries);
Debug.Assert(cs.PeekChar(true) == char.MinValue);
// Assign tags
foreach(PwEntry pe in lCreatedEntries)
{
string strUri = pe.Strings.ReadSafe(PwDefs.UrlField);
if(strUri.Length == 0) continue;
foreach(KeyValuePair<string, List<string>> kvp in dTags)
{
foreach(string strTagUri in kvp.Value)
{
if(strUri.Equals(strTagUri, StrUtil.CaseIgnoreCmp))
pe.AddTag(kvp.Key);
}
}
}
}
示例8: MakeList
public static void MakeList()
{
string strData = File.ReadAllText("MostPopularPasswords.txt", StrUtil.Utf8);
strData += " ";
CharStream cs = new CharStream(strData);
List<string> vPasswords = new List<string>();
StringBuilder sbPassword = new StringBuilder();
while (true)
{
char ch = cs.ReadChar();
if (ch == char.MinValue) break;
if (char.IsWhiteSpace(ch))
{
string strPassword = sbPassword.ToString();
strPassword = strPassword.ToLower();
if (strPassword.Length > 3)
{
if (vPasswords.IndexOf(strPassword) < 0)
vPasswords.Add(strPassword);
}
sbPassword = new StringBuilder();
}
else
{
Debug.Assert(!char.IsControl(ch) && !char.IsHighSurrogate(ch) &&
!char.IsLowSurrogate(ch) && !char.IsSurrogate(ch));
Debug.Assert(IsPopularChar(ch));
sbPassword.Append(ch);
}
}
ulong[] vTable = new ulong[PpcTableSize / 64];
Array.Clear(vTable, 0, vTable.Length);
long lBitsInTable = 0;
foreach (string strPassword in vPasswords)
{
byte[] pbUtf8 = StrUtil.Utf8.GetBytes(strPassword);
int[] vIndices = GetTableIndices(pbUtf8, PpcTableSize);
foreach (int i in vIndices)
{
if (SetTableBit(vTable, i)) ++lBitsInTable;
}
}
StringBuilder sb = new StringBuilder();
sb.Append("\t\t\t");
for (int i = 0; i < vTable.Length; ++i)
{
if (i > 0)
{
if ((i % 3) == 0)
{
sb.AppendLine(",");
sb.Append("\t\t\t");
}
else sb.Append(", ");
}
sb.Append("0x");
sb.Append(vTable[i].ToString("X16"));
sb.Append("UL");
}
sb.AppendLine();
sb.AppendLine();
sb.AppendLine("Bits set: " + lBitsInTable.ToString() + " of " +
PpcTableSize.ToString());
int cHashFn = GetTableIndices(StrUtil.Utf8.GetBytes("Dummy"), PpcTableSize).Length;
sb.AppendLine("Hash functions: " + cHashFn.ToString());
double dblPhi = Math.Pow(1.0 - ((double) cHashFn / PpcTableSize),
(double) vPasswords.Count);
sb.AppendLine("Phi (bits unset ratio) estimation: " +
dblPhi.ToString(CultureInfo.InvariantCulture));
dblPhi = ((double) (PpcTableSize - lBitsInTable) / (double) PpcTableSize);
sb.AppendLine("Exact Phi: " + dblPhi.ToString(CultureInfo.InvariantCulture));
sb.AppendLine("False positives ratio: " + Math.Pow(1.0 - dblPhi,
(double) cHashFn).ToString(CultureInfo.InvariantCulture));
File.WriteAllText("Table.txt", sb.ToString());
}
示例9: JsonNumber
public JsonNumber(CharStream csDataSource)
{
if(csDataSource == null) throw new ArgumentNullException("csDataSource");
StringBuilder sb = new StringBuilder();
while(true)
{
char ch = csDataSource.PeekChar(true);
if(((ch >= '0') && (ch <= '9')) || (ch == 'e') || (ch == 'E') ||
(ch == '+') || (ch == '-') || (ch == '.'))
{
csDataSource.ReadChar(true);
sb.Append(ch);
}
else break;
}
const NumberStyles ns = (NumberStyles.Integer | NumberStyles.AllowDecimalPoint |
NumberStyles.AllowThousands | NumberStyles.AllowExponent);
if(!double.TryParse(sb.ToString(), ns, NumberFormatInfo.InvariantInfo,
out m_value)) { Debug.Assert(false); }
}
示例10: CsvStreamReader
public CsvStreamReader(string strData, bool bAllowUnquoted)
{
m_sChars = new CharStream(strData);
m_bAllowUnquoted = bAllowUnquoted;
}
示例11: Parse
private static List<SiEvent> Parse(string strSequence)
{
CharStream cs = new CharStream(strSequence);
List<SiEvent> l = new List<SiEvent>();
string strError = KPRes.AutoTypeSequenceInvalid;
Keys kCurKbMods = Keys.None;
List<Keys> lMods = new List<Keys>();
lMods.Add(Keys.None);
while(true)
{
char ch = cs.ReadChar();
if(ch == char.MinValue) break;
if((ch == '+') || (ch == '^') || (ch == '%'))
{
if(lMods.Count == 0) { Debug.Assert(false); break; }
else if(ch == '+') lMods[lMods.Count - 1] |= Keys.Shift;
else if(ch == '^') lMods[lMods.Count - 1] |= Keys.Control;
else if(ch == '%') lMods[lMods.Count - 1] |= Keys.Alt;
else { Debug.Assert(false); }
continue;
}
else if(ch == '(')
{
lMods.Add(Keys.None);
continue;
}
else if(ch == ')')
{
if(lMods.Count >= 2)
{
lMods.RemoveAt(lMods.Count - 1);
lMods[lMods.Count - 1] = Keys.None;
}
else throw new FormatException(strError);
continue;
}
Keys kEffMods = Keys.None;
foreach(Keys k in lMods) kEffMods |= k;
EnsureKeyModifiers(kEffMods, ref kCurKbMods, l);
if(ch == '{')
{
List<SiEvent> lSub = ParseSpecial(cs);
if(lSub == null) throw new FormatException(strError);
l.AddRange(lSub);
}
else if(ch == '}')
throw new FormatException(strError);
else if(ch == '~')
{
SiEvent si = new SiEvent();
si.Type = SiEventType.Key;
si.VKey = (int)Keys.Enter;
l.Add(si);
}
else
{
SiEvent si = new SiEvent();
si.Type = SiEventType.Char;
si.Char = ch;
l.Add(si);
}
lMods[lMods.Count - 1] = Keys.None;
}
EnsureKeyModifiers(Keys.None, ref kCurKbMods, l);
return l;
}
示例12: JsonNumber
public JsonNumber(CharStream csDataSource)
{
if(csDataSource == null) throw new ArgumentNullException("csDataSource");
StringBuilder sb = new StringBuilder();
while(true)
{
char ch = csDataSource.PeekChar(true);
if(((ch >= '0') && (ch <= '9')) || (ch == 'e') || (ch == 'E') ||
(ch == '+') || (ch == '-') || (ch == '.'))
{
csDataSource.ReadChar(true);
sb.Append(ch);
}
else break;
}
if(!double.TryParse(sb.ToString(), out m_value)) { Debug.Assert(false); }
}
示例13: SplitKeySequence
private static List<string> SplitKeySequence(string strKeys)
{
List<string> vParts = new List<string>();
if(string.IsNullOrEmpty(strKeys)) return vParts;
CharStream cs = new CharStream(strKeys);
StringBuilder sbRawText = new StringBuilder();
while(true)
{
char ch = cs.ReadChar();
if(ch == char.MinValue) break;
switch(ch)
{
case ')':
case '}':
throw new FormatException();
case '(':
case '{':
case '+':
case '^':
case '%':
case ' ':
case '\t':
string strBuf = sbRawText.ToString();
if(strBuf.IndexOfAny(new char[]{ '+', '^', '%',
' ', '\t' }) < 0)
{
if(strBuf.Length > 0) vParts.Add(strBuf);
sbRawText.Remove(0, sbRawText.Length);
}
if(ch == '(')
{
ReadParenthesized(cs, sbRawText);
if(sbRawText.Length > 0)
vParts.Add(sbRawText.ToString());
sbRawText.Remove(0, sbRawText.Length);
}
else if(ch == '{')
{
ReadBraced(cs, sbRawText);
if(sbRawText.Length > 0)
vParts.Add(sbRawText.ToString());
sbRawText.Remove(0, sbRawText.Length);
}
else if(ch == ' ')
{
vParts.Add(" ");
sbRawText.Remove(0, sbRawText.Length);
}
else if(ch == '\t')
{
vParts.Add("\t");
sbRawText.Remove(0, sbRawText.Length);
}
else sbRawText.Append(ch);
break;
default:
sbRawText.Append(ch);
break;
}
}
if(sbRawText.Length > 0) vParts.Add(sbRawText.ToString());
return vParts;
}
示例14: Generate
public static PwgError Generate(ProtectedString psOutBuffer,
PwProfile pwProfile, CryptoRandomStream crsRandomSource)
{
LinkedList<char> vGenerated = new LinkedList<char>();
PwCharSet pcsCurrent = new PwCharSet();
PwCharSet pcsCustom = new PwCharSet();
PwCharSet pcsUsed = new PwCharSet();
bool bInCharSetDef = false;
string strPattern = ExpandPattern(pwProfile.Pattern);
if(strPattern.Length == 0) return PwgError.Success;
CharStream csStream = new CharStream(strPattern);
char ch = csStream.ReadChar();
while(ch != char.MinValue)
{
pcsCurrent.Clear();
bool bGenerateChar = false;
if(ch == '\\')
{
ch = csStream.ReadChar();
if(ch == char.MinValue) // Backslash at the end
{
vGenerated.AddLast('\\');
break;
}
if(bInCharSetDef) pcsCustom.Add(ch);
else
{
vGenerated.AddLast(ch);
pcsUsed.Add(ch);
}
}
else if(ch == '[')
{
pcsCustom.Clear();
bInCharSetDef = true;
}
else if(ch == ']')
{
pcsCurrent.Add(pcsCustom.ToString());
bInCharSetDef = false;
bGenerateChar = true;
}
else if(bInCharSetDef)
{
if(pcsCustom.AddCharSet(ch) == false)
pcsCustom.Add(ch);
}
else if(pcsCurrent.AddCharSet(ch) == false)
{
vGenerated.AddLast(ch);
pcsUsed.Add(ch);
}
else bGenerateChar = true;
if(bGenerateChar)
{
PwGenerator.PrepareCharSet(pcsCurrent, pwProfile);
if(pwProfile.NoRepeatingCharacters)
pcsCurrent.Remove(pcsUsed.ToString());
char chGen = PwGenerator.GenerateCharacter(pwProfile,
pcsCurrent, crsRandomSource);
if(chGen == char.MinValue) return PwgError.TooFewCharacters;
vGenerated.AddLast(chGen);
pcsUsed.Add(chGen);
}
ch = csStream.ReadChar();
}
if(vGenerated.Count == 0) return PwgError.Success;
char[] vArray = new char[vGenerated.Count];
vGenerated.CopyTo(vArray, 0);
if(pwProfile.PatternPermutePassword)
PwGenerator.ShufflePassword(vArray, crsRandomSource);
byte[] pbUtf8 = Encoding.UTF8.GetBytes(vArray);
psOutBuffer.SetString(Encoding.UTF8.GetString(pbUtf8, 0, pbUtf8.Length));
Array.Clear(pbUtf8, 0, pbUtf8.Length);
Array.Clear(vArray, 0, vArray.Length);
vGenerated.Clear();
return PwgError.Success;
}
示例15: ReadParenthesized
private static void ReadParenthesized(CharStream csIn, StringBuilder sbBuffer)
{
sbBuffer.Append('(');
while(true)
{
char ch = csIn.ReadChar();
if((ch == char.MinValue) || (ch == '}'))
throw new FormatException();
else if(ch == ')')
{
sbBuffer.Append(ch);
break;
}
else if(ch == '(')
ReadParenthesized(csIn, sbBuffer);
else if(ch == '{')
ReadBraced(csIn, sbBuffer);
else sbBuffer.Append(ch);
}
}