github.com/aavshr/aws-sdk-go@v1.41.3/service/s3/s3crypto/key_handler.go (about)

     1  package s3crypto
     2  
     3  import (
     4  	"crypto/rand"
     5  
     6  	"github.com/aavshr/aws-sdk-go/aws"
     7  )
     8  
     9  // CipherDataGenerator handles generating proper key and IVs of proper size for the
    10  // content cipher. CipherDataGenerator will also encrypt the key and store it in
    11  // the CipherData.
    12  type CipherDataGenerator interface {
    13  	GenerateCipherData(int, int) (CipherData, error)
    14  }
    15  
    16  // CipherDataGeneratorWithContext handles generating proper key and IVs of
    17  // proper size for the content cipher. CipherDataGenerator will also encrypt
    18  // the key and store it in the CipherData.
    19  type CipherDataGeneratorWithContext interface {
    20  	GenerateCipherDataWithContext(aws.Context, int, int) (CipherData, error)
    21  }
    22  
    23  // CipherDataGeneratorWithCEKAlg handles generating proper key and IVs of proper size for the
    24  // content cipher. CipherDataGenerator will also encrypt the key and store it in
    25  // the CipherData.
    26  type CipherDataGeneratorWithCEKAlg interface {
    27  	GenerateCipherDataWithCEKAlg(ctx aws.Context, keySize, ivSize int, cekAlgorithm string) (CipherData, error)
    28  }
    29  
    30  // CipherDataDecrypter is a handler to decrypt keys from the envelope.
    31  type CipherDataDecrypter interface {
    32  	DecryptKey([]byte) ([]byte, error)
    33  }
    34  
    35  // CipherDataDecrypterWithContext is a handler to decrypt keys from the envelope with request context.
    36  type CipherDataDecrypterWithContext interface {
    37  	DecryptKeyWithContext(aws.Context, []byte) ([]byte, error)
    38  }
    39  
    40  func generateBytes(n int) ([]byte, error) {
    41  	b := make([]byte, n)
    42  	_, err := rand.Read(b)
    43  	if err != nil {
    44  		return nil, err
    45  	}
    46  	return b, nil
    47  }