Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
fireout committed Mar 4, 2016
2 parents 4f3f6f9 + d54bb00 commit abaf804
Show file tree
Hide file tree
Showing 67 changed files with 5,696 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.suo
*.user
_ReSharper.*
bin
obj
sequence.xml
6 changes: 6 additions & 0 deletions Configuration/Model/AnySubstitution.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Sequencer.Configuration.Model
{
public class AnySubstitution :BaseSubstitution
{
}
}
17 changes: 17 additions & 0 deletions Configuration/Model/BaseSubstitution.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Xml.Serialization;

namespace Sequencer.Configuration.Model
{
public abstract class BaseSubstitution
{
protected BaseSubstitution() { Replace = ""; With = ""; CaseSensitive = false; }

[XmlAttribute("replace")]
public string Replace { get; set; }
[XmlAttribute("with")]
public string With { get; set; }

[XmlAttribute("caseSensitive")]
public bool CaseSensitive { get; set; }
}
}
14 changes: 14 additions & 0 deletions Configuration/Model/CapitalizeEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Xml.Serialization;

namespace Sequencer.Configuration.Model
{
public enum CapitalizeEnum : byte
{
[XmlEnum("never")]
Never = 0,
[XmlEnum("always")]
Always = 100,
[XmlEnum("proper")]
Proper = 101
}
}
134 changes: 134 additions & 0 deletions Configuration/Model/CharacterList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Xml.Serialization;

namespace Sequencer.Configuration.Model
{
[XmlRoot(ElementName = "Words")]
public class CharacterList : CustomSerializationBaseList<char>
{
public override void ReadXml(XmlReader reader)
{
string content = reader.ReadElementContentAsString();
content = content.Replace("\n", " ");
content = content.Replace("\t", " ");
content = content.Replace("\r", " ");
string[] contentArray = content.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

BackingList = new List<char>();
foreach (string s in contentArray)
{
if (s.Length == 1)
{
/* if the item is a single backslash, it probably preceeded
* a space character, so add a literal space.
*/
if (s[0] == '\\')
{
BackingList.Add(' ');
}
else
{
BackingList.Add(s[0]);
}
}
else if (s.Length == 2 && s[0] == '\\')
{
/* if the item is a two-character sequence and the first
* character is a backslash, include the second character
* instead (allows adding a literal backslash since we
* treat it special above; and any other special sequences
* we may add in the future).
*/
BackingList.Add(s[1]);
}
}
}

public override void WriteXml(XmlWriter writer)
{
StringBuilder configString = new StringBuilder();
foreach (char c in BackingList)
{
if (configString.Length > 0)
configString.Append(" ");
if (c == '\\' || c == ' ')
configString.Append('\\');
configString.Append(c);
}
writer.WriteString(configString.ToString());
}

public override string ToString()
{
return new string(BackingList.ToArray());
}
}

[XmlRoot(ElementName = "Words")]
public class OverridingCharacterList : OverridingCustomSerializationBaseList<char>
{
public override void ReadXml(XmlReader reader)
{
string overrideString = (reader.GetAttribute("override") ?? "true");
if (overrideString == "1") overrideString = "true";
Override = overrideString.ToLower().Equals("true");

string content = reader.ReadElementContentAsString();
content = content.Replace("\n", " ");
content = content.Replace("\t", " ");
content = content.Replace("\r", " ");
string[] contentArray = content.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

BackingList = new List<char>();
foreach (string s in contentArray)
for (int i = 0; i < s.Length; i++)
{
/* if the first character in an item is a backslash, then it
* escapes the next character, or it escapes a space
*/
if (s[i] == '\\')
{
if (i+1 < s.Length)
{
/* length > 1 means it escapes the next char */
BackingList.Add(s[i+1]);
i+=1;
}
else if (s.Length == 1)
{
/* just a backslash means it escaped a space */
BackingList.Add(' ');
}
}
else
{
BackingList.Add(s[i]);
}
}
}

public override void WriteXml(XmlWriter writer)
{
writer.WriteAttributeString("override", Override.ToString().ToLower());

StringBuilder configString = new StringBuilder();
foreach (char c in BackingList)
{
if (configString.Length > 0)
configString.Append(" ");
if (c == '\\' || c == ' ')
configString.Append('\\');
configString.Append(c);
}
writer.WriteString(configString.ToString());
}

public override string ToString()
{
return new string(BackingList.ToArray());
}
}
}
99 changes: 99 additions & 0 deletions Configuration/Model/CharacterSequenceItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System;
using System.ComponentModel;
using System.Xml.Serialization;

