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 implementation

    Validates 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) throws

    Parameters

    digits

    The length of the code to be generated

  • validateGeneratorAlgorithm(_:) Default implementation

    Ensure 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) throws

    Parameters

    generatorAlgorithm

    The generator algorithm to verify

  • validateTime(_:) Default implementation

    Validate that the requested time to generate a token against is not before the UNIX reference time

    Default Implementation

    Declaration

    Swift

    static func validateTime(_ timeSinceEpoch: TimeInterval) throws

    Parameters

    timeSinceEpoch

    Time since UNIX reference in seconds

  • validatePeriod(_:) Default implementation

    Validate often the token should change (should be a positive number)

    Default Implementation

    Declaration

    Swift

    static func validatePeriod(_ period: TimeInterval) throws

    Parameters

    period

    Duration of time in seconds

  • A Base32 shared secret

    Declaration

    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 implementation

    Creates a one-time password

    Default Implementation

    Declaration

    Swift

    func generate(with date: Date) throws -> String

    Parameters

    date

    Seed date to generate from, must be in the future