Documentation ¶
Index ¶
- Constants
- func RegisterCompressorDecompressor(ct CompressionType, str string, cdc CompressorDecompressorConstructor)
- func RegisterEncrypterDecrypter(et EncryptionType, str string, edc EncrypterDecrypterConstructor)
- type AESEncrypterDecrypter
- type CompressionMode
- type CompressionType
- type CompressorDecompressorConstructor
- type EncrypterDecrypterConstructor
- type EncryptionType
- type GZipCompressorDecompressor
- type LZ4CompressorDecompressor
- type NopProcessor
- type Processor
- type ProcessorChain
- type SnappyCompressorDecompressor
Constants ¶
const ( // EncryptionTypeAES is the enum constant which identifies AES, // an encryption algorithm, and also the encryption algorithm, // promoted by this package and used by default. // // What specific AES algorithm is used, depends on the given key size: // // * 16 bytes: AES_128 // * 24 bytes: AES_192 // * 32 bytes: AES_256 // // When giving a key of a size other than these 3, // while creating an encrypter-decrypter, the constructor will return an error. EncryptionTypeAES EncryptionType = iota // DefaultEncryptionType represents the default // encryption algorithm as promoted by this package. // // This package reserves the right to change the // default encryption algorithm at any time, // but this constant will always be available and up to date. DefaultEncryptionType = EncryptionTypeAES // MaxStandardEncryptionType defines the encryption type, // which has the greatest defined/used enum value. // When defining your custom EncryptionType you can do so as follows: // // const ( // MyEncryptionType = iota + processing.MaxStandardEncryptionType + 1 // MyOtherEncryptionType // // ... // ) // // The maximum allowed value of a custom encryption type is 255, // due to the underlying uint8 type. MaxStandardEncryptionType = EncryptionTypeAES )
Variables ¶
This section is empty.
Functions ¶
func RegisterCompressorDecompressor ¶
func RegisterCompressorDecompressor(ct CompressionType, str string, cdc CompressorDecompressorConstructor)
RegisterCompressorDecompressor registers a new or overwrite an existing compression algorithm. The given str will be used in a case-insensitive manner, if the registered compressor-decompressor however overwrites an existing compression type, the str parameter will be ignored and instead the already used string version will be used. This is intended to be called from the init function in packages that implement the compressor-decompressor.
func RegisterEncrypterDecrypter ¶
func RegisterEncrypterDecrypter(et EncryptionType, str string, edc EncrypterDecrypterConstructor)
RegisterEncrypterDecrypter registers a new or overwrite an existing encryption algorithm. The given str will be used in a case-insensitive manner, if the registered encrypter-decrypter however overwrites an existing encryption type, the str parameter will be ignored and instead the already used string version will be used. This is intended to be called from the init function in packages that implement the encrypter-decrypter.
Types ¶
type AESEncrypterDecrypter ¶
type AESEncrypterDecrypter struct {
// contains filtered or unexported fields
}
AESEncrypterDecrypter defines a processor, which encrypts and decrypts, using the Golang std AES implementation as its internal algorithm.
It will encrypt plain text to cipher text while writing, and it will decrypt cipher text to plain text while reading.
What specific AES algorithm is used, depends on the given key size:
- 16 bytes: AES_128
- 24 bytes: AES_192
- 32 bytes: AES_256
When giving a key of a size other than these 3, NewAESEncrypterDecrypter will return an error.
func NewAESEncrypterDecrypter ¶
func NewAESEncrypterDecrypter(privateKey []byte) (*AESEncrypterDecrypter, error)
NewAESEncrypterDecrypter creates a new encrypter-decrypter processor, using the Golang std AES implementation as its internal algorithm.
See AESEncrypterDecrypter for more information.
func (*AESEncrypterDecrypter) ReadProcess ¶
func (ed *AESEncrypterDecrypter) ReadProcess(cipher []byte) (plain []byte, err error)
ReadProcess implements Processor.ReadProcess
func (*AESEncrypterDecrypter) SharedReadBuffer ¶
func (ed *AESEncrypterDecrypter) SharedReadBuffer() bool
SharedReadBuffer implements Processor.SharedReadBuffer
func (*AESEncrypterDecrypter) SharedWriteBuffer ¶
func (ed *AESEncrypterDecrypter) SharedWriteBuffer() bool
SharedWriteBuffer implements Processor.SharedWriteBuffer
func (*AESEncrypterDecrypter) WriteProcess ¶
func (ed *AESEncrypterDecrypter) WriteProcess(plain []byte) (cipher []byte, err error)
WriteProcess implements Processor.WriteProcess
type CompressionMode ¶
type CompressionMode uint8
CompressionMode represents a compression mode.
A compression mode is a hint to the compression type's constructor, it is not guaranteed that the returned compressor is as ideal as you'll hope, the implementation should however try to fit the requested mode to a possible configuration which respects the particalar mode as much as possible.
const ( // CompressionModeDisabled is the enum constant which identifies // the disabled compression mode. // Meaning we do not want any compression type at all. CompressionModeDisabled CompressionMode = iota // CompressionModeDefault is the enum constant which identifies // the default compression mode. What this means exactly // is up to the compression algorithm to define. CompressionModeDefault // CompressionModeBestSpeed is the enum constant which identifies // the request to use the compression with a configuration, // which aims for the best possible speed, using that algorithm. // // What this exactly means is up to the compression type, // and it is entirely free to ignore this compression mode all together, // if it doesn't make sense for that type in particular. CompressionModeBestSpeed // CompressionModeBestCompression is the enum constant which identifies // the request to use the compression with a configuration, // which aims for the best possible compression (ratio), using that algorithm. // // What this exactly means is up to the compression type, // and it is entirely free to ignore this compression mode all together, // if it doesn't make sense for that type in particular. CompressionModeBestCompression )
func (CompressionMode) MarshalText ¶
func (cm CompressionMode) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler.MarshalText
func (CompressionMode) String ¶
func (cm CompressionMode) String() string
String implements Stringer.String
func (*CompressionMode) UnmarshalText ¶
func (cm *CompressionMode) UnmarshalText(text []byte) error
UnmarshalText implements encoding.TextUnmarshaler.UnmarshalText
type CompressionType ¶
type CompressionType uint8
CompressionType represents a compression algorithm.
const ( // CompressionTypeSnappy is the enum constant which identifies Snappy, // a compression algorithm, implemented by Google, and also the compression algorithm, // promoted by this package and used by default. // // See github.com/golang/snappy for more information about the // technical details beyind this compression type. CompressionTypeSnappy CompressionType = iota // CompressionTypeLZ4 is the enum constant which identifies lz4, // a compression algorithm, implemented by Pierre Curto. // // See github.com/pierrec/lz4 for more information about the // technical details beyind this compression type. CompressionTypeLZ4 // CompressionTypeGZip is the enum constant which identifies gz4, // a compression algorithm, part of the Golang std. // // See compress/gzip (Golang STD package) for more information about the // technical details beyind this compression type. CompressionTypeGZip // DefaultCompressionType represents the default // compression algorithm as promoted by this package. // // This package reserves the right to change the // default compression algorithm at any time, // but this constant will always be available and up to date. DefaultCompressionType = CompressionTypeSnappy // MaxStandardCompressionType defines the compression type, // which has the greatest defined/used enum value. // When defining your custom CompressionType you can do so as follows: // // const ( // MyCompressionType = iota + processing.MaxStandardCompressionType + 1 // MyOtherCompressionType // // ... // ) // // The maximum allowed value of a custom compression type is 255, // due to the underlying uint8 type. MaxStandardCompressionType = CompressionTypeGZip )
func (CompressionType) MarshalText ¶
func (ct CompressionType) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler.MarshalText
func (CompressionType) String ¶
func (ct CompressionType) String() string
String implements Stringer.String
func (*CompressionType) UnmarshalText ¶
func (ct *CompressionType) UnmarshalText(text []byte) error
UnmarshalText implements encoding.TextUnmarshaler.UnmarshalText
type CompressorDecompressorConstructor ¶
type CompressorDecompressorConstructor func(mode CompressionMode) (Processor, error)
CompressorDecompressorConstructor defines a function which can be used to create an compressor-decompressor.
The given compression mode serves as a hint from the user to the constructor, about what the user is expecting from its desired compressor-decompressor. The constructor is however free to interpret this value as it sees fit, however it is recommended to try to respect the choice as much as possible.
type EncrypterDecrypterConstructor ¶
EncrypterDecrypterConstructor defines a function which can be used to create an encrypter-decrypter. The key parameter is a required private key which is used to encrypt and decrypt the data while processing it.
type EncryptionType ¶
type EncryptionType uint8
EncryptionType represents an encryption algorithm.
func (EncryptionType) MarshalText ¶
func (et EncryptionType) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler.MarshalText
func (EncryptionType) String ¶
func (et EncryptionType) String() string
String implements Stringer.String
func (*EncryptionType) UnmarshalText ¶
func (et *EncryptionType) UnmarshalText(text []byte) error
UnmarshalText implements encoding.TextUnmarshaler.UnmarshalText
type GZipCompressorDecompressor ¶
type GZipCompressorDecompressor struct {
// contains filtered or unexported fields
}
GZipCompressorDecompressor defines a processor, which compresses and decompresses, using Golang's standard gzip implementation.
It will compress text to compressed text while writing, and it will decompress compress text to (uncompressed) text while reading.
The CompressionMode is mapped directly to the gzip mode, with the same name. When the given CompressionMode couldn't be recognized, the gzip.BestSpeed mode will be used.
See compress/gzip (Golang STD package) for more information about the technical details beyind this compression type.
func NewGZipCompressorDecompressor ¶
func NewGZipCompressorDecompressor(cm CompressionMode) (*GZipCompressorDecompressor, error)
NewGZipCompressorDecompressor creates a new compressor-decompressor processor, using Golang's standard gzip implementation.
See GZipCompressorDecompressor for more information.
func (*GZipCompressorDecompressor) ReadProcess ¶
func (cd *GZipCompressorDecompressor) ReadProcess(data []byte) ([]byte, error)
ReadProcess implements Processor.ReadProcess
input data gets decompressed, and returned as the decompressed (and uncompressed?) output data
func (*GZipCompressorDecompressor) SharedReadBuffer ¶
func (cd *GZipCompressorDecompressor) SharedReadBuffer() bool
SharedReadBuffer implements Processor.SharedReadBuffer
func (*GZipCompressorDecompressor) SharedWriteBuffer ¶
func (cd *GZipCompressorDecompressor) SharedWriteBuffer() bool
SharedWriteBuffer implements Processor.SharedWriteBuffer
func (*GZipCompressorDecompressor) WriteProcess ¶
func (cd *GZipCompressorDecompressor) WriteProcess(data []byte) ([]byte, error)
WriteProcess implements Processor.WriteProcess
input data gets compressed, and returned as compressed output data
type LZ4CompressorDecompressor ¶
type LZ4CompressorDecompressor struct {
// contains filtered or unexported fields
}
LZ4CompressorDecompressor defines a processor, which compresses and decompresses, using the LZ4 compression algorithm, implemented by Pierre Curto.
It will compress text to compressed text while writing, and it will decompress compress text to (uncompressed) text while reading.
See github.com/pierrec/lz4 for more information about the technical details beyind this compressor-decompressor type.
func NewLZ4CompressorDecompressor ¶
func NewLZ4CompressorDecompressor(cm CompressionMode) (*LZ4CompressorDecompressor, error)
NewLZ4CompressorDecompressor creates a new compressor-decompressor processor, using the LZ4 compression algorithm, implemented by Pierre Curto.
See LZ4CompressorDecompressor for more information.
func (*LZ4CompressorDecompressor) ReadProcess ¶
func (cd *LZ4CompressorDecompressor) ReadProcess(data []byte) ([]byte, error)
ReadProcess implements Processor.ReadProcess
input data gets decompressed, and returned as the decompressed (and uncompressed?) output data
func (*LZ4CompressorDecompressor) SharedReadBuffer ¶
func (cd *LZ4CompressorDecompressor) SharedReadBuffer() bool
SharedReadBuffer implements Processor.SharedReadBuffer
func (*LZ4CompressorDecompressor) SharedWriteBuffer ¶
func (cd *LZ4CompressorDecompressor) SharedWriteBuffer() bool
SharedWriteBuffer implements Processor.SharedWriteBuffer
func (*LZ4CompressorDecompressor) WriteProcess ¶
func (cd *LZ4CompressorDecompressor) WriteProcess(data []byte) ([]byte, error)
WriteProcess implements Processor.WriteProcess
input data gets compressed, and returned as compressed output data
type NopProcessor ¶
type NopProcessor struct{}
NopProcessor implements the Processor interface, but does not do any processing whatsoever. Instead it returns the data it receives.
This implementation can be used in case you are required to give a Processor, in some location, but have no desire to do any processing yourself.
func (NopProcessor) ReadProcess ¶
func (nop NopProcessor) ReadProcess(data []byte) ([]byte, error)
ReadProcess implements Processor.WriteProcess
func (NopProcessor) SharedReadBuffer ¶
func (nop NopProcessor) SharedReadBuffer() bool
SharedReadBuffer implements Processor.SharedReadBuffer
func (NopProcessor) SharedWriteBuffer ¶
func (nop NopProcessor) SharedWriteBuffer() bool
SharedWriteBuffer implements Processor.SharedWriteBuffer
func (NopProcessor) WriteProcess ¶
func (nop NopProcessor) WriteProcess(data []byte) ([]byte, error)
WriteProcess implements Processor.WriteProcess
type Processor ¶
type Processor interface { // WriteProcess processes data in the write direction. // // The input byte slice is used as read-only data. // // Should you want to want to take ownership of the the output slice, // you'll have to copy the output data slice, // if and only if the `SharedWriteBuffer` of this Processor returns true, // as this means the allocated memory for that slice // is shared between sequential WriteProcess calls. // See SharedWriteBuffer for more information. WriteProcess(input []byte) (output []byte, err error) // ReadProcess processes data in the read direction, // and thus takes in processed data as input, // in other words data that was previously processed // by the WriteProcess method of an instance of this Processor type. // // The input byte slice is used as read-only data. // // Should you want to want to take ownership of the the output slice, // you'll have to copy the output data slice, // if and only if the `SharedReadBuffer` of this Processor returns true, // as this means the allocated memory for that slice // is shared between sequential ReadProcess calls. // See SharedReadBuffer for more information. ReadProcess(input []byte) (output []byte, err error) // the internal buffer is reused for sequential SharedWriteBuffer calls. // Meaning that the output data returned by WriteProcess // will remain owned by this Processor, // and should be either consumed as read-only and instantly, // or copied to a different slice in memory right after the data has been received. SharedWriteBuffer() bool // the internal buffer is reused for sequential ReadProcess calls. // Meaning that the output data returned by ReadProcess // will remain owned by this Processor, // and should be either consumed as read-only and instantly, // or copied to a different slice in memory right after the data has been received. SharedReadBuffer() bool }
Processor defines the interface which can process data. It processes data in two directions, read and write.
The processor implementation has to guarantee, that data that was written, can also be read by it. And thus the ReadProcess can be seen as the reverse WritePRocess. In other words, the following has to be true for all processors:
require.NotNil(inputData) require.NotNil(processor) processedData, err := processor.WriteProcess(inputData) if err == nil { outputData, err := processor.ReadProcess(processedData) if err == nil { require.Equal(inputData, outputData) } }
A Processor is /NEVER/ thread-safe, and should only ever be used on /ONE/ goroutine at a time. If you wish to hash on multiple goroutines, you'll have to create one Processor (instance) per goroutine.
func NewCompressorDecompressor ¶
func NewCompressorDecompressor(ct CompressionType, mode CompressionMode) (Processor, error)
NewCompressorDecompressor returns a new instance for the given compression type. If the compression type is not registered as a valid compression type, an error is returned.
The given compression mode is required, but the type's default value can be used.
func NewEncrypterDecrypter ¶
func NewEncrypterDecrypter(et EncryptionType, privateKey []byte) (Processor, error)
NewEncrypterDecrypter returns a new instance for the given encryption type. If the encryption type is not registered as a valid encryption type, an error is returned.
The given privateKey is not optional and has to be defined.
type ProcessorChain ¶
type ProcessorChain struct {
// contains filtered or unexported fields
}
ProcessorChain can be used to chain multiple processor together. It will process data using all given processors in sequence, in the order that they are given, when writing. When reading the order of processors will be reverse as the one given, this to ensure that what has been written with this chain can also be read again.
func NewProcessorChain ¶
func NewProcessorChain(processors []Processor) *ProcessorChain
NewProcessorChain creates a new processor chain. At least 2 processors have to be given, or else NewProcessorChain panics. See ProcessorChain for more about information about the type.
func (*ProcessorChain) ReadProcess ¶
func (chain *ProcessorChain) ReadProcess(data []byte) ([]byte, error)
ReadProcess implements Processor.ReadProcess
Processes the given data in the read direction, using all the given processors in the reverse order they're given, starting with the last and ending with the first.
If an error happens at any point, this method will short circuit and return that error immediately.
func (*ProcessorChain) SharedReadBuffer ¶
func (chain *ProcessorChain) SharedReadBuffer() bool
SharedReadBuffer implements Processor.SharedReadBuffer
func (*ProcessorChain) SharedWriteBuffer ¶
func (chain *ProcessorChain) SharedWriteBuffer() bool
SharedWriteBuffer implements Processor.SharedWriteBuffer
func (*ProcessorChain) WriteProcess ¶
func (chain *ProcessorChain) WriteProcess(data []byte) ([]byte, error)
WriteProcess implements Processor.WriteProcess
Processes the given data in the write direction, using all the given processors in the order they're given, starting with the first and ending with the last.
If an error happens at any point, this method will short circuit and return that error immediately.
type SnappyCompressorDecompressor ¶
type SnappyCompressorDecompressor struct {
// contains filtered or unexported fields
}
SnappyCompressorDecompressor defines a processor, which compresses and decompresses, using google's Snappy compression implementation in Golang.
It will compress text to compressed text while writing, and it will decompress compress text to (uncompressed) text while reading.
See github.com/golang/snappy for more information about the technical details beyind this compressor-decompressor type.
func NewSnappyCompressorDecompressor ¶
func NewSnappyCompressorDecompressor(cm CompressionMode) (*SnappyCompressorDecompressor, error)
NewSnappyCompressorDecompressor creates a new compressor-decompressor processor, using google's Snappy compression implementation in Golang.
See SnappyCompressorDecompressor for more information.
func (*SnappyCompressorDecompressor) ReadProcess ¶
func (cd *SnappyCompressorDecompressor) ReadProcess(data []byte) ([]byte, error)
ReadProcess implements Processor.ReadProcess
input data gets decompressed, and returned as the decompressed (and uncompressed?) output data
func (*SnappyCompressorDecompressor) SharedReadBuffer ¶
func (cd *SnappyCompressorDecompressor) SharedReadBuffer() bool
SharedReadBuffer implements Processor.SharedReadBuffer
func (*SnappyCompressorDecompressor) SharedWriteBuffer ¶
func (cd *SnappyCompressorDecompressor) SharedWriteBuffer() bool
SharedWriteBuffer implements Processor.SharedWriteBuffer
func (*SnappyCompressorDecompressor) WriteProcess ¶
func (cd *SnappyCompressorDecompressor) WriteProcess(data []byte) ([]byte, error)
WriteProcess implements Processor.WriteProcess
input data gets compressed, and returned as compressed output data