github.com/ethersphere/bee/v2@v2.2.0/pkg/encryption/mock/chunk_encryption.go (about)

     1  // Copyright 2020 The Swarm Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package mock
     6  
     7  import (
     8  	"github.com/ethersphere/bee/v2/pkg/encryption"
     9  )
    10  
    11  type chunkEncrypter struct {
    12  	key []byte
    13  }
    14  
    15  func NewChunkEncrypter(key []byte) encryption.ChunkEncrypter { return &chunkEncrypter{key: key} }
    16  
    17  func (c *chunkEncrypter) EncryptChunk(chunkData []byte) (encryption.Key, []byte, []byte, error) {
    18  	enc := New(WithXOREncryption(c.key))
    19  	encryptedSpan, err := enc.Encrypt(chunkData[:8])
    20  	if err != nil {
    21  		return nil, nil, nil, err
    22  	}
    23  	encryptedData, err := enc.Encrypt(chunkData[8:])
    24  	if err != nil {
    25  		return nil, nil, nil, err
    26  	}
    27  	return nil, encryptedSpan, encryptedData, nil
    28  }