Skip to content

Commit 3cd3734

Browse files
authored
Allow for custom encoding nonce (#53)
To allow for optional deterministic output, allow for a custom nonce to be set.
1 parent 2b8420b commit 3cd3734

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

dare.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ func newAuthEncV10(cfg *Config) (authEncV10, error) {
9090
return authEncV10{}, err
9191
}
9292
var randVal [8]byte
93-
if _, err = io.ReadFull(cfg.Rand, randVal[:]); err != nil {
93+
if cfg.Nonce != nil {
94+
copy(randVal[:], cfg.Nonce[:8])
95+
} else if _, err = io.ReadFull(cfg.Rand, randVal[:]); err != nil {
9496
return authEncV10{}, err
9597
}
9698
return authEncV10{
@@ -167,7 +169,9 @@ func newAuthEncV20(cfg *Config) (authEncV20, error) {
167169
return authEncV20{}, err
168170
}
169171
var randVal [12]byte
170-
if _, err = io.ReadFull(cfg.Rand, randVal[:]); err != nil {
172+
if cfg.Nonce != nil {
173+
randVal = *cfg.Nonce
174+
} else if _, err = io.ReadFull(cfg.Rand, randVal[:]); err != nil {
171175
return authEncV20{}, err
172176
}
173177
return authEncV20{

sio.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ type Config struct {
122122
// the default value (crypto/rand.Reader) is used.
123123
Rand io.Reader
124124

125+
// Nonce will override the nonce if set non-nil.
126+
// V2 will use all 12 bytes, V1 first 8 bytes.
127+
Nonce *[12]byte
128+
125129
// The size of the encrypted payload in bytes. The
126130
// default value is 64KB. It should be used to restrict
127131
// the size of encrypted packages. The payload size

0 commit comments

Comments
 (0)