Add last night's progress.

Basic functionality for HOTP, TOTP, and YubiKey OTP. Still need YubiKey
HMAC, serialisation, check, and scan.
This commit is contained in:
Kyle Isom
2013-12-20 17:00:01 -07:00
parent 1dec15fd11
commit 0982f47ce3
9 changed files with 386 additions and 29 deletions

13
otp.go
View File

@@ -13,6 +13,7 @@ type Type uint
const (
OATH_HOTP = iota
OATH_TOTP
YUBIKEY
)
// PRNG is an io.Reader that provides a cryptographically secure
@@ -47,24 +48,20 @@ type OTP interface {
// the hash function used by the OTP
Hash() func() hash.Hash
// URL generates a Google Authenticator url (or perhaps some other url)
URL(string) string
// QR outputs a byte slice containing a PNG-encoded QR code
// of the URL.
QR(string) ([]byte, error)
// Returns the type of this OTP.
Type() Type
}
func OTPString(otp OTP) string {
func otpString(otp OTP) string {
var typeName string
switch otp.Type() {
case OATH_HOTP:
typeName = "OATH-HOTP"
case OATH_TOTP:
typeName = "OATH-TOTP"
case YUBIKEY:
return fmt.Sprintf("YubiKey with %d byte public identity",
len(otp.(*YubiKey).Public()))
}
return fmt.Sprintf("%s, %d", typeName, otp.Size())
}