refactor: no need to record 'df' in two places in state
This commit is contained in:
1 parent
e414f6d059
commit
d15575212a
1 file changed
+4
-7
+4
-7
@@ -123,7 +123,6 @@ type NaClEncryptor struct {
|
|||||||
offset uint16
|
offset uint16
|
||||||
nonce *[24]byte
|
nonce *[24]byte
|
||||||
nonceChan chan *[24]byte
|
nonceChan chan *[24]byte
|
||||||
flags uint16
|
|
||||||
prefixLen int
|
prefixLen int
|
||||||
conn *LocalConnection
|
conn *LocalConnection
|
||||||
df bool
|
df bool
|
||||||
@@ -178,17 +177,12 @@ func (ne *NonEncryptor) TotalLen() int {
|
|||||||
func NewNaClEncryptor(prefix []byte, conn *LocalConnection, df bool) *NaClEncryptor {
|
func NewNaClEncryptor(prefix []byte, conn *LocalConnection, df bool) *NaClEncryptor {
|
||||||
buf := make([]byte, MaxUDPPacketSize)
|
buf := make([]byte, MaxUDPPacketSize)
|
||||||
prefixLen := copy(buf, prefix)
|
prefixLen := copy(buf, prefix)
|
||||||
flags := uint16(0)
|
|
||||||
if df {
|
|
||||||
flags = flags | (1 << 15)
|
|
||||||
}
|
|
||||||
return &NaClEncryptor{
|
return &NaClEncryptor{
|
||||||
NonEncryptor: *NewNonEncryptor([]byte{}),
|
NonEncryptor: *NewNonEncryptor([]byte{}),
|
||||||
buf: buf,
|
buf: buf,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
nonce: nil,
|
nonce: nil,
|
||||||
nonceChan: make(chan *[24]byte, ChannelSize),
|
nonceChan: make(chan *[24]byte, ChannelSize),
|
||||||
flags: flags,
|
|
||||||
prefixLen: prefixLen,
|
prefixLen: prefixLen,
|
||||||
conn: conn,
|
conn: conn,
|
||||||
df: df}
|
df: df}
|
||||||
@@ -196,7 +190,10 @@ func NewNaClEncryptor(prefix []byte, conn *LocalConnection, df bool) *NaClEncryp
|
|||||||
|
|
||||||
func (ne *NaClEncryptor) Bytes() []byte {
|
func (ne *NaClEncryptor) Bytes() []byte {
|
||||||
plaintext := ne.NonEncryptor.Bytes()
|
plaintext := ne.NonEncryptor.Bytes()
|
||||||
offsetFlags := ne.offset | ne.flags
|
offsetFlags := ne.offset
|
||||||
|
if ne.df {
|
||||||
|
offsetFlags |= (1 << 15)
|
||||||
|
}
|
||||||
ciphertext := ne.buf
|
ciphertext := ne.buf
|
||||||
binary.BigEndian.PutUint16(ciphertext[ne.prefixLen:], offsetFlags)
|
binary.BigEndian.PutUint16(ciphertext[ne.prefixLen:], offsetFlags)
|
||||||
nonce := ne.nonce
|
nonce := ne.nonce
|
||||||
|
|||||||
Reference in new issue
Block a user