Skip to content

Commit 40cf7bc

Browse files
committed
password: fix sequencer documentation
1 parent c012590 commit 40cf7bc

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

password/sequencer.go

+7-15
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,23 @@ import (
66
"math/big"
77
"math/rand/v2"
88
"sync"
9-
"time"
109
)
1110

1211
var (
1312
biZero = big.NewInt(0)
1413
biOne = big.NewInt(1)
1514
)
1615

16+
// Sequencer is a deterministic Password Generator that generates all possible
17+
// combinations of passwords for a Charset and defined number of characters in
18+
// the password. It lets you move back and forth through the list of possible
19+
// passwords, and involves no RNG.
1720
type Sequencer interface {
1821
// First moves to the first possible password and returns the same.
1922
First() string
2023
// Get returns the current password in the sequence.
2124
Get() string
22-
// GetN returns the password at location N, given 0 <= N < MaxPossibleWords
25+
// GetN returns the value for N (location in list of possible passwords).
2326
GetN() *big.Int
2427
// GotoN overrides N.
2528
GotoN(n *big.Int) (string, error)
@@ -37,8 +40,6 @@ type Sequencer interface {
3740
PrevN(n *big.Int) string
3841
// Reset cleans up state and moves to the first possible word.
3942
Reset()
40-
// SetSeed overrides the seed value for the RNG.
41-
SetSeed(seed uint64)
4243
// Stream sends all possible passwords in order to the given channel. If you
4344
// want to limit output, pass in a *big.Int with the number of passwords you
4445
// want to be generated and streamed.
@@ -65,7 +66,6 @@ type sequencer struct {
6566
// interface.
6667
func NewSequencer(rules ...Rule) (Sequencer, error) {
6768
s := &sequencer{}
68-
s.SetSeed(uint64(time.Now().UnixNano()))
6969
for _, rule := range append(basicRules, rules...) {
7070
rule(s)
7171
}
@@ -110,15 +110,15 @@ func (s *sequencer) Get() string {
110110
return s.get()
111111
}
112112

113-
// GetN returns the password at location N, given 0 <= N <= MaxPossibleWords
113+
// GetN returns the current location in the list of possible passwords.
114114
func (s *sequencer) GetN() *big.Int {
115115
s.mutex.Lock()
116116
defer s.mutex.Unlock()
117117

118118
return new(big.Int).Set(s.n)
119119
}
120120

121-
// GotoN overrides N.
121+
// GotoN overrides the current location in the list of possible passwords.
122122
func (s *sequencer) GotoN(n *big.Int) (string, error) {
123123
s.mutex.Lock()
124124
defer s.mutex.Unlock()
@@ -201,14 +201,6 @@ func (s *sequencer) Reset() {
201201
s.First()
202202
}
203203

204-
// SetSeed changes the seed value of the RNG.
205-
func (s *sequencer) SetSeed(seed uint64) {
206-
s.mutex.Lock()
207-
defer s.mutex.Unlock()
208-
209-
s.rng = rand.New(rand.NewPCG(seed, seed+100))
210-
}
211-
212204
// Stream sends all possible passwords in order to the given channel. If you
213205
// want to limit output, pass in a *big.Int with the number of passwords you
214206
// want to be generated and streamed.

0 commit comments

Comments
 (0)