/// <summary> /// Removes a key from this keyring. /// </summary> /// <param name="name">Name of key to remove</param> public void Remove(string name) { if (ReadOnly) { throw new Exception("Keyring is read-only."); } if (KeyNames.Contains(name)) { throw new Exception("Key not found."); } Keys.RemoveAll(k => k.Name == name); KeyNames.Remove(name); KeyringChanged?.Invoke(); }
/// <summary> /// Imports keys from a given keyring to this keyring. /// </summary> /// <param name="importableKeyring">External keyring to import from</param> public void Import(Keyring importableKeyring) { if (ReadOnly) { throw new Exception("Keyring is read-only."); } foreach (var key in importableKeyring.Keys) { if (HasKey(key.Name)) { continue; } Add(key.Name, key.KeyData, key.Locked); } KeyringChanged?.Invoke(); }
/// <summary> /// Adds a key to this keyring. /// </summary> /// <param name="name">Name of the key</param> /// <param name="key">Key encryption data</param> /// <param name="preLocked">If the key should be locked immediately</param> public void Add(string name, EncryptionKey key, bool preLocked = false) { if (ReadOnly) { throw new Exception("Keyring is read-only."); } if (KeyNames.Contains(name)) { throw new Exception("Key already exists. If replacing, use Remove() first."); } var newKey = new KeyDescriptor(name, key, preLocked); newKey.KeyLockChanged += locked => { KeyringChanged?.Invoke(); }; Keys.Add(newKey); KeyNames.Add(newKey.Name); KeyringChanged?.Invoke(); }