gotopt

package module
v0.0.0-...-e4b530a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2015 License: Apache-2.0 Imports: 11 Imported by: 0

README

gotopt: A basic package to generate/validate TOPT (RFC6238)

Build Status GoDoc

Usage

package main

import(
   "fmt"
   "github.com/sheepkiller/gotopt"
   "os"
   "time"
)

func main() {
   token, remain, err := gotopt.GetTOPT("AAAAAAAAAAAAAAAA", 6, "sha1")
   if err != nil {
      fmt.Printf("Error: %s\n", err.Error())
      os.Exit(1)
   }
   fmt.Printf("TOPT: %s will expire in %d seconds\n", token, remain)
   valid, err:= gotopt.ValidateTOPT("AAAAAAAAAAAAAAAA", 6, "sha1", token, 0)
   if valid {
      fmt.Println("token is valid")
   }
   time.Sleep(30 * time.Second)
   valid, err= gotopt.ValidateTOPT("AAAAAAAAAAAAAAAA", 6, "sha1", token, 0)
   if valid {
      fmt.Println("token is valid")
   } else {
      fmt.Println("token is invalid")
   }
   valid, err= gotopt.ValidateTOPT("AAAAAAAAAAAAAAAA", 6, "sha1", token, 1)
   if valid {
      fmt.Println("token is valid")
   } else {
      fmt.Println("token is invalid")
   }
}

References

This work is based on:

Documentation

Overview

Package to generate/validate TOPT from 4 to 8 digits with SHA1/SHA256/SHA512 hash functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTOPT

func GetTOPT(str_secret string, digits int, shaX string) (str_token string, remain uint64, err error)

Generate a TOPT

str_secret: secret key (strict base32)
digits: number of digits (from 4 to 8)
shaX: hash function (SHA1, SHA256, or SHA512)

returns:

str_token: string representation of token (type string)
remain: remaining validity time (type uint64)
err: error

func ValidateTOPT

func ValidateTOPT(str_secret string, digits int, shaX string, topt string, interval int) (valid_token bool, err error)

Validate a TOPT

str_secret: secret key (strict base32)
digits: number of digits (from 4 to 8)
shaX: hash function (SHA1, SHA256, or SHA512)
topt: token to validate (type string)
interval: validate against previous interval window (30s)

returns

valid_token: boolean : true if valid, false if not
err: error

XXX: need test

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL