public void EncodedClear() { KdbxString str = new KdbxString(KeyVal, TextVal, this._rng, false); Assert.AreEqual(str.RawValue, TextVal); }
public void RoundTripClear() { KdbxString str = new KdbxString(KeyVal, TextVal, this._rng, false); Assert.AreEqual(str.ClearValue, TextVal); }
public void RoundTripProtected() { KdbxString str = new KdbxString(KeyVal, TextVal, this._rng, true); Assert.AreEqual(str.ClearValue, TextVal); }
public void SetXmlProtected() { byte[] clearBytes = Encoding.UTF8.GetBytes(TextVal); byte[] padBytes = this._rng.GetBytes((uint)clearBytes.Length); ByteHelper.Xor(padBytes, 0, clearBytes, 0, clearBytes.Length); string enc = Convert.ToBase64String(clearBytes); XElement node = new XElement("String"); XElement value = new XElement("Value", enc); value.SetAttributeValue("Protected", "True"); node.Add( new XElement("Key", KeyVal), value ); KdbxString str = new KdbxString(node, this._rng.Clone()); Assert.AreEqual(str.ClearValue, TextVal); Assert.AreNotEqual(str.RawValue, TextVal); Assert.IsNotNull(str.RawValue); Assert.AreNotEqual(str.RawValue, String.Empty); Assert.IsTrue(str.Protected); Assert.AreEqual(str.Key, KeyVal); }
public void SetNullProtected() { KdbxString str = new KdbxString(KeyVal, null, this._rng, true); Assert.IsNull(str.ClearValue); Assert.IsNull(str.RawValue); }
public void EncodedProtected() { KdbxString str = new KdbxString(KeyVal, TextVal, this._rng, true); Assert.AreNotEqual(str.RawValue, TextVal); Assert.IsNotNull(str.RawValue); Assert.AreNotEqual(str.RawValue, String.Empty); }
public void Deprotect() { KdbxString str = new KdbxString(KeyVal, TextVal, this._rng, true) { Protected = false }; Assert.AreEqual(str.RawValue, TextVal); }
public void ChangeClearValueUnprotected() { KdbxString str = new KdbxString(KeyVal, TextVal, this._rng, false) { ClearValue = OtherTextVal }; Assert.AreEqual(str.ClearValue, OtherTextVal); Assert.AreEqual(str.RawValue, OtherTextVal); }
public void Protect() { KdbxString str = new KdbxString(KeyVal, TextVal, this._rng, false) { Protected = true }; Assert.AreNotEqual(str.RawValue, TextVal); Assert.IsNotNull(str.RawValue); Assert.AreNotEqual(str.RawValue, String.Empty); }
public void ChangeClearValueProtected() { KdbxString str = new KdbxString(KeyVal, TextVal, this._rng, true) { ClearValue = OtherTextVal }; Assert.AreEqual(str.ClearValue, OtherTextVal); Assert.AreNotEqual(str.RawValue, OtherTextVal); Assert.IsNotNull(str.RawValue); Assert.AreNotEqual(str.RawValue, String.Empty); }
/// <summary> /// Initializes this ViewModel as an edit view over a new protected string. /// </summary> /// <param name="rng">The random number generator to use for the new string.</param> /// <param name="resourceProvider">ResourceLoader used for localization.</param> public FieldEditorViewModel(IRandomNumberGenerator rng, IResourceProvider resourceProvider) : this(resourceProvider) { if (rng == null) { throw new ArgumentNullException(nameof(rng)); } Original = null; WorkingCopy = new KdbxString(String.Empty, String.Empty, rng, false); // Evaluate whether it's currently possible to save the string CanSave(null); }
public void SetXmlUnprotected() { XElement node = new XElement("String"); node.Add( new XElement("Key", KeyVal), new XElement("Value", TextVal) ); KdbxString str = new KdbxString(node, this._rng); Assert.AreEqual(str.ClearValue, TextVal); Assert.AreEqual(str.RawValue, TextVal); Assert.IsFalse(str.Protected); Assert.AreEqual(str.Key, KeyVal); }
public void XmlRoundTrip() { byte[] clearBytes = Encoding.UTF8.GetBytes(TextVal); byte[] padBytes = this._rng.GetBytes((uint)clearBytes.Length); ByteHelper.Xor(padBytes, 0, clearBytes, 0, clearBytes.Length); string enc = Convert.ToBase64String(clearBytes); XElement node = new XElement("String"); XElement value = new XElement("Value", enc); value.SetAttributeValue("Protected", "True"); node.Add( new XElement("Key", KeyVal), value ); KdbxString str = new KdbxString(node, this._rng.Clone()); XElement node2 = str.ToXml(this._rng.Clone(), new KdbxSerializationParameters(KdbxVersion.Unspecified)); KdbxString str2 = new KdbxString(node2, this._rng.Clone()); Assert.AreEqual(str.Protected, str2.Protected); Assert.AreEqual(str.ClearValue, str2.ClearValue); }