MCPcopy Create free account
hub / github.com/DOSNetwork/core / encryptPipe

Method encryptPipe

p2p/client.go:218–253  ·  view source on GitHub ↗
(plaintext chan []byte)

Source from the content-addressed store, hash-verified

216}
217
218func (c *client) encryptPipe(plaintext chan []byte) (out chan []byte) {
219 out = make(chan []byte)
220
221 go func() {
222 defer close(out)
223 for {
224 var result []byte
225 select {
226 case <-c.ctx.Done():
227 return
228 case text, ok := <-plaintext:
229 if ok {
230 var err error
231 var block cipher.Block
232 var aesgcm cipher.AEAD
233
234 if block, err = aes.NewCipher(c.dhKey); err != nil {
235 c.reportError(errors.Errorf("client encryptPipe: %w", err))
236 continue
237 }
238
239 if aesgcm, err = cipher.NewGCM(block); err != nil {
240 c.reportError(errors.Errorf("client encryptPipe: %w", err))
241 continue
242 }
243 result = aesgcm.Seal(nil, c.dhNonce, text, nil)
244 }
245 }
246 select {
247 case <-c.ctx.Done():
248 case out <- result:
249 }
250 }
251 }()
252 return out
253}
254
255func (c *client) decryptPipe(ciphertext chan []byte) (out chan []byte) {
256 out = make(chan []byte)

Callers 1

runMethod · 0.95

Calls 1

reportErrorMethod · 0.95

Tested by

no test coverage detected