state

package
v3.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sign

func Sign(key []byte, message string) string

Sign generates a state string signed with SHA3 256. It is useful for OAuth2 or Webhook callback. base64RawURL(8 bytes time + 8 bytes nonce + 32 bytes sha3 256)

fmt.Println(Sign([]byte("my key"), ""))
// zILSqgsAAACNRsElhX2IP-HqOmhKKSMJDNv2f7G2ONo-ULM4G4zppTWTiSDKwCjc
fmt.Println(Sign([]byte("my key"), "some message"))
// zILSqgsAAAA01z-LM1BfpaW9l7dK9zPUUJZl1P0_Jr4yEgYWHSQ_bFeiGFKA6qq6

func Verify

func Verify(key []byte, message, state string, expire ...time.Duration) bool

Verify Verify state that generated by Sign.

fmt.Println(Verify([]byte("my key"), "", state, 60 * time.Second)

Types

type States

type States struct {
	// contains filtered or unexported fields
}

States is a rotating Sign/Verify struct.

func New

func New(keys ...[]byte) (*States, error)

New creates an instance of States.

func (*States) Sign

func (s *States) Sign(message string) string

Sign generates a state string signed with SHA3 256. base64RawURL(8 bytes time + 8 bytes nonce + 32 bytes sha3 256)

func (*States) Verify

func (s *States) Verify(message, state string, expire ...time.Duration) bool

Verify Verify state that generated by Sign.

Jump to

Keyboard shortcuts

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