 }
 
 public extension Generator {
+    /**
+    Calculates the current password based on the generator's configuration. The password generated
+    will be constant for a counter-based generator, but for a timer-based generator the password
+    will depend on the current time when this method is called.
+
+    Note: Calling this method does *not* increment the counter of a counter-based generator.
+
+    :returns: The current password, or `nil` if a password could not be generated.
+    */
     var password: String? {
         if !validateGenerator(factor, secret, algorithm, digits) { return nil }
         let counter = counterForGeneratorWithFactor(self.factor, atTimeIntervalSince1970: NSDate().timeIntervalSince1970)


import Foundation

public struct Generator: Equatable {
    public let factor: Factor
    public let secret: NSData
    public let algorithm: Algorithm
    public let digits: Int

    public init?(factor: Factor, secret: NSData, algorithm: Algorithm = .SHA1, digits: Int = 6) {
        if !validateGenerator(factor, secret, algorithm, digits) {
            return nil

        self.digits = digits
    }

    /**
    A moving factor with which a generator produces different one-time passwords over time.
    
    Counter:
      Indicates a HOTP, with an associated 8-byte counter value for the moving factor. After
      each use of the password generator, the counter should be incremented to stay in sync with
      the server.
    Timer:
      Indicates a TOTP, with an associated time interval for calculating the time-based moving
      factor. This period value remains constant, and is used as a divisor for the number of
      seconds since the Unix epoch.
    */
    public enum Factor: Equatable {
        case Counter(UInt64)
        case Timer(period: NSTimeInterval)
    }

    /// A cryptographic hash function used to calculate the HMAC from which a password is derived.
    /// The supported algorithms are SHA-1, SHA-256, and SHA-512
    public enum Algorithm: Equatable {
        case SHA1, SHA256, SHA512
    }
