コード例 #1
0
        public void PropertyChangedHandler(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "FieldEditorViewModel")
            {
                if (ViewModel.FieldEditorViewModel != null)
                {
                    IProtectedString editingString = ViewModel.FieldEditorViewModel.Original;

                    FrameworkElement flyoutTarget;
                    if (editingString == null)
                    {
                        // New field - show below "Fields" label
                        flyoutTarget = this.entryFieldsLabel;
                    }
                    else
                    {
                        // Existing field - show below GridView container
                        flyoutTarget = this.fieldsGridView.ContainerFromItem(editingString) as FrameworkElement;
                        DebugHelper.Assert(flyoutTarget != null);
                    }

                    ((FrameworkElement)FieldEditorFlyout.Content).DataContext = ViewModel;
                    FieldEditorFlyout.ShowAt(flyoutTarget);
                }
                else
                {
                    // Field has been committed or otherwise discarded
                    FieldEditorFlyout.Hide();

                    // TODO: Resize the field in the GridView if needed
                    // Currently difficult because I need a reference to the updated string. Add an event to the ViewModel?
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Handles changes to <see cref="ProtectedString"/>.
        /// </summary>
        /// <param name="o">This control.</param>
        /// <param name="e">EventArgs for the property change.</param>
        private static void ProtectedStringChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            ProtectedTextBox thisControl = (ProtectedTextBox)o;

            IProtectedString oldStr = (IProtectedString)e.OldValue;

            if (oldStr != null)
            {
                oldStr.PropertyChanged -= thisControl.WrappedStringPropertyChangeHandler;
            }

            IProtectedString newStr = (IProtectedString)e.NewValue;

            if (newStr != null)
            {
                newStr.PropertyChanged += thisControl.WrappedStringPropertyChangeHandler;
                if (newStr.Protected)
                {
                    thisControl.Protect();
                }
                else
                {
                    thisControl.Deprotect();
                }
            }
        }
コード例 #3
0
 public bool Equals(IProtectedString other)
 {
     if (GetType() != other.GetType())
     {
         return(false);
     }
     return(Equals((ProtectedStringBlock)other));
 }
コード例 #4
0
 public StringPatternAnalyzer(IProtectedString password)
 {
     this.password = password;
     upperCase     = new Character(this);
     lowerCase     = new Character(this);
     number        = new NumericalCharacter(this);
     symbol        = new SpecialCharacter(this);
     unicode       = new SpecialCharacter(this);
 }
コード例 #5
0
        /// <summary>
        /// Initializes this ViewModel as an edit view over the specified protected string.
        /// </summary>
        /// <param name="stringToEdit">The string that this ViewModel wraps.</param>
        /// <param name="resourceProvider">ResourceLoader used for localization.</param>
        public FieldEditorViewModel(IProtectedString stringToEdit, IResourceProvider resourceProvider)
            : this(resourceProvider)
        {
            Original    = stringToEdit ?? throw new ArgumentNullException(nameof(stringToEdit));
            WorkingCopy = Original.Clone();

            // Evaluate whether it's currently possible to save the string
            CanSave(null);
        }
コード例 #6
0
ファイル: KdbxString.cs プロジェクト: sfuqua/PassKeep
        public int CompareTo(IProtectedString other)
        {
            // If the other string is null, this instance is greater.
            if (other == null)
            {
                return(1);
            }

            // Compare by ClearValue strings
            return(ClearValue.CompareTo(other.ClearValue));
        }
コード例 #7
0
ファイル: EntryFieldGridView.cs プロジェクト: sfuqua/PassKeep
 /// <summary>
 /// Handles interfering with layout to resize containers as needed.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void VariableGridView_LayoutUpdated(object sender, object e)
 {
     LayoutUpdated -= VariableGridView_LayoutUpdated;
     if (Items.Count > 0)
     {
         // Assuming an item was added (because removed items were already appropriately sized),
         // adjust the size of the last field.
         IProtectedString lastItem  = Items[Items.Count - 1] as IProtectedString;
         DependencyObject container = ContainerFromItem(lastItem);
         if (container != null)
         {
             SizeFromProtectedString(container, lastItem);
         }
         this.FindDescendantByType <VariableSizedWrapGrid>().InvalidateMeasure();
     }
 }
コード例 #8
0
ファイル: EntryFieldGridView.cs プロジェクト: sfuqua/PassKeep
        /// <summary>
        /// Adjusts the size of <paramref name="item"/> based on how large it will be to fit
        /// the given <paramref name="str"/> within itself.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="str"></param>
        public static void SizeFromProtectedString(DependencyObject item, IProtectedString str)
        {
            // Find the parent Border within the item
            Border templateBorder = item.FindDescendantByType <Border>();

            if (templateBorder == null)
            {
                item.SetValue(VariableSizedWrapGrid.ColumnSpanProperty, 4);

                if (!str.Protected && str.ClearValue.Contains("\n"))
                {
                    item.SetValue(VariableSizedWrapGrid.RowSpanProperty, 4);
                }
                else
                {
                    item.SetValue(VariableSizedWrapGrid.RowSpanProperty, 2);
                }
            }
            else
            {
                templateBorder.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

                TextBlock headerBlock = templateBorder.FindDescendantByType <TextBlock>();
                headerBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

                ProtectedTextBox contentBox = templateBorder.FindDescendantByType <ProtectedTextBox>();
                contentBox.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

                // As a hack I add 5px to the desiredWidth to bump it up if necessary...
                double desiredWidth  = Math.Max(headerBlock.DesiredSize.Width, contentBox.DesiredSize.Width) + 5;
                double desiredHeight = headerBlock.DesiredSize.Height + contentBox.DesiredSize.Height;

                VariableSizedWrapGrid vswg = VisualTreeHelper.GetParent(item) as VariableSizedWrapGrid;

                int columns = (int)Math.Ceiling(desiredWidth / vswg.ItemWidth);
                columns = Math.Max(Math.Min(columns, 5), 1);
                item.SetValue(VariableSizedWrapGrid.ColumnSpanProperty, columns);

                int rows = (int)Math.Ceiling(desiredHeight / vswg.ItemHeight);
                rows = Math.Max(Math.Min(rows, 7), 1);
                item.SetValue(VariableSizedWrapGrid.RowSpanProperty, rows);
            }
        }
コード例 #9
0
        public void Initialize()
        {
            IRandomNumberGenerator rng = new Salsa20(new byte[32]);

            IResourceProvider resourceProvider = new MockResourceProvider();

            this.parentEntry = new MockEntry();
            this.parentEntry.Fields.Add(
                new KdbxString(ExistingFieldKey, ExistingFieldValue, rng, ExistingFieldProtected)
                );

            MethodInfo testMethod = GetType().GetRuntimeMethod(
                TestContext.TestName, new Type[0]
                );

            DetailsForAttribute specAttr = testMethod.GetCustomAttribute <DetailsForAttribute>();

            if (specAttr == null)
            {
                return;
            }
            else
            {
                if (specAttr.IsNew)
                {
                    this.viewModel = new FieldEditorViewModel(rng, resourceProvider);
                }
                else
                {
                    this.originalString = new KdbxString(EditedFieldKey, EditedFieldValue, rng, EditedFieldProtected);
                    this.parentEntry.Fields.Add(this.originalString);

                    this.viewModel = new FieldEditorViewModel(this.originalString, resourceProvider);
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Handles changes to the "Protected" property of the wrapped string.
        /// </summary>
        /// <param name="sender">The wrapped protected string.</param>
        /// <param name="e">EventArgs for the change.</param>
        private void WrappedStringPropertyChangeHandler(object sender, PropertyChangedEventArgs e)
        {
            DebugHelper.Assert(sender == ProtectedString);
            IProtectedString wrappedStr = (IProtectedString)sender;

            if (e.PropertyName == "Protected")
            {
                // If the string is newly protected, we need to adjust the current state by deferring to our focus handlers.
                // If it is newly unprotected, clear the protection of this control.
                if (wrappedStr.Protected)
                {
                    if (this.PART_ProtectedBox.FocusState == FocusState.Unfocused)
                    {
                        OnLostFocus(null, new RoutedEventArgs());
                    }
                    else
                    {
                        OnGotFocus(null, new RoutedEventArgs());
                    }
                }
                else
                {
                    Deprotect();
                }
            }
            else if (e.PropertyName == "ClearValue")
            {
                // If the value of the string changed and we're not protected, update the string.
                if (!wrappedStr.Protected)
                {
                    this.PART_ProtectedBox.TextChanged -= TextChanged;
                    this.PART_ProtectedBox.Text         = wrappedStr.ClearValue;
                    this.PART_ProtectedBox.TextChanged += TextChanged;
                }
            }
        }
コード例 #11
0
ファイル: UnprotectedString.cs プロジェクト: sfuqua/PassKeep
 /// <summary>
 /// Compares ClearValues.
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public int CompareTo(IProtectedString other)
 {
     return((ClearValue ?? string.Empty).CompareTo(other.ClearValue ?? string.Empty));
 }
 public string ComputeHash(IProtectedString protectedString)
 {
     using ProtectedMemory protectedMemory = protectedString.GetProtectedUtf8Bytes();
     return(ComputeHash(protectedMemory));
 }
コード例 #13
0
 public override ProtectedMemory ComputeHashProtected(IProtectedString protectedString)
 {
     using ProtectedMemory protectedMemory = protectedString.GetProtectedUtf8Bytes();
     return(ComputeHashProtected(protectedMemory));
 }
コード例 #14
0
 public abstract ProtectedMemory ComputeHashProtected(IProtectedString protectedString);
コード例 #15
0
 public abstract string ComputeHash(IProtectedString protectedString);
コード例 #16
0
 public ProtectedMemory ComputeHmacProtected(IProtectedString key, IProtectedString message)
 {
     using ProtectedMemory mKey     = key.GetProtectedUtf8Bytes();
     using ProtectedMemory mMessage = message.GetProtectedUtf8Bytes();
     return(ComputeHmacProtected(mKey, mMessage));
 }
コード例 #17
0
 public ProtectedPasswordAnalyzer(IProtectedString password)
 {
     this.password = password;
 }
コード例 #18
0
 public ProtectedMemory ComputeHashProtected(IProtectedString protectedString)
 {
     throw new NotImplementedException();
 }
コード例 #19
0
 public string ComputeHash(IProtectedString protectedString)
 {
     throw new NotImplementedException();
 }