2018-11-11 18:09:52 +01:00
|
|
|
//
|
|
|
|
|
// Constants.swift
|
|
|
|
|
// passKit
|
|
|
|
|
//
|
|
|
|
|
// Created by Danny Moesch on 16.08.18.
|
|
|
|
|
// Copyright © 2018 Bob Sun. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
public struct Constants {
|
|
|
|
|
|
2018-11-14 21:29:25 +01:00
|
|
|
static let OTP_SECRET = "otp_secret"
|
|
|
|
|
static let OTP_TYPE = "otp_type"
|
|
|
|
|
static let OTP_ALGORITHM = "otp_algorithm"
|
|
|
|
|
static let OTP_PERIOD = "otp_period"
|
|
|
|
|
static let OTP_DIGITS = "otp_digits"
|
|
|
|
|
static let OTP_COUNTER = "otp_counter"
|
|
|
|
|
static let OTPAUTH = "otpauth"
|
|
|
|
|
|
2018-11-11 18:09:52 +01:00
|
|
|
public static let OTP_KEYWORDS = [
|
2018-11-14 21:29:25 +01:00
|
|
|
OTP_SECRET,
|
|
|
|
|
OTP_TYPE,
|
|
|
|
|
OTP_ALGORITHM,
|
|
|
|
|
OTP_PERIOD,
|
|
|
|
|
OTP_DIGITS,
|
|
|
|
|
OTP_COUNTER,
|
|
|
|
|
OTPAUTH,
|
2018-11-11 18:09:52 +01:00
|
|
|
]
|
|
|
|
|
|
2018-11-14 21:29:25 +01:00
|
|
|
static let TOTP = "totp"
|
|
|
|
|
static let HOTP = "hotp"
|
|
|
|
|
static let SHA256 = "sha256"
|
|
|
|
|
static let SHA512 = "sha512"
|
2018-12-01 15:53:48 +01:00
|
|
|
static let DEFAULT_DIGITS = 6
|
|
|
|
|
static let DEFAULT_PERIOD = 30.0
|
|
|
|
|
static let DEFAULT_COUNTER: UInt64? = nil
|
2018-11-14 21:29:25 +01:00
|
|
|
|
2018-11-11 18:09:52 +01:00
|
|
|
static let BLANK = " "
|
|
|
|
|
static let MULTILINE_WITH_LINE_BREAK_INDICATOR = "|"
|
|
|
|
|
static let MULTILINE_WITH_LINE_BREAK_SEPARATOR = "\n"
|
|
|
|
|
static let MULTILINE_WITHOUT_LINE_BREAK_INDICATOR = ">"
|
|
|
|
|
static let MULTILINE_WITHOUT_LINE_BREAK_SEPARATOR = BLANK
|
|
|
|
|
|
|
|
|
|
static let OTPAUTH_URL_START = "\(OTPAUTH)://"
|
2018-12-15 21:48:35 +01:00
|
|
|
|
|
|
|
|
public static let PASSWORD_KEYWORD = "password"
|
|
|
|
|
public static let USERNAME_KEYWORD = "username"
|
|
|
|
|
public static let LOGIN_KEYWORD = "login"
|
|
|
|
|
public static let URL_KEYWORD = "url"
|
|
|
|
|
public static let UNKNOWN = "unknown"
|
2018-11-11 18:09:52 +01:00
|
|
|
|
|
|
|
|
public static func isOtpRelated(line: String) -> Bool {
|
|
|
|
|
let (key, _) = Parser.getKeyValuePair(from: line)
|
2018-12-08 00:56:22 +01:00
|
|
|
return key != nil && isOtpKeyword(key!)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static func isOtpKeyword(_ keyword: String) -> Bool {
|
|
|
|
|
return OTP_KEYWORDS.contains(keyword.lowercased())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static func isUnknown(_ string: String) -> Bool {
|
|
|
|
|
return string.starts(with: UNKNOWN)
|
2018-11-11 18:09:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static func unknown(_ number: UInt) -> String {
|
|
|
|
|
return "\(UNKNOWN) \(number)"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static func getSeparator(breakingLines: Bool) -> String {
|
|
|
|
|
return breakingLines ? MULTILINE_WITH_LINE_BREAK_SEPARATOR : MULTILINE_WITHOUT_LINE_BREAK_SEPARATOR
|
|
|
|
|
}
|
|
|
|
|
}
|