Skip to content

Commit

Permalink
Add comments to public functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Mobilpadde committed Mar 7, 2023
1 parent 0f1616c commit a9f635a
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions token/checks/checkAmount.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"github.com/Mobilpadde/moths/v5/token/errs"
)

// CheckAmount is used to check
// if the length of a token can be used.
func CheckAmount(amount int) error {
if amount < 1 {
return errs.ErrAmount1
Expand Down
2 changes: 2 additions & 0 deletions token/checks/checkEmojies.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"github.com/Mobilpadde/moths/v5/token/errs"
)

// CheckEmojies is used to check
// if enough emojies are specified.
func CheckEmojies(emojies emojies.Emojies) error {
if len(emojies) < 1 {
return errs.ErrEmojies1
Expand Down
2 changes: 2 additions & 0 deletions token/checks/checkPeriod.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/Mobilpadde/moths/v5/token/errs"
)

// CheckPeriod is used to check
// if the period of validity is long enough.
func CheckPeriod(period time.Duration) error {
if period.Milliseconds() < 1000 {
return errs.ErrPeriod1
Expand Down
2 changes: 2 additions & 0 deletions token/checks/checkSecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package checks

import "github.com/Mobilpadde/moths/v5/token/errs"

// CheckSecret is used to check
// if the provided secret is "strong" enough.
func CheckSecret(secret string) error {
if len(secret) == 0 {
return errs.ErrSecretLength
Expand Down
3 changes: 3 additions & 0 deletions token/code/newCode.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (

const EmojiBytes = 4

// NewCode creates a new code
//
// This is generally not for public usage.
func NewCode(token string, amount int, em emojies.Emojies, createdAt time.Time, expiresAt time.Time) (Code, error) {
code, err := generateCode(token, amount, em)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions token/emojies/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package emojies

import "unicode/utf8"

// ToEmojies can be used to convert a
// slice of strings to [Emojies].
func ToEmojies(emojies []string) Emojies {
em := Emojies{}

Expand Down
2 changes: 2 additions & 0 deletions token/newGenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/Mobilpadde/moths/v5/token/checks"
)

// NewGenerator creates a new token generator
// with the given [Option]s.
func NewGenerator(opts ...Option) (*Generator, error) {
m := &Generator{
amount: 6, // Defaults to `6` as most other TOTP codes are this length
Expand Down
2 changes: 2 additions & 0 deletions token/optionAmount.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"github.com/Mobilpadde/moths/v5/token/checks"
)

// OptionWithAmount is used to specify
// the amount of emojies in a code.
func OptionWithAmount(amount int) Option {
return func(m *Generator) error {
if err := checks.CheckAmount(amount); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions token/optionEmojies.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"github.com/Mobilpadde/moths/v5/token/emojies"
)

// OptionWithEmojies is used to specify
// which emojies that can be used in
// any given code.
func OptionWithEmojies(emojies emojies.Emojies) Option {
return func(m *Generator) error {
if err := checks.CheckEmojies(emojies); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions token/optionPeriod.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/Mobilpadde/moths/v5/token/checks"
)

// OptionWithPeriod is used to specify
// how long a code will remain valid.
func OptionWithPeriod(period time.Duration) Option {
return func(m *Generator) error {
if err := checks.CheckPeriod(period); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions token/optionSecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/Mobilpadde/moths/v5/token/checks"
)

// OptionWithSecret is used to specify
// the secret to generate codes from.
func OptionWithSecret(secret string) Option {
return func(m *Generator) error {
if err := checks.CheckSecret(secret); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions token/optionTime.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ package token

import "time"

// OptionWithTime is used to specify
// a custom time to generate code from.
//
// If none is specified, the current time
// will be used.
func OptionWithTime(t time.Time) Option {
return func(m *Generator) error {
m.timing.time = t
Expand Down

0 comments on commit a9f635a

Please sign in to comment.