coscrypto

package
v0.7.47 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2024 License: MIT Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
const (
	COSClientSideEncryptionKey                      string = "x-cos-meta-client-side-encryption-key"
	COSClientSideEncryptionStart                           = "x-cos-meta-client-side-encryption-start"
	COSClientSideEncryptionCekAlg                          = "x-cos-meta-client-side-encryption-cek-alg"
	COSClientSideEncryptionWrapAlg                         = "x-cos-meta-client-side-encryption-wrap-alg"
	COSClientSideEncryptionMatDesc                         = "x-cos-meta-client-side-encryption-matdesc"
	COSClientSideEncryptionUnencryptedContentLength        = "x-cos-meta-client-side-encryption-unencrypted-content-length"
	COSClientSideEncryptionUnencryptedContentMD5           = "x-cos-meta-client-side-encryption-unencrypted-content-md5"
	COSClientSideEncryptionDataSize                        = "x-cos-meta-client-side-encryption-data-size"
	COSClientSideEncryptionPartSize                        = "x-cos-meta-client-side-encryption-part-size"
	UserAgent                                              = "User-Agent"
)
View Source
const (
	CosKmsCryptoWrap   = "KMS/TencentCloud"
	AesCtrAlgorithm    = "AES/CTR/NoPadding"
	EncryptionUaSuffix = "COSEncryptionClient"
)

Variables

View Source
var (
	KMSEndPoint = "kms.tencentcloudapi.com"
)

Functions

func NewKMSClient

func NewKMSClient(cred *cos.Credential, region string, opt ...KMSClientOptions) (*kms.Client, error)

Types

type Cipher

type Cipher interface {
	Encrypter
	Decrypter
}

Cipher is interface for encryption or decryption of an object

type CipherData

type CipherData struct {
	IV            []byte
	Key           []byte
	MatDesc       string
	WrapAlgorithm string
	CEKAlgorithm  string
	EncryptedIV   []byte
	EncryptedKey  []byte
}

func (*CipherData) Clone

func (cd *CipherData) Clone() CipherData

func (*CipherData) GetIV

func (cd *CipherData) GetIV() uint64

func (*CipherData) RandomKeyIv

func (cd *CipherData) RandomKeyIv(keyLen int, ivLen int) error

func (*CipherData) SeekIV

func (cd *CipherData) SeekIV(startPos uint64)

func (*CipherData) SetIV

func (cd *CipherData) SetIV(iv uint64)

type ContentCipher

type ContentCipher interface {
	EncryptContent(io.Reader) (io.ReadCloser, error)
	DecryptContent(io.Reader) (io.ReadCloser, error)
	Clone(cd CipherData) (ContentCipher, error)
	GetEncryptedLen(int64) int64
	GetCipherData() *CipherData
	GetAlignLen() int
}

type ContentCipherBuilder

type ContentCipherBuilder interface {
	ContentCipher() (ContentCipher, error)
	ContentCipherEnv(Envelope) (ContentCipher, error)
	GetMatDesc() string
}

func CreateAesCtrBuilder

func CreateAesCtrBuilder(cipher MasterCipher) ContentCipherBuilder

type CryptoClient

type CryptoClient struct {
	*cos.Client
	Object               *CryptoObjectService
	ContentCipherBuilder ContentCipherBuilder
	// contains filtered or unexported fields
}

func NewCryptoClient

func NewCryptoClient(client *cos.Client, masterCipher MasterCipher) *CryptoClient

type CryptoContext

type CryptoContext struct {
	DataSize      int64
	PartSize      int64
	ContentCipher ContentCipher
}

type CryptoDecrypter

type CryptoDecrypter struct {
	Body      io.Reader
	Decrypter io.Reader
	// contains filtered or unexported fields
}

CryptoDecrypter provides close method for Decrypter

func (*CryptoDecrypter) Close

func (rc *CryptoDecrypter) Close() error

Close lets the CryptoDecrypter satisfy io.ReadCloser interface

func (*CryptoDecrypter) Read

func (rc *CryptoDecrypter) Read(b []byte) (int, error)

Read lets the CryptoDecrypter satisfy io.ReadCloser interface

type CryptoEncrypter

type CryptoEncrypter struct {
	Body      io.Reader
	Encrypter io.Reader
	// contains filtered or unexported fields
}

CryptoEncrypter provides close method for Encrypter

func (*CryptoEncrypter) Close

func (rc *CryptoEncrypter) Close() error

Close lets the CryptoEncrypter satisfy io.ReadCloser interface

func (*CryptoEncrypter) Read

func (rc *CryptoEncrypter) Read(b []byte) (int, error)

Read lets the CryptoEncrypter satisfy io.ReadCloser interface

type CryptoObjectService

type CryptoObjectService struct {
	*cos.ObjectService
	// contains filtered or unexported fields
}

func (*CryptoObjectService) CompleteMultipartUpload