namespace Sequencer.Configuration.Model
{
[XmlRoot(ElementName = "Characters")]
public class CharacterSequenceItem : SequenceItem
{
public CharacterSequenceItem()
{
Length = 5;
LengthStrength = StrengthEnum.Full;
AllowDuplicate = true;
Characters = new OverridingCharacterList();
}

public OverridingCharacterList Characters { get; set; }

public override double entropy(PasswordSequenceConfiguration config)
{
double entropyVal = 0;

if (Length > 0)
{
uint len = Length;
uint charlist_len = 0;
if (Characters != null)
{
charlist_len = (uint)Characters.Count;
}
if (Characters == null || !Characters.Override)
{
charlist_len += (uint)config.DefaultCharacters.Count;
}

if (!AllowDuplicate)
{
len = (len <= charlist_len ? len : charlist_len);
}

double cur_len_entropy = 0.0;
uint cur_len = len;
while (cur_len > 0 && charlist_len > 0)
{
cur_len_entropy += Math.Log(charlist_len, 2);

if (LengthStrength < StrengthEnum.Full)
{
if (cur_len > 1)
{
entropyVal += (1 - (double)LengthStrength / 100) * cur_len_entropy / len;
}
}

if (!AllowDuplicate)
{
charlist_len -= 1;
}
cur_len -= 1;
}
entropyVal += ((double)LengthStrength / 100) * cur_len_entropy;
}

return entropyVal;
}

[XmlAttribute("allowDuplicate")]
public bool AllowDuplicate { get; set; }

[XmlAttribute("length")]
public uint Length { get; set; }

[XmlIgnore]
private StrengthEnum _myLenStren;
[XmlIgnore]
public StrengthEnum LengthStrength
{
get { return _myLenStren; }
set
{
if (value > StrengthEnum.Full)
_myLenStren = StrengthEnum.Full;
else if (value < 0)
_myLenStren = 0;
else
_myLenStren = value;
}
}

[XmlAttribute("lengthStrength")]
[EditorBrowsable(EditorBrowsableState.Never), Browsable(false)]
public string XmlLengthStrength
{
get { return LengthStrength.ToString().ToLower(); }
set { LengthStrength = (StrengthEnum)Enum.Parse(typeof(StrengthEnum), value, true); }
}
}
}
112 changes: 112 additions & 0 deletions Configuration/Model/CustomSerializationBaseList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace Sequencer.Configuration.Model
{
public abstract class CustomSerializationBaseList<T> : IList<T>, IXmlSerializable
{
protected CustomSerializationBaseList()
{
BackingList = new List<T>();
}

protected List<T> BackingList;

public IEnumerator<T> GetEnumerator()
{
return BackingList.GetEnumerator();
}

IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

public void Add(T item)
{
BackingList.Add(item);
}
public void AddRange(IEnumerable<T> values)
{
BackingList.AddRange(values);
}


public void Clear()
{
BackingList.Clear();
}

public bool Contains(T item)
{
return BackingList.Contains(item);
}

public void CopyTo(T[] array, int arrayIndex)
{
BackingList.CopyTo(array, arrayIndex);
}

public bool Remove(T item)
{
return BackingList.Remove(item);
}

public int Count
{
get { return BackingList.Count; }
}

public bool IsReadOnly
{
get { return false; }
}

public int IndexOf(T item)
{
return BackingList.IndexOf(item);
}

public void Insert(int index, T item)
{
BackingList.Insert(index, item);
}

public void RemoveAt(int index)
{
BackingList.RemoveAt(index);
}

public T this[int index]
{
get { return BackingList[index]; }
set { BackingList[index] = value; }
}

public virtual XmlSchema GetSchema()
{
return null;
}

public abstract void ReadXml(XmlReader reader);
//{
// string content = reader.ReadContentAsString();
// string[] contentArray = content.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

// _backingList = new List<T>(contentArray.Cast<T>());
//}

public abstract void WriteXml(XmlWriter writer);
//{
// writer.WriteString(string.Join(" ", _backingList.Select(i => i.ToString()).ToArray()));
//}

public override string ToString()
{
return BackingList.ToString();
}
}
}
Loading

0 comments on commit abaf804

Please sign in to comment.