@@ -121,21 +121,17 @@ func (s *StorageDB) SetIDPublicKey(correlationID, secretKey, publicKey string) e
121121func (s * StorageDB ) SetID (ID string ) error {
122122 data := & CorrelationData {}
123123
124- if s .Options .UseDisk () {
125- aesKey := make ([]byte , 32 )
126- if _ , err := rand .Read (aesKey ); err != nil {
127- return errors .Wrap (err , "could not generate AES key" )
128- }
129- data .AESKey = aesKey
130- }
131-
132124 s .cache .Put (ID , data )
133125 return nil
134126}
135127
136128// AddInteraction adds an interaction data to the correlation ID after encrypting
137129// it with Public Key for the provided correlation ID.
138130func (s * StorageDB ) AddInteraction (correlationID string , data []byte ) error {
131+ if len (data ) == 0 {
132+ return nil
133+ }
134+
139135 item , found := s .cache .GetIfPresent (correlationID )
140136 if ! found {
141137 return ErrCorrelationIdNotFound
@@ -146,10 +142,15 @@ func (s *StorageDB) AddInteraction(correlationID string, data []byte) error {
146142 }
147143
148144 if s .Options .UseDisk () {
149- ct , err := AESEncrypt (value .AESKey , data )
150- if err != nil {
151- return errors .Wrap (err , "could not encrypt event data" )
145+ ct := string (data )
146+ if len (value .AESKey ) > 0 {
147+ var err error
148+ ct , err = AESEncrypt (value .AESKey , data )
149+ if err != nil {
150+ return errors .Wrap (err , "could not encrypt event data" )
151+ }
152152 }
153+
153154 value .Lock ()
154155 existingData , _ := s .db .Get ([]byte (correlationID ), nil )
155156 _ = s .db .Put ([]byte (correlationID ), AppendMany ("\n " , existingData , []byte (ct )), nil )
@@ -165,6 +166,10 @@ func (s *StorageDB) AddInteraction(correlationID string, data []byte) error {
165166
166167// AddInteractionWithId adds an interaction data to the id bucket
167168func (s * StorageDB ) AddInteractionWithId (id string , data []byte ) error {
169+ if len (data ) == 0 {
170+ return nil
171+ }
172+
168173 item , ok := s .cache .GetIfPresent (id )
169174 if ! ok {
170175 return ErrCorrelationIdNotFound
@@ -175,10 +180,15 @@ func (s *StorageDB) AddInteractionWithId(id string, data []byte) error {
175180 }
176181
177182 if s .Options .UseDisk () {
178- ct , err := AESEncrypt (value .AESKey , data )
179- if err != nil {
180- return errors .Wrap (err , "could not encrypt event data" )
183+ ct := string (data )
184+ if len (value .AESKey ) > 0 {
185+ var err error
186+ ct , err = AESEncrypt (value .AESKey , data )
187+ if err != nil {
188+ return errors .Wrap (err , "could not encrypt event data" )
189+ }
181190 }
191+
182192 value .Lock ()
183193 existingData , _ := s .db .Get ([]byte (id ), nil )
184194 _ = s .db .Put ([]byte (id ), AppendMany ("\n " , existingData , []byte (ct )), nil )
0 commit comments