Simplify code
This commit is contained in:
parent
9e027b878a
commit
64956c6643
2 changed files with 7 additions and 9 deletions
|
|
@ -21,6 +21,7 @@ public class Password {
|
||||||
private var parser = Parser(plainText: "")
|
private var parser = Parser(plainText: "")
|
||||||
private var additions = [AdditionField]()
|
private var additions = [AdditionField]()
|
||||||
private var firstLineIsOTPField = false
|
private var firstLineIsOTPField = false
|
||||||
|
|
||||||
private var otpToken: Token? {
|
private var otpToken: Token? {
|
||||||
didSet {
|
didSet {
|
||||||
otpType = OtpType(token: otpToken)
|
otpType = OtpType(token: otpToken)
|
||||||
|
|
@ -82,11 +83,11 @@ public class Password {
|
||||||
|
|
||||||
if self.plainText != plainText {
|
if self.plainText != plainText {
|
||||||
self.plainText = plainText
|
self.plainText = plainText
|
||||||
changed = changed|PasswordChange.content.rawValue
|
changed |= PasswordChange.content.rawValue
|
||||||
}
|
}
|
||||||
if self.url != url {
|
if self.url != url {
|
||||||
self.url = url
|
self.url = url
|
||||||
changed = changed|PasswordChange.path.rawValue
|
changed |= PasswordChange.path.rawValue
|
||||||
}
|
}
|
||||||
|
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
@ -171,7 +172,7 @@ public class Password {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
var description = otpType.description
|
var description = otpType.description
|
||||||
if case let .timer(period)? = otpToken?.generator.factor {
|
if case let .timer(period) = otpToken!.generator.factor {
|
||||||
let timeSinceEpoch = Date().timeIntervalSince1970
|
let timeSinceEpoch = Date().timeIntervalSince1970
|
||||||
let validTime = Int(period - timeSinceEpoch.truncatingRemainder(dividingBy: period))
|
let validTime = Int(period - timeSinceEpoch.truncatingRemainder(dividingBy: period))
|
||||||
description += " (expires in \(validTime)s)"
|
description += " (expires in \(validTime)s)"
|
||||||
|
|
|
||||||
|
|
@ -12,14 +12,11 @@ import SwiftyUserDefaults
|
||||||
extension PasswordEntity {
|
extension PasswordEntity {
|
||||||
|
|
||||||
public var nameWithCategory: String {
|
public var nameWithCategory: String {
|
||||||
get {
|
|
||||||
if let p = path, p.hasSuffix(".gpg") {
|
if let p = path, p.hasSuffix(".gpg") {
|
||||||
return String(p.prefix(upTo: p.index(p.endIndex, offsetBy: -4)))
|
return String(p.prefix(upTo: p.index(p.endIndex, offsetBy: -4)))
|
||||||
} else {
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public func getCategoryText() -> String {
|
public func getCategoryText() -> String {
|
||||||
return getCategoryArray().joined(separator: " > ")
|
return getCategoryArray().joined(separator: " > ")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue