acrastruct

package
v0.0.0-...-982e07a Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
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.

View Source
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

View Source
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

View Source
var ErrInvalidAcraStruct = errors.New("invalid AcraStruct")

ErrInvalidAcraStruct defines invalid AcraStruct error

View Source
var ErrNoPrivateKeys = errors.New("cannot decrypt AcraStruct with empty key list")

ErrNoPrivateKeys is returned when DecryptRotatedAcrastruct is given an empty key list

TagBegin represents begin sequence of bytes for AcraStruct.

Functions

func CreateAcrastruct

func CreateAcrastruct(data []byte, acraPublic *keys.PublicKey, context []byte) ([]byte, error)

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

func ExtractAcraStruct(data []byte) (int, []byte, error)

ExtractAcraStruct return AcraStruct that stored at start of data and return size in bytes of parsed AcraStructLength

func GetDataLengthFromAcraStruct

func GetDataLengthFromAcraStruct(data []byte) int

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

func ValidateAcraStructLength(data []byte) error

ValidateAcraStructLength check that data has minimal length for AcraStruct and data block equal to data length in AcraStruct

Types

type Processor

type Processor interface {
	OnAcraStruct(ctx context.Context, acrastruct []byte) ([]byte, error)
}

Processor interface used as callback for recognized AcraStructs and should return data instead AcraStruct

Jump to

Keyboard shortcuts

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