Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for custom encoding nonce #53

Merged
merged 1 commit into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions dare.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ func newAuthEncV10(cfg *Config) (authEncV10, error) {
return authEncV10{}, err
}
var randVal [8]byte
if _, err = io.ReadFull(cfg.Rand, randVal[:]); err != nil {
if cfg.Nonce != nil {
copy(randVal[:], cfg.Nonce[:8])
} else if _, err = io.ReadFull(cfg.Rand, randVal[:]); err != nil {
return authEncV10{}, err
}
return authEncV10{
Expand Down Expand Up @@ -167,7 +169,9 @@ func newAuthEncV20(cfg *Config) (authEncV20, error) {
return authEncV20{}, err
}
var randVal [12]byte
if _, err = io.ReadFull(cfg.Rand, randVal[:]); err != nil {
if cfg.Nonce != nil {
randVal = *cfg.Nonce
} else if _, err = io.ReadFull(cfg.Rand, randVal[:]); err != nil {
return authEncV20{}, err
}
return authEncV20{
Expand Down
4 changes: 4 additions & 0 deletions sio.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ type Config struct {
// the default value (crypto/rand.Reader) is used.
Rand io.Reader

// Nonce will override the nonce if set non-nil.
// V2 will use all 12 bytes, V1 first 8 bytes.
Nonce *[12]byte

// The size of the encrypted payload in bytes. The
// default value is 64KB. It should be used to restrict
// the size of encrypted packages. The payload size
Expand Down
Loading