Skip to content

Commit 6d80748

Browse files
refactor: module
1 parent 87d222c commit 6d80748

File tree

10 files changed

+59
-49
lines changed

10 files changed

+59
-49
lines changed

doc.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
// Authenticator supports using a QR code as an enrollment method:
2828
//
2929
// import (
30-
// "github.com/pquerna/otp/totp"
30+
// "github.com/authelia/otp/totp"
3131
//
3232
// "bytes"
3333
// "image/png"
@@ -58,7 +58,7 @@
5858
// Validating a TOTP passcode is very easy, just prompt the user for a passcode
5959
// and retrieve the associated user's previously stored secret.
6060
//
61-
// import "github.com/pquerna/otp/totp"
61+
// import "github.com/authelia/otp/totp"
6262
//
6363
// passcode := promptForPasscode()
6464
// secret := getSecret("[email protected]")

example/main.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package main
22

33
import (
4-
"github.com/pquerna/otp"
5-
"github.com/pquerna/otp/totp"
4+
"github.com/authelia/otp"
5+
"github.com/authelia/otp/totp"
66

77
"bufio"
88
"bytes"
@@ -34,18 +34,18 @@ func promptForPasscode() string {
3434

3535
// Demo function, not used in main
3636
// Generates Passcode using a UTF-8 (not base32) secret and custom parameters
37-
func GeneratePassCode(utf8string string) string{
38-
secret := base32.StdEncoding.EncodeToString([]byte(utf8string))
39-
passcode, err := totp.GenerateCodeCustom(secret, time.Now(), totp.ValidateOpts{
40-
Period: 30,
41-
Skew: 1,
42-
Digits: otp.DigitsSix,
43-
Algorithm: otp.AlgorithmSHA512,
44-
})
45-
if err != nil {
46-
panic(err)
47-
}
48-
return passcode
37+
func GeneratePassCode(utf8string string) string {
38+
secret := base32.StdEncoding.EncodeToString([]byte(utf8string))
39+
passcode, err := totp.GenerateCodeCustom(secret, time.Now(), totp.ValidateOpts{
40+
Period: 30,
41+
Skew: 1,
42+
Digits: otp.DigitsSix,
43+
Algorithm: otp.AlgorithmSHA512,
44+
})
45+
if err != nil {
46+
panic(err)
47+
}
48+
return passcode
4949
}
5050

5151
func main() {

go.mod

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
module github.com/pquerna/otp
1+
module github.com/authelia/otp
22

3-
go 1.12
3+
go 1.21
44

55
require (
6-
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc
7-
github.com/stretchr/testify v1.3.0
6+
github.com/boombuler/barcode v1.0.1
7+
github.com/stretchr/testify v1.8.4
8+
)
9+
10+
require (
11+
github.com/davecgh/go-spew v1.1.1 // indirect
12+
github.com/pmezard/go-difflib v1.0.0 // indirect
13+
gopkg.in/yaml.v3 v3.0.1 // indirect
814
)

go.sum

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc h1:biVzkmvwrH8WK8raXaxBx6fRVTlJILwEwQGL1I/ByEI=
2-
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
3-
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
4-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1+
github.com/boombuler/barcode v1.0.1 h1:NDBbPmhS+EqABEs5Kg3n/5ZNjy73Pz7SIV+KCeqyXcs=
2+
github.com/boombuler/barcode v1.0.1/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
3+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
4+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
55
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
66
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
8-
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
9-
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
7+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
8+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
9+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
10+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
11+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
12+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

hotp/hotp.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@
1818
package hotp
1919

2020
import (
21-
"github.com/pquerna/otp"
22-
"github.com/pquerna/otp/internal"
23-
"io"
24-
2521
"crypto/hmac"
2622
"crypto/rand"
2723
"crypto/subtle"
2824
"encoding/base32"
2925
"encoding/binary"
3026
"fmt"
27+
"io"
3128
"math"
3229
"net/url"
3330
"strings"
31+
32+
"github.com/authelia/otp"
33+
"github.com/authelia/otp/internal"
3434
)
3535

3636
const debug = false

hotp/hotp_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package hotp
1919

2020
import (
21-
"github.com/pquerna/otp"
21+
"github.com/authelia/otp"
2222
"github.com/stretchr/testify/assert"
2323
"github.com/stretchr/testify/require"
2424

@@ -78,15 +78,15 @@ func TestGenerateRFCMatrix(t *testing.T) {
7878
}
7979
}
8080

81-
func TestGenerateCodeCustom(t *testing.T){
81+
func TestGenerateCodeCustom(t *testing.T) {
8282
secSha1 := base32.StdEncoding.EncodeToString([]byte("12345678901234567890"))
8383

84-
code, err := GenerateCodeCustom("foo",1,ValidateOpts{})
84+
code, err := GenerateCodeCustom("foo", 1, ValidateOpts{})
8585
print(code)
8686
require.Equal(t, otp.ErrValidateSecretInvalidBase32, err, "Decoding of secret as base32 failed.")
8787
require.Equal(t, "", code, "Code should be empty string when we have an error.")
8888

89-
code, err = GenerateCodeCustom(secSha1,1,ValidateOpts{})
89+
code, err = GenerateCodeCustom(secSha1, 1, ValidateOpts{})
9090
require.Equal(t, 6, len(code), "Code should be 6 digits when we have not an error.")
9191
require.NoError(t, err, "Expected no error.")
9292
}
@@ -98,7 +98,7 @@ func TestValidateInvalid(t *testing.T) {
9898
ValidateOpts{
9999
Digits: otp.DigitsSix,
100100
Algorithm: otp.AlgorithmSHA1,
101-
})
101+
})
102102
require.Equal(t, otp.ErrValidateInputInvalidLength, err, "Expected Invalid length error.")
103103
require.Equal(t, false, valid, "Valid should be false when we have an error.")
104104

interop/go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module github.com/pquerna/otp/interop
1+
module github.com/authelia/otp/interop
22

3-
go 1.12
3+
go 1.21

interop/twofactor_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ import (
2222
"time"
2323

2424
"github.com/gokyle/twofactor"
25-
"github.com/pquerna/otp"
26-
"github.com/pquerna/otp/totp"
2725
"github.com/stretchr/testify/require"
26+
27+
"github.com/authelia/otp"
28+
"github.com/authelia/otp/totp"
2829
)
2930

3031
func TestTwoFactor(t *testing.T) {

totp/totp.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818
package totp
1919

2020
import (
21-
"github.com/pquerna/otp"
22-
"github.com/pquerna/otp/hotp"
23-
"github.com/pquerna/otp/internal"
24-
"io"
25-
2621
"crypto/rand"
2722
"encoding/base32"
23+
"io"
2824
"math"
2925
"net/url"
3026
"strconv"
3127
"time"
28+
29+
"github.com/authelia/otp"
30+
"github.com/authelia/otp/hotp"
31+
"github.com/authelia/otp/internal"
3232
)
3333

3434
// Validate a TOTP using the current time.

totp/totp_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
package totp
1919

2020
import (
21-
"github.com/pquerna/otp"
21+
"github.com/authelia/otp"
2222
"github.com/stretchr/testify/assert"
2323
"github.com/stretchr/testify/require"
2424

@@ -61,14 +61,14 @@ var (
6161
}
6262
)
6363

64-
//
6564
// Test vectors from http://tools.ietf.org/html/rfc6238#appendix-B
6665
// NOTE -- the test vectors are documented as having the SAME
6766
// secret -- this is WRONG -- they have a variable secret
6867
// depending upon the hmac algorithm:
69-
// http://www.rfc-editor.org/errata_search.php?rfc=6238
70-
// this only took a few hours of head/desk interaction to figure out.
7168
//
69+
// http://www.rfc-editor.org/errata_search.php?rfc=6238
70+
//
71+
// this only took a few hours of head/desk interaction to figure out.
7272
func TestValidateRFCMatrix(t *testing.T) {
7373
for _, tx := range rfcMatrixTCs {
7474
valid, err := ValidateCustom(tx.TOTP, tx.Secret, time.Unix(tx.TS, 0).UTC(),

0 commit comments

Comments
 (0)