Example #1
0
        public void EncodedClear()
        {
            KdbxString str =
                new KdbxString(KeyVal, TextVal, this._rng, false);

            Assert.AreEqual(str.RawValue, TextVal);
        }
Example #2
0
        public void RoundTripClear()
        {
            KdbxString str =
                new KdbxString(KeyVal, TextVal, this._rng, false);

            Assert.AreEqual(str.ClearValue, TextVal);
        }
Example #3
0
        public void RoundTripProtected()
        {
            KdbxString str =
                new KdbxString(KeyVal, TextVal, this._rng, true);

            Assert.AreEqual(str.ClearValue, TextVal);
        }
Example #4
0
        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);
        }
Example #5
0
        public void SetNullProtected()
        {
            KdbxString str
                = new KdbxString(KeyVal, null, this._rng, true);

            Assert.IsNull(str.ClearValue);
            Assert.IsNull(str.RawValue);
        }
Example #6
0
        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);
        }
Example #7
0
        public void Deprotect()
        {
            KdbxString str =
                new KdbxString(KeyVal, TextVal, this._rng, true)
            {
                Protected = false
            };

            Assert.AreEqual(str.RawValue, TextVal);
        }
Example #8
0
        public void ChangeClearValueUnprotected()
        {
            KdbxString str =
                new KdbxString(KeyVal, TextVal, this._rng, false)
            {
                ClearValue = OtherTextVal
            };

            Assert.AreEqual(str.ClearValue, OtherTextVal);
            Assert.AreEqual(str.RawValue, OtherTextVal);
        }
Example #9
0
        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);
        }
Example #10
0
        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);
        }
Example #11
0
        /// <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);
        }
Example #12
0
        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);
        }
Example #13
0
        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);
        }