GeneratorProtocol
@available(iOS 13.0, OSX 10.15, watchOS 6.0, tvOS 13.0, *)
public protocol GeneratorProtocol
A type that can represent a generator for a given type of one-time password
This object is used for validation as well as storage for the actual algorithm generation data
-
validateDigits(_:)Default implementationValidates the number of digits to generate
the suggested number of digits is 6-8, as stated by RFC6238.
Default Implementation
Declaration
Swift
static func validateDigits(_ digits: Int) throwsParameters
digitsThe length of the code to be generated
-
validateGeneratorAlgorithm(_:)Default implementationEnsure that the given generation algorithm is valid
Default Implementation
Counter’s aren’t validated, but the period but be great than 0 So we do validate that.
Declaration
Swift
static func validateGeneratorAlgorithm(_ generatorAlgorithm: GeneratorAlgorithm) throwsParameters
generatorAlgorithmThe generator algorithm to verify
-
validateTime(_:)Default implementationValidate that the requested time to generate a token against is not before the
UNIXreference timeDefault Implementation
Declaration
Swift
static func validateTime(_ timeSinceEpoch: TimeInterval) throwsParameters
timeSinceEpochTime since UNIX reference in seconds
-
validatePeriod(_:)Default implementationValidate often the token should change (should be a positive number)
Default Implementation
Declaration
Swift
static func validatePeriod(_ period: TimeInterval) throwsParameters
periodDuration of time in seconds
-
A
Base32shared secretDeclaration
Swift
var secret: Data { get } -
The length of the code to be generated
Declaration
Swift
var digits: Int { get } -
Generator algorithm being used
Declaration
Swift
var generatorAlgorithm: GeneratorAlgorithm { get } -
Hash function being used
Declaration
Swift
var hashAlgorithm: SupportedHashAlgorithm { get } -
generate(with:)Default implementationCreates a one-time password
Default Implementation
Declaration
Swift
func generate(with date: Date) throws -> StringParameters
dateSeed date to generate from, must be in the future
GeneratorProtocol Protocol Reference