Entry.swift 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Entry.swift
  2. // This file is part of KeePassKit.
  3. //
  4. // Copyright © 2019 Maxime Epain. All rights reserved.
  5. //
  6. // KeePassKit is free software: you can redistribute it and/or modify
  7. // it under the terms of the GNU General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // KeePassKit is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU General Public License
  17. // along with KeePassKit. If not, see <https://www.gnu.org/licenses/>.
  18. import Binary
  19. import Foundation
  20. public final class Entry: Row, Streamable {
  21. public enum Column: UInt16, Streamable, Endable {
  22. case reserved = 0x0000
  23. case uuid = 0x0001
  24. case groupID = 0x0002
  25. case iconID = 0x0003
  26. case title = 0x0004
  27. case url = 0x0005
  28. case username = 0x0006
  29. case password = 0x0007
  30. case notes = 0x0008
  31. case creationTime = 0x0009
  32. case lastModifiedTime = 0x000A
  33. case lastAccessTime = 0x000B
  34. case expirationTime = 0x000C
  35. case binaryDesc = 0x000D
  36. case binaryData = 0x000E
  37. case end = 0xFFFF
  38. public static var endValue: Self { .end }
  39. }
  40. public internal(set) weak var parent: Group?
  41. public var properties: [TLV<Column, UInt32>]
  42. public init() {
  43. properties = []
  44. }
  45. public init(from input: Input) throws {
  46. properties = try input.read()
  47. }
  48. }
  49. extension Entry {
  50. public func removeFromParent() {
  51. parent?.entries.removeAll(where: { $0 == self })
  52. self[.groupID] = -1
  53. parent = nil
  54. }
  55. }
  56. extension Entry: Hashable {
  57. public static func == (lhs: Entry, rhs: Entry) -> Bool {
  58. lhs[.uuid] == rhs[.uuid]
  59. }
  60. public func hash(into hasher: inout Hasher) {
  61. hasher.combine(self[.uuid])
  62. hasher.combine(self[.title])
  63. }
  64. }