Exemplo n.º 1
0
        /// <summary>
        /// Whether two <see cref="KdbxBinaries"/> instances contain the same data.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            KdbxBinaries other = obj as KdbxBinaries;

            if (other == null)
            {
                return(false);
            }

            if (this.binaries.Count != other.binaries.Count)
            {
                return(false);
            }

            foreach (KeyValuePair <int, KdbxBinary> kvp in this.binaries)
            {
                if (!other.binaries.ContainsKey(kvp.Key))
                {
                    return(false);
                }

                if (!this.binaries[kvp.Key].Equals(other.binaries[kvp.Key]))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deserializes this node by using the <see cref="KdbxMetadata"/> binary collection
        /// to dereference @Ref.
        /// </summary>
        /// <param name="xml"></param>
        /// <param name="metadata">Used to dereference the Ref attribute.</param>
        /// <param name="parameters"></param>
        public KdbxBinAttachment(XElement xml, KdbxMetadata metadata, KdbxSerializationParameters parameters)
            : base(xml)
        {
            FileName = GetString("Key", true);

            XElement valueNode = GetNode("Value");

            if (valueNode == null)
            {
                throw new KdbxParseException(
                          ReaderResult.FromXmlParseFailure($"Node {rootName} missing required child Value")
                          );
            }

            int    refId;
            string refAttr = valueNode.Attribute("Ref")?.Value;

            if (refAttr == null || !int.TryParse(refAttr, out refId))
            {
                throw new KdbxParseException(
                          ReaderResult.FromXmlParseFailure($"Child Value node of {rootName} missing required int @Ref")
                          );
            }

            Data = metadata.Binaries.GetById(refId);
            this.binaryCollection = metadata.Binaries;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Parses out a metadata element from XML.
        /// </summary>
        /// <param name="xml">XML to deserialize.</param>
        /// <param name="headerBinaries">Binaries that have been pre-parsed from a header.</param>
        /// <param name="parameters">Parameters controlling serialization.</param>
        public KdbxMetadata(XElement xml, IEnumerable <ProtectedBinary> headerBinaries, KdbxSerializationParameters parameters)
            : base(xml)
        {
            if (headerBinaries == null)
            {
                throw new ArgumentNullException(nameof(headerBinaries));
            }

            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            Generator                  = GetString("Generator");
            HeaderHash                 = GetString("HeaderHash");
            DatabaseName               = GetString("DatabaseName");
            DatabaseNameChanged        = GetDate("DatabaseNameChanged", parameters);
            DatabaseDescription        = GetString("DatabaseDescription");
            DatabaseDescriptionChanged = GetDate("DatabaseDescriptionChanged", parameters);
            DefaultUserName            = GetString("DefaultUserName");
            DefaultUserNameChanged     = GetDate("DefaultUserNameChanged", parameters);
            MaintenanceHistoryDays     = GetInt("MaintenanceHistoryDays");
            DbColor              = GetNullableColor("Color");
            MasterKeyChanged     = GetDate("MasterKeyChanged", parameters, false);
            MasterKeyChangeRec   = GetInt("MasterKeyChangeRec", -1);
            MasterKeyChangeForce = GetInt("MasterKeyChangeForce", -1);
            MemoryProtection     = new KdbxMemoryProtection(GetNode(KdbxMemoryProtection.RootName));

            XElement iconsElement = GetNode(KdbxCustomIcons.RootName);

            if (iconsElement != null)
            {
                CustomIcons = new KdbxCustomIcons(iconsElement);
            }
            else
            {
                CustomIcons = null;
            }

            RecycleBinEnabled          = GetBool("RecycleBinEnabled");
            RecycleBinUuid             = GetUuid("RecycleBinUUID");
            RecycleBinChanged          = GetDate("RecycleBinChanged", parameters);
            EntryTemplatesGroup        = GetUuid("EntryTemplatesGroup");
            EntryTemplatesGroupChanged = GetDate("EntryTemplatesGroupChanged", parameters);
            HistoryMaxItems            = GetInt("HistoryMaxItems", -1);
            HistoryMaxSize             = GetInt("HistoryMaxSize", -1);
            LastSelectedGroup          = GetUuid("LastSelectedGroup");
            LastTopVisibleGroup        = GetUuid("LastTopVisibleGroup");

            XElement binariesElement = GetNode(KdbxBinaries.RootName);

            if (parameters.BinariesInXml)
            {
                if (binariesElement != null)
                {
                    Binaries = new KdbxBinaries(binariesElement, parameters);
                }
                else
                {
                    Binaries = new KdbxBinaries();
                }
            }
            else
            {
                // Populate with values from binary inner header
                Binaries = new KdbxBinaries(headerBinaries);
            }

            XElement customDataElement = GetNode(KdbxCustomData.RootName);

            if (customDataElement != null)
            {
                CustomData = new KdbxCustomData(customDataElement);
            }
            else
            {
                CustomData = null;
            }
        }