public KdbxEntry(IKeePassGroup parent, IRandomNumberGenerator rng, KdbxMetadata metadata) : this(false) { DebugHelper.Assert(parent != null); DebugHelper.Assert(rng != null); if (rng == null) { throw new ArgumentNullException("rng"); } DebugHelper.Assert(metadata != null); if (metadata == null) { throw new ArgumentNullException("metadata"); } Parent = parent ?? throw new ArgumentNullException("parent"); Uuid = new KeePassUuid(); IconID = KdbxEntry.DefaultIconId; Times = new KdbxTimes(); History = new KdbxHistory(metadata); KdbxMemoryProtection memProtection = metadata.MemoryProtection; Title = new KdbxString("Title", string.Empty, rng, memProtection.ProtectTitle); string initialUsername = metadata.DefaultUserName ?? string.Empty; UserName = new KdbxString("UserName", initialUsername, rng, memProtection.ProtectUserName); Password = new KdbxString("Password", string.Empty, rng, memProtection.ProtectPassword); Url = new KdbxString("URL", string.Empty, rng, memProtection.ProtectUrl); Notes = new KdbxString("Notes", string.Empty, rng, memProtection.ProtectNotes); Tags = string.Empty; OverrideUrl = string.Empty; this._metadata = metadata; }
public KdbxEntry(XElement xml, IKeePassGroup parent, IRandomNumberGenerator rng, KdbxMetadata metadata, KdbxSerializationParameters parameters) : base(xml, parameters) { Parent = parent; ForegroundColor = GetNullableColor("ForegroundColor"); BackgroundColor = GetNullableColor("BackgroundColor"); OverrideUrl = GetString("OverrideURL") ?? string.Empty; Tags = GetString("Tags") ?? string.Empty; Fields = new ObservableCollection <IProtectedString>(); IEnumerable <KdbxString> strings = GetNodes(KdbxString.RootName) .Select(x => new KdbxString(x, rng)); foreach (KdbxString s in strings) { switch (s.Key) { case "Notes": Notes = s; break; case "Password": Password = s; break; case "Title": Title = s; break; case "URL": Url = s; break; case "UserName": UserName = s; break; default: Fields.Add(s); break; } } KdbxMemoryProtection memProtection = metadata.MemoryProtection; if (Password == null) { Password = new KdbxString("Password", string.Empty, rng, memProtection.ProtectPassword); } if (Title == null) { Title = new KdbxString("Title", string.Empty, rng, memProtection.ProtectTitle); } if (Url == null) { Url = new KdbxString("URL", string.Empty, rng, memProtection.ProtectUrl); } if (UserName == null) { UserName = new KdbxString("UserName", string.Empty, rng, memProtection.ProtectUserName); } if (Notes == null) { Notes = new KdbxString("Notes", string.Empty, rng, memProtection.ProtectNotes); } IEnumerable <KdbxBinAttachment> binNodes = GetNodes(KdbxBinAttachment.RootName).Select(x => new KdbxBinAttachment(x, metadata, parameters)); Binaries = new ObservableCollection <IKeePassBinAttachment>(binNodes); XElement autoTypeNode = GetNode(KdbxAutoType.RootName); if (autoTypeNode != null) { AutoType = new KdbxAutoType(autoTypeNode); } XElement historyElement = GetNode(KdbxHistory.RootName); if (historyElement != null) { History = new KdbxHistory(historyElement, rng, metadata, parameters); } else { History = new KdbxHistory(metadata); } this._metadata = metadata; }
/// <summary> /// Helper that deserializes an entry as a history entry (no parent). /// </summary> /// <param name="xml"></param> /// <param name="rng"></param> /// <param name="metadata"></param> /// <param name="parameters"></param> public KdbxEntry(XElement xml, IRandomNumberGenerator rng, KdbxMetadata metadata, KdbxSerializationParameters parameters) : this(xml, null, rng, metadata, parameters) { this.isHistoryEntry = true; History = null; }