mirror of
https://github.com/KeyKeeperApp/KeyKeeper.git
synced 2026-04-17 18:16:28 +03:00
create PassStoreEntryPassword
This commit is contained in:
10
src/KeyKeeper/PasswordStore/LoginField.cs
Normal file
10
src/KeyKeeper/PasswordStore/LoginField.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace KeyKeeper.PasswordStore;
|
||||
|
||||
public struct LoginField
|
||||
{
|
||||
public byte Type;
|
||||
public Guid CustomFieldSubtype;
|
||||
public required string Value;
|
||||
}
|
||||
46
src/KeyKeeper/PasswordStore/PassStoreEntryPassword.cs
Normal file
46
src/KeyKeeper/PasswordStore/PassStoreEntryPassword.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using static KeyKeeper.PasswordStore.FileFormatConstants;
|
||||
|
||||
namespace KeyKeeper.PasswordStore;
|
||||
|
||||
public class PassStoreEntryPassword : PassStoreEntry
|
||||
{
|
||||
public LoginField Username { get; set; }
|
||||
public LoginField Password { get; set; }
|
||||
public List<LoginField> ExtraFields { get; set; }
|
||||
|
||||
public PassStoreEntryPassword(Guid id, DateTime createdAt, DateTime modifiedAt, Guid iconType, string name, LoginField username, LoginField password, List<LoginField>? extras = null)
|
||||
{
|
||||
Id = id;
|
||||
CreationDate = createdAt;
|
||||
ModificationDate = modifiedAt;
|
||||
IconType = iconType;
|
||||
Name = name;
|
||||
Username = username;
|
||||
Password = password;
|
||||
ExtraFields = extras ?? new();
|
||||
}
|
||||
|
||||
protected override byte[] InnerSerialize()
|
||||
{
|
||||
MemoryStream str = new();
|
||||
str.WriteByte(ENTRY_PASS_ID);
|
||||
WriteField(str, Username);
|
||||
WriteField(str, Password);
|
||||
BinaryWriter wr = new(str);
|
||||
wr.Write7BitEncodedInt(ExtraFields.Count);
|
||||
foreach (LoginField field in ExtraFields)
|
||||
WriteField(str, field);
|
||||
return str.ToArray();
|
||||
}
|
||||
|
||||
private void WriteField(Stream str, LoginField field)
|
||||
{
|
||||
str.WriteByte(field.Type);
|
||||
if (field.Type == LOGIN_FIELD_CUSTOM_ID)
|
||||
str.Write(field.CustomFieldSubtype.ToByteArray());
|
||||
FileFormatUtil.WriteU16TaggedString(str, field.Value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user