Documentation
¶
Index ¶
- Constants
- Variables
- func CreateAcrastruct(data []byte, acraPublic *keys.PublicKey, context []byte) ([]byte, error)
- func DecryptAcrastruct(data []byte, privateKey *keys.PrivateKey, additionalContext []byte) ([]byte, error)
- func DecryptRotatedAcrastruct(data []byte, privateKeys []*keys.PrivateKey, additionalContext []byte) ([]byte, error)
- func ExtractAcraStruct(data []byte) (int, []byte, error)
- func GetDataLengthFromAcraStruct(data []byte) int
- func GetMinAcraStructLength() int
- func ProcessAcraStructs(ctx context.Context, inBuffer []byte, outBuffer []byte, processor Processor) ([]byte, error)
- func ValidateAcraStructLength(data []byte) error
- type Processor
Constants ¶
const ( // length of EC public key PublicKeyLength = 45 // length of 32 byte of symmetric key wrapped to smessage SMessageKeyLength = 84 KeyBlockLength = PublicKeyLength + SMessageKeyLength SymmetricKeySize = 32 // DataLengthSize length of part of AcraStruct that store data part length. So max data size is 2^^64 that // may be wrapped into AcraStruct. We decided that 2^^64 is enough and not much as 8 byte overhead per AcraStruct DataLengthSize = 8 )
Shows key and data length.
const ( // TagSymbol used in begin tag in AcraStruct TagSymbol byte = '"' )
Constants that setup which symbol would be used at start in AcraStruct to simplify recognizing from other binary data Double-quote was chosen because it's printable symbol (help in debugging when we can see in console that it's start of AcraStruct) and rarely used sequentially Tag length was chosen
Variables ¶
var ( ErrIncorrectAcraStructTagBegin = errors.New("AcraStruct has incorrect TagBegin") ErrIncorrectAcraStructLength = errors.New("AcraStruct has incorrect length") ErrIncorrectAcraStructDataLength = errors.New("AcraStruct has incorrect data length value") )
Errors show incorrect AcraStruct length
var ErrInvalidAcraStruct = errors.New("invalid AcraStruct")
ErrInvalidAcraStruct defines invalid AcraStruct error
var ErrNoPrivateKeys = errors.New("cannot decrypt AcraStruct with empty key list")
ErrNoPrivateKeys is returned when DecryptRotatedAcrastruct is given an empty key list
var TagBegin = []byte{TagSymbol, TagSymbol, TagSymbol, TagSymbol, TagSymbol, TagSymbol, TagSymbol, TagSymbol}
TagBegin represents begin sequence of bytes for AcraStruct.
Functions ¶
func CreateAcrastruct ¶
CreateAcrastruct encrypt your data using acra_public key and context (optional) and pack into correct Acrastruct format
func DecryptAcrastruct ¶
func DecryptAcrastruct(data []byte, privateKey *keys.PrivateKey, additionalContext []byte) ([]byte, error)
DecryptAcrastruct returns plaintext data from AcraStruct, decrypting it using Themis SecureCell in Seal mode, using optional additional context and privateKey as decryption key. Returns error if decryption failed.
func DecryptRotatedAcrastruct ¶
func DecryptRotatedAcrastruct(data []byte, privateKeys []*keys.PrivateKey, additionalContext []byte) ([]byte, error)
DecryptRotatedAcrastruct tries decrypting an AcraStruct with a set of rotated keys. It either returns decrypted data if one of the keys succeeds, or an error if none is good.
func ExtractAcraStruct ¶
ExtractAcraStruct return AcraStruct that stored at start of data and return size in bytes of parsed AcraStructLength
func GetDataLengthFromAcraStruct ¶
GetDataLengthFromAcraStruct unpack data length value from AcraStruct
func GetMinAcraStructLength ¶
func GetMinAcraStructLength() int
GetMinAcraStructLength returns minimal length of AcraStruct because in golang we can't declare byte array as constant we need to calculate length of TagBegin in runtime or hardcode as constant and maintain len(TagBegin) == CONST_VALUE
func ProcessAcraStructs ¶
func ProcessAcraStructs(ctx context.Context, inBuffer []byte, outBuffer []byte, processor Processor) ([]byte, error)
ProcessAcraStructs find AcraStructs in inBuffer, call processor on every recognized AcraStruct and replace it with result into outBuffer until end of data from inBuffer or any error result On error it returns inBuffer as is
func ValidateAcraStructLength ¶
ValidateAcraStructLength check that data has minimal length for AcraStruct and data block equal to data length in AcraStruct