func (s *CryptoObjectService) CompleteMultipartUpload(ctx context.Context, name, uploadID string, opt *cos.CompleteMultipartUploadOptions) (*cos.CompleteMultipartUploadResult, *cos.Response, error)

func (*CryptoObjectService) CopyPart

func (s *CryptoObjectService) CopyPart(ctx context.Context, name, uploadID string, partNumber int, sourceURL string, opt *cos.ObjectCopyPartOptions) (*cos.CopyPartResult, *cos.Response, error)

func (*CryptoObjectService) Download

func (s *CryptoObjectService) Download(ctx context.Context, name string, filepath string, opt *cos.MultiDownloadOptions) (*cos.Response, error)

func (*CryptoObjectService) Get

func (s *CryptoObjectService) Get(ctx context.Context, name string, opt *cos.ObjectGetOptions, id ...string) (*cos.Response, error)

func (*CryptoObjectService) GetToFile

func (s *CryptoObjectService) GetToFile(ctx context.Context, name, localpath string, opt *cos.ObjectGetOptions, id ...string) (*cos.Response, error)

func (*CryptoObjectService) InitiateMultipartUpload

func (s *CryptoObjectService) InitiateMultipartUpload(ctx context.Context, name string, opt *cos.InitiateMultipartUploadOptions, cryptoCtx *CryptoContext) (*cos.InitiateMultipartUploadResult, *cos.Response, error)

func (*CryptoObjectService) MultiUpload

func (s *CryptoObjectService) MultiUpload(ctx context.Context, name string, filepath string, opt *cos.MultiUploadOptions) (*cos.CompleteMultipartUploadResult, *cos.Response, error)

func (*CryptoObjectService) Put

func (s *CryptoObjectService) Put(ctx context.Context, name string, r io.Reader, opt *cos.ObjectPutOptions) (*cos.Response, error)

func (*CryptoObjectService) PutFromFile

func (s *CryptoObjectService) PutFromFile(ctx context.Context, name, filePath string, opt *cos.ObjectPutOptions) (resp *cos.Response, err error)

func (*CryptoObjectService) Upload

func (s *CryptoObjectService) Upload(ctx context.Context, name string, filepath string, opt *cos.MultiUploadOptions) (*cos.CompleteMultipartUploadResult, *cos.Response, error)

func (*CryptoObjectService) UploadPart

func (s *CryptoObjectService) UploadPart(ctx context.Context, name, uploadID string, partNumber int, r io.Reader, opt *cos.ObjectUploadPartOptions, cryptoCtx *CryptoContext) (*cos.Response, error)

type Decrypter

type Decrypter interface {
	Decrypt(io.Reader) io.Reader
}

Decrypter is interface with only decrypt method

type Encrypter

type Encrypter interface {
	Encrypt(io.Reader) io.Reader
}

Encrypter is interface with only encrypt method

type Envelope

type Envelope struct {
	IV                    string
	CipherKey             string
	MatDesc               string
	WrapAlg               string
	CEKAlg                string
	UnencryptedMD5        string
	UnencryptedContentLen string
}

func (Envelope) IsValid

func (el Envelope) IsValid() bool

func (Envelope) String

func (el Envelope) String() string

type KMSClientOptions added in v0.7.41

type KMSClientOptions = func(*profile.HttpProfile)

func KMSEndpoint added in v0.7.41

func KMSEndpoint(endpoint string) KMSClientOptions

type MasterCipher

type MasterCipher interface {
	Encrypt([]byte) ([]byte, error)
	Decrypt([]byte) ([]byte, error)
	GetWrapAlgorithm() string
	GetMatDesc() string
}

func CreateMasterKMS

func CreateMasterKMS(client *kms.Client, kmsId string, desc map[string]string, opts ...MasterKMSCipherOptions) (MasterCipher, error)

type MasterKMSCipher

type MasterKMSCipher struct {
	Client  *kms.Client
	KmsId   string
	MatDesc string
	Conf    MasterKMSCipherConf
}

func (*MasterKMSCipher) Decrypt

func (kc *MasterKMSCipher) Decrypt(ciphertext []byte) ([]byte, error)

func (*MasterKMSCipher) Encrypt

func (kc *MasterKMSCipher) Encrypt(plaintext []byte) ([]byte, error)

func (*MasterKMSCipher) GetMatDesc

func (kc *MasterKMSCipher) GetMatDesc() string

func (*MasterKMSCipher) GetWrapAlgorithm

func (kc *MasterKMSCipher) GetWrapAlgorithm() string

type MasterKMSCipherConf added in v0.7.43

type MasterKMSCipherConf struct {
	Retry         int
	RetryInternal int64 // ms
}

type MasterKMSCipherOptions added in v0.7.43

type MasterKMSCipherOptions = func(*MasterKMSCipher)

func KMSRetry added in v0.7.43

func KMSRetry(retry int) MasterKMSCipherOptions

func KMSRetryInternal added in v0.7.43

func KMSRetryInternal(internal int64) MasterKMSCipherOptions

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL