From 1c71f889fa0cd5c46b55859fd09d657cfccbdd6a Mon Sep 17 00:00:00 2001 From: Oliver Wiese <oliver.wiese@fu-berlin.de> Date: Mon, 2 Mar 2020 15:50:26 +0100 Subject: [PATCH] add comments to coredata elements --- .../EnzevalosContact+CoreDataClass.swift | 32 +++++-- .../EnzevalosContact+CoreDataProperties.swift | 3 + enzevalos_iphone/Folder+CoreDataClass.swift | 3 + .../Folder+CoreDataProperties.swift | 6 ++ .../KeyRecord+CoreDataClass.swift | 37 ++++++- .../Mail_Address+CoreDataClass.swift | 13 ++- .../Mail_Address+CoreDataProperties.swift | 11 ++- .../PersistentKey+CoreDataClass.swift | 10 ++ .../PersistentKey+CoreDataProperties.swift | 59 +++++++++++- .../PersistentMail +CoreDataClass.swift | 24 ++++- .../PersistentMail +CoreDataProperties.swift | 96 +++++++++++++++++-- .../SecretKey+CoreDataProperties.swift | 22 ++++- 12 files changed, 291 insertions(+), 25 deletions(-) diff --git a/enzevalos_iphone/EnzevalosContact+CoreDataClass.swift b/enzevalos_iphone/EnzevalosContact+CoreDataClass.swift index 5187b1f2..d1408ebc 100644 --- a/enzevalos_iphone/EnzevalosContact+CoreDataClass.swift +++ b/enzevalos_iphone/EnzevalosContact+CoreDataClass.swift @@ -36,7 +36,11 @@ fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool { } } - +/** + EnzevalosContact is used for persons and items of the address book (by apple). + One enzevalosContact maps to one person/item of the address book. + One enzevalosContact links to multiple key records since the person have multiple keys. + */ @objc(EnzevalosContact) open class EnzevalosContact: NSManagedObject, Contact, Comparable { @@ -57,6 +61,9 @@ open class EnzevalosContact: NSManagedObject, Contact, Comparable { } } + /** + Just like nameOptional or a localized variant of "no name". Just in case you like to enforce a name. + */ open var name: String { if let name = nameOptional { return name @@ -146,6 +153,9 @@ open class EnzevalosContact: NSManagedObject, Contact, Comparable { } } + /** + A set of associated public keys + */ var publicKeys: Set<PersistentKey> { get { var pks = Set<PersistentKey>() @@ -155,7 +165,9 @@ open class EnzevalosContact: NSManagedObject, Contact, Comparable { return pks } } - + /** + A set of associated key records + */ open var records: [KeyRecord] { get { if let krecords = self.keyrecords as? Set<KeyRecord> { @@ -195,6 +207,9 @@ open class EnzevalosContact: NSManagedObject, Contact, Comparable { return date } + /** + Related item in the address book (from apple) + */ open var cnContact: CNContact? { get { if let cn = cnidentifier { @@ -207,6 +222,9 @@ open class EnzevalosContact: NSManagedObject, Contact, Comparable { } } + /** + Create a new cnContact in the address book. + */ open var newCnContact: CNContact { let con = CNMutableContact() let name = self.displayname @@ -241,13 +259,6 @@ open class EnzevalosContact: NSManagedObject, Contact, Comparable { return nil } - func getAddressByMCOAddress(_ mcoaddress: MCOAddress) -> Mail_Address? { - if (mcoaddress.mailbox) != nil { - return getAddress(mcoaddress.mailbox.lowercased()) - } - return nil - } - open func getMailAddresses() -> [MailAddress] { var adr = [MailAddress] () for a in addresses { @@ -257,6 +268,9 @@ open class EnzevalosContact: NSManagedObject, Contact, Comparable { return adr } + /** + Is the address associated to the person(enzevalos contact) + */ func isAddress(mailadr: String) -> Bool { for adr in getMailAddresses() { if mailadr.lowercased() == adr.mailAddress.lowercased() { diff --git a/enzevalos_iphone/EnzevalosContact+CoreDataProperties.swift b/enzevalos_iphone/EnzevalosContact+CoreDataProperties.swift index 72caa20c..106d86af 100644 --- a/enzevalos_iphone/EnzevalosContact+CoreDataProperties.swift +++ b/enzevalos_iphone/EnzevalosContact+CoreDataProperties.swift @@ -29,6 +29,9 @@ extension EnzevalosContact { } @NSManaged public var displayname: String? + /** + Identifier to look up contact in the address book + */ @NSManaged public var cnidentifier: String? @NSManaged public var color: UIColor? @NSManaged public var addresses: NSSet diff --git a/enzevalos_iphone/Folder+CoreDataClass.swift b/enzevalos_iphone/Folder+CoreDataClass.swift index 3a6ea446..68b5157f 100644 --- a/enzevalos_iphone/Folder+CoreDataClass.swift +++ b/enzevalos_iphone/Folder+CoreDataClass.swift @@ -41,6 +41,9 @@ public class Folder: NSManagedObject { } } + /** + Please read the RFC. + */ var uids: MCOIndexSet { get { diff --git a/enzevalos_iphone/Folder+CoreDataProperties.swift b/enzevalos_iphone/Folder+CoreDataProperties.swift index a1f45577..89189882 100644 --- a/enzevalos_iphone/Folder+CoreDataProperties.swift +++ b/enzevalos_iphone/Folder+CoreDataProperties.swift @@ -22,9 +22,15 @@ extension Folder { @NSManaged public var keyRecords: NSSet? @NSManaged public var path: String //backendFolderPath @NSManaged public var lastUpdate: Date? + /** + Used for logging. + */ @NSManaged public var pseudonym: String @NSManaged public var icon: String? + /** + Please read the RFC! + */ public var uidvalidity: UInt32? { set { if let num = newValue { diff --git a/enzevalos_iphone/KeyRecord+CoreDataClass.swift b/enzevalos_iphone/KeyRecord+CoreDataClass.swift index 5b99b081..e95102f4 100644 --- a/enzevalos_iphone/KeyRecord+CoreDataClass.swift +++ b/enzevalos_iphone/KeyRecord+CoreDataClass.swift @@ -23,12 +23,17 @@ import CoreData import Contacts import UIKit +/** + Key records are mostly used in the inbox and for id (views). For each key we have a single key record. There are also key records for each mail address without keys, for instance when receiving unsigned mails. + + One person can have multiple key records, e.g. one with key, one without a key or multiple keys. + */ @objc(KeyRecord) public class KeyRecord: NSManagedObject, Record { public var isUser: Bool { get{ - /* + /** A keyrecord matches to the user if: * we know the secret key, because we are the key owner * the mail addresses matches @@ -45,6 +50,9 @@ public class KeyRecord: NSManagedObject, Record { } } + /** + Does the key record has a secret key? + */ public var isSecretKey: Bool { if let id = self.keyID { return DataHandler.handler.findSecretKey(keyID: id) != nil @@ -86,6 +94,11 @@ public class KeyRecord: NSManagedObject, Record { return nil } + + /** + MyNick is unique where as multiple key records can have the same name. + It is used to display different key records. + */ public var myNick: String { if let n = self.nick { return n @@ -109,6 +122,10 @@ public class KeyRecord: NSManagedObject, Record { return id } + /** + One person can have multiple key records, e.g. one with key, one without a key or multiple keys. + In case of multiple keys we have a primaryID. The key of this id is used for decryption etc. + */ public var isPrimaryID: Bool { if let keyID = self.keyID { for addr in self.addresses { @@ -129,6 +146,9 @@ public class KeyRecord: NSManagedObject, Record { } } + /** + It is the current fingerprint of the public key. + */ public var fingerprint: String? { get { if let k = pgpKey { @@ -154,12 +174,19 @@ public class KeyRecord: NSManagedObject, Record { } } + /** + EnzevalosContact provides some contact information about the key record. + */ public var ezContact: EnzevalosContact { get { return contact } } + + /** + Is a list of all received mails from this record. + */ public var mails: [PersistentMail] { get { if let m = persistentMails as? Set<PersistentMail> { @@ -168,7 +195,10 @@ public class KeyRecord: NSManagedObject, Record { return [] } } - + + /** + cnContact is the original corresponding contact in the address book. + */ public var cnContact: CNContact? { get { return contact.cnContact @@ -195,6 +225,9 @@ public class KeyRecord: NSManagedObject, Record { } } + /** + Corresponding mail addresses to the current key. + */ public var addresses: [MailAddress] { get { if let k = activeKey { diff --git a/enzevalos_iphone/Mail_Address+CoreDataClass.swift b/enzevalos_iphone/Mail_Address+CoreDataClass.swift index c7eb9a9b..17d570ce 100644 --- a/enzevalos_iphone/Mail_Address+CoreDataClass.swift +++ b/enzevalos_iphone/Mail_Address+CoreDataClass.swift @@ -25,7 +25,9 @@ import Contacts @objc(Mail_Address) open class Mail_Address: NSManagedObject, MailAddress { - + /** + What key should be used to send encrypted messages or to verify messages? + */ public var primaryKey: PersistentKey? { get { if hasKey { @@ -44,6 +46,9 @@ open class Mail_Address: NSManagedObject, MailAddress { return address.lowercased() } + /** + In the address book a mail address has a label (e.g. work, private, ...). + */ open var label: CNLabeledValue<NSString> { if let cnc = self.contact?.cnContact { for adr in cnc.emailAddresses { @@ -62,6 +67,9 @@ open class Mail_Address: NSManagedObject, MailAddress { return false } + /** + Is this a mail address of the user? + */ public var isUser: Bool { get { if let userAddr = UserManager.loadUserValue(Attribute.userAddr) as? String { @@ -71,6 +79,9 @@ open class Mail_Address: NSManagedObject, MailAddress { } } + /** + Just create a MCOAddress. Mailcore (our IMAP/SMTP library) needs MCOAddresses to send mails etc. + */ public func transform () -> MCOAddress { var name = address if let contact = contact { diff --git a/enzevalos_iphone/Mail_Address+CoreDataProperties.swift b/enzevalos_iphone/Mail_Address+CoreDataProperties.swift index fe549dcf..b627b37f 100644 --- a/enzevalos_iphone/Mail_Address+CoreDataProperties.swift +++ b/enzevalos_iphone/Mail_Address+CoreDataProperties.swift @@ -34,9 +34,18 @@ extension Mail_Address { @NSManaged public var cc: NSSet? @NSManaged public var from: NSSet? @NSManaged public var to: NSSet? + /** + Just for logging. + */ @NSManaged public var pseudonym: String - @NSManaged public var primaryKeyID: String? //TODO: set to private? + /** + What key should be used to send encrypted messages or to verify messages? + */ + @NSManaged public var primaryKeyID: String? @NSManaged private var keys: NSSet? + /** + Did we invited the mail address owner to use encryption? + */ @NSManaged public var invitations: Int16 var primaryActiveKeyID: String? { diff --git a/enzevalos_iphone/PersistentKey+CoreDataClass.swift b/enzevalos_iphone/PersistentKey+CoreDataClass.swift index 39181f2e..d908198e 100644 --- a/enzevalos_iphone/PersistentKey+CoreDataClass.swift +++ b/enzevalos_iphone/PersistentKey+CoreDataClass.swift @@ -9,6 +9,13 @@ import Foundation import CoreData +/** + Is a stored public key. + + It stores the keydata, some additional information and relations to key records etc. + + A key can be part of a key chain, such that one key introduced another key (yet not implemented) + */ @objc(PersistentKey) public class PersistentKey: NSManagedObject { @@ -44,6 +51,9 @@ public class PersistentKey: NSManagedObject { return self.verifiedDate != nil } + /** + Is the key expired (according to the crypto scheme)? + */ func isExpired() -> Bool { let pgp = SwiftPGP() if let key = pgp.loadKey(id: self.keyID) { diff --git a/enzevalos_iphone/PersistentKey+CoreDataProperties.swift b/enzevalos_iphone/PersistentKey+CoreDataProperties.swift index b1af66d5..74919be9 100644 --- a/enzevalos_iphone/PersistentKey+CoreDataProperties.swift +++ b/enzevalos_iphone/PersistentKey+CoreDataProperties.swift @@ -18,22 +18,62 @@ extension PersistentKey { @NSManaged public var keyID: String @NSManaged public var verifiedDate: Date? + /** + When did we received the last signed mail? + */ @NSManaged public var lastSeen: Date? + /** + When did we received the last mail with autocrypt header? + */ @NSManaged public var lastSeenAutocrypt: Date? + /** + When did we imported the key? + */ @NSManaged public var discoveryDate: Date? @NSManaged private var mailaddress: NSSet? + /** + What is the mail which contains this key (only the first)? + */ @NSManaged public var firstMail: PersistentMail? + /** + A pseudonym was used for logging. + */ @NSManaged public var pseudonym: String + /** + Did we send our own public key to the owner of this public key? + This means does the owner knows our public key? + */ @NSManaged public var sentOwnPublicKey: Bool @NSManaged public var signedMails: NSSet? @NSManaged private var record: KeyRecord? @NSManaged private var activeKey: PersistentKey? + /** + This is only for the travler scenario. You can ignore it. + */ @NSManaged public var activeRepeal: PersistentMail? + /** + Currently not used. + */ @NSManaged private var parentKey: PersistentKey? + /** + Currently not used. + */ @NSManaged private var childKeys: NSSet? + /** + This is only for the travler scenario. You can ignore it. + */ @NSManaged public var repealedByMails: NSSet? + /** + This is only for the travler scenario. You can ignore it. + */ @NSManaged private var isRepealed: Bool + /** + This is only for the travler scenario. You can ignore it. + */ @NSManaged private var gotFailedCallForUse: Bool + /** + This is only for the travler scenario. You can ignore it. + */ @NSManaged private var isMisstrusted: Bool var mailaddresses: NSSet? { @@ -64,6 +104,9 @@ extension PersistentKey { return parentKey != nil } + /** + Currently not used. + */ var rootKey: PersistentKey { get { var key = self @@ -100,7 +143,9 @@ extension PersistentKey { keys.append(rootKey) return keys } - + /** + This is only for the travler scenario. You can ignore it. + */ public var repealed: Bool { get { return rootKey.isRepealed @@ -109,7 +154,9 @@ extension PersistentKey { rootKey.isRepealed = newRepealState } } - + /** + This is only for the travler scenario. You can ignore it. + */ public var failedCallForUse: Bool { get { return rootKey.gotFailedCallForUse @@ -118,7 +165,9 @@ extension PersistentKey { rootKey.gotFailedCallForUse = newState } } - + /** + This is only for the travler scenario. You can ignore it. + */ public var misstrust: Bool { get { return rootKey.isMisstrusted @@ -127,7 +176,9 @@ extension PersistentKey { rootKey.isMisstrusted = trust } } - + /** + This is the autocrypt prefer enc state. + */ public var prefer_encryption: EncState{ set { let name = "preferEncryption" diff --git a/enzevalos_iphone/PersistentMail +CoreDataClass.swift b/enzevalos_iphone/PersistentMail +CoreDataClass.swift index e1ce1fe3..4764e26c 100644 --- a/enzevalos_iphone/PersistentMail +CoreDataClass.swift +++ b/enzevalos_iphone/PersistentMail +CoreDataClass.swift @@ -21,7 +21,16 @@ import Foundation import CoreData - +/** +A PersistentMail stores all information about one mail: + - Sender, receivers + - subject, date + - body + - encryption state + - signature state + - attached files, keys + +*/ @objc(PersistentMail) open class PersistentMail: NSManagedObject, Mail { public var predecessor: PersistentMail? = nil @@ -66,6 +75,9 @@ open class PersistentMail: NSManagedObject, Mail { } } + /** + This the signed first mail of the signed key? + */ var isNewPubKey: Bool { guard let signedKey = self.signedKey else { return false @@ -77,6 +89,9 @@ open class PersistentMail: NSManagedObject, Mail { return false } + /** + Just a flag if the user read this mail. + */ var isRead: Bool { get { let value = flag.contains(MCOMessageFlag.seen) @@ -92,6 +107,9 @@ open class PersistentMail: NSManagedObject, Mail { } } + /** + Just a flag if the user answered the mail. + */ var isAnwered: Bool { get { let value = flag.contains(MCOMessageFlag.answered) @@ -132,6 +150,10 @@ open class PersistentMail: NSManagedObject, Mail { return returnString } + /** + Just a short part of the body. Can be used for a preview. + In case of trouble there is no preview. + */ var shortBodyString: String? { guard !trouble else { return nil diff --git a/enzevalos_iphone/PersistentMail +CoreDataProperties.swift b/enzevalos_iphone/PersistentMail +CoreDataProperties.swift index 18fd66fe..e032c064 100644 --- a/enzevalos_iphone/PersistentMail +CoreDataProperties.swift +++ b/enzevalos_iphone/PersistentMail +CoreDataProperties.swift @@ -21,7 +21,6 @@ import Foundation import CoreData - extension PersistentMail { @nonobjc open override class func fetchRequest() -> NSFetchRequest<NSFetchRequestResult> { @@ -29,11 +28,20 @@ extension PersistentMail { } @NSManaged public var body: String? + /** + Deprecated + */ @NSManaged public var visibleBody: String? @NSManaged public var decryptedBody: String? @NSManaged public var encryptedBody: String? @NSManaged public var date: Date - @NSManaged public var secretKey: String? // secret key which is in the mail (to import) + /** + secret key which is attacted to the mail (to import) + */ + @NSManaged public var secretKey: String? + /** + The corresponding key record + */ @NSManaged public var record: KeyRecord? public var hasAttachment: Bool { @@ -45,6 +53,9 @@ extension PersistentMail { } } + /** + Some mail flags, e.g. read flag, answered flag (according to RFC) + */ public var flag: MCOMessageFlag { set { if newValue != flag { @@ -68,28 +79,86 @@ extension PersistentMail { } } + /** + Please use encryption state + */ @NSManaged public var isEncrypted: Bool + /** + This mail is signed but check isSigned, too. + We recommand to use signature state + */ @NSManaged public var isSigned: Bool + /** + We could verify the signature (with a given public key) + */ @NSManaged public var isCorrectlySigned: Bool + /** + This mail is encrypted but we could not decrypt the message (e.g. the secret key is missing) + */ @NSManaged public var unableToDecrypt: Bool + /** + Subject of a mail (according to RFC) + */ @NSManaged public var subject: String? + /** + Which folder is used to store the mail? + */ @NSManaged public var folder: Folder - @NSManaged public var firstKey: PersistentKey? // NOT USED + /** + Not used. + */ + @NSManaged public var firstKey: PersistentKey? + /** + What key is the signature key of this mail? + */ @NSManaged public var signedKey: PersistentKey? + /** + Did we received the mail? + */ @NSManaged public var received: Bool + /** + Only used in traveler scenario. + */ @NSManaged public var deleteWhileTravel: Bool + /** + Only used in traveler scenario. + */ @NSManaged public var storeEncrypted: Bool + /** + Only used in traveler scenario. + */ @NSManaged public var repealsKey: PersistentKey? + /** + This can be used for threading. This is defined in a RFC. + */ @NSManaged public var gmailMessageID: NSNumber? + /** + This can be used for threading. This is defined in a RFC. + */ @NSManaged public var gmailThreadID: NSNumber? + /** + Please read up this mail in the RFC! + */ @NSManaged public var messageID: String? + /** + Currently not used. + */ @NSManaged public var notLoadedMessages: String? - @NSManaged public var decryptedKey: PersistentKey? // Only for traveler scenario - + /** + Only for traveler scenario. + */ + @NSManaged public var decryptedKey: PersistentKey? + + /** + Sender mail client. + */ @NSManaged public var xMailer: String? - + /** + Key id of the signature key. + TODO rename to signedKeyID + */ public var keyID: String? { set { self.willChangeValue(forKey: "keyID") @@ -116,6 +185,9 @@ extension PersistentMail { } + /** + Does this mail has some (crypto) errors, e.g. manipulated encryption or signature? + */ public var trouble: Bool { set { self.willChangeValue(forKey: "trouble") @@ -130,6 +202,9 @@ extension PersistentMail { } } + /** + Please read the RFC! + */ public var uid: UInt64 { set { self.willChangeValue(forKey: "uid") @@ -146,6 +221,9 @@ extension PersistentMail { return 0 } } + /** + Please read the RFC! + */ public var uidvalidity: UInt32? { set { if let num = newValue { @@ -215,6 +293,9 @@ extension PersistentMail { } + /** + Enter a password and if possible import the secret keys. + */ public func processSecretKey(pw: String?) throws -> Bool { var sk = "" if let key = secretKey { @@ -232,6 +313,9 @@ extension PersistentMail { @NSManaged public var cc: NSSet? @NSManaged public var to: NSSet @NSManaged public var attachments: NSSet? + /** + Can be used for threading. Please read the RFC. + */ @NSManaged public var referenceMails: NSSet? } diff --git a/enzevalos_iphone/SecretKey+CoreDataProperties.swift b/enzevalos_iphone/SecretKey+CoreDataProperties.swift index 2bb74ef7..47d46811 100644 --- a/enzevalos_iphone/SecretKey+CoreDataProperties.swift +++ b/enzevalos_iphone/SecretKey+CoreDataProperties.swift @@ -10,19 +10,39 @@ import Foundation import CoreData - +/** + + */ extension SecretKey { @nonobjc public class func fetchRequest() -> NSFetchRequest<SecretKey> { return NSFetchRequest<SecretKey>(entityName: "SecretKey") } + /** + Did we exported the secretkey? + */ @NSManaged public var exported: Bool + /** + When did we import the secretkey? + */ @NSManaged public var importedDate: NSDate? @NSManaged public var keyID: String + /** + Used in the travler scenario. Just ignore it. + */ @NSManaged public var obsolete: Bool + /** + Not used yet. Should store how we imported the key (generated on device, imported from mail via autorcrypt, via iTunes, ...) + */ @NSManaged public var origin: Int16 + /** + Just added in case of multiple accounts. + */ @NSManaged public var account: Account? + /** + A Set of mails where as the key was used for decryption. + */ @NSManaged public var decryptedMails: NSSet? } -- GitLab