envelope

package
v0.0.78 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Kind0x01 envelope identifier for Message Location Identifier Envelope where the resource is the decrypted hash.
	// This is used for stores where the resource can be set regardless of the content.
	// The first byte of the envelope is used to identify which programmable envelope is used.
	Kind0x01 byte = 0x01
	// Kind0x02 envelope identifier for Message Location Identifier Envelope where the resource is the encrypted hash.
	// This is used for stores where the resource is set based on the hash of the content.
	// The first byte of the envelope is used to identify which programmable envelope is used.
	Kind0x02 byte = 0x02
	// Kind0x50 envelope identifier for Alpha Envelope.
	// The first byte of the envelope is used to identify which programmable envelope is used.
	Kind0x50 byte = 0x50
	// KindString0x01 envelope string identifier for Message Location Identifier Envelope decrypted hash.
	KindString0x01 string = "0x01"
	// KindString0x02 envelope string identifier for Message Location Identifier Envelope encrypted hash.
	KindString0x02 string = "0x02"
	// KindString0x50 envelope string identifier for Alpha Envelope.
	KindString0x50 string = "0x50"
)

Variables

This section is empty.

Functions

func Marshal

func Marshal(data Data) ([]byte, error)

Marshal takes envelope data and encodes it into the wire format, returning the data.

func ParseEnvelope added in v0.0.38

func ParseEnvelope(envelope string) (byte, error)

ParseEnvelope parses envelope from string to byte.

Types

type CreateOptionsBuilder

type CreateOptionsBuilder func(*CreateOpts)

CreateOptionsBuilder creates the options to derive a key from scrypt.

func WithDecryptedHash

func WithDecryptedHash(decryptedHash []byte) CreateOptionsBuilder

WithDecryptedHash creates options builder with the decrypted hash.

func WithEncryptedContents added in v0.0.51

func WithEncryptedContents(encryptedContents []byte) CreateOptionsBuilder

WithEncryptedContents creates options builder with a the encrypted content of the message.

func WithEncryptedHash

func WithEncryptedHash(encryptedHash []byte) CreateOptionsBuilder

WithEncryptedHash creates options builder with the encrypted hash.

func WithKind

func WithKind(kind byte) CreateOptionsBuilder

WithKind creates options builder with envelope type identifier.

func WithMessageLocationIdentifier

func WithMessageLocationIdentifier(msgLocInd uint64) (CreateOptionsBuilder, error)

WithMessageLocationIdentifier creates options builder with a message location identifier.

func WithResource

func WithResource(resource string) CreateOptionsBuilder

WithResource creates options builder with a resource location.

func WithURL

func WithURL(address string) CreateOptionsBuilder

WithURL creates options builder with an encrypted URL.

type CreateOpts

type CreateOpts struct {
	// URL of message.
	URL string
	// DecryptedHash use to verify the decrypted contents have not been tampered with.
	DecryptedHash []byte
	// EncryptedHash use to verify the encrypted contents have not been tampered with.
	EncryptedHash []byte
	// Resource id of the message.
	Resource string
	// Kind type of envelope used
	Kind byte
	// Location maps to an addressable location.
	Location uint64
	// EncryptedContents message after its been encrypted.
	EncryptedContents []byte
}

CreateOpts for building an envelope.

type Data

type Data interface {
	// URL returns the addressable location of the message, the URL may be encrypted requiring decrypter to be supplied.
	URL(decrypter cipher.Decrypter) (*url.URL, error)
	// IntegrityHash returns a hash of the encrypted content. This can be used to validate the integrity of the contents before decrypting.
	IntegrityHash(decrypter cipher.Decrypter) ([]byte, error)
	// ContentsHash returns a hash of the decrypted content.
	// This can be used to verify the contents of the message have not been tampered with.
	ContentsHash(decrypter cipher.Decrypter) ([]byte, error)
	// Valid will verify the contents of the envelope.
	// Checks the envelopes contents for no integrity issues which would prevent the envelope from being read.
	Valid() error
	// DecrypterKind returns the byte ID for the decrypter needed for the envelope
	DecrypterKind() (byte, error)
}

Data definition for programmable envelopes.

func NewEnvelope

func NewEnvelope(encrypter cipher.Encrypter, o []CreateOptionsBuilder) (Data, error)

NewEnvelope create a new envelope with encrypter, public key, and settings. Envelope can then be used when sending messages.

func Unmarshal

func Unmarshal(buf []byte) (Data, error)

Unmarshal parses the envelope buffer representation in buf and places the decoded result in data.

type UInt64Bytes

type UInt64Bytes []byte

UInt64Bytes is a new "data type" that combines a variable size integer with a byte array to efficiently store both values.

func NewUInt64Bytes

func NewUInt64Bytes(i uint64, data []byte) UInt64Bytes

NewUInt64Bytes creates a `UInt64Bytes` with the identifier and data added.

func (UInt64Bytes) Bytes

func (u UInt64Bytes) Bytes() ([]byte, error)

Bytes extracts the data portion.

func (UInt64Bytes) UInt64

func (u UInt64Bytes) UInt64() (uint64, error)

UInt64 extracts the identified portion.

func (UInt64Bytes) Values

func (u UInt64Bytes) Values() (i uint64, b []byte, err error)

Values returns the identified and data from UInt64Bytes. Identified is of type `uint64`. Data is of type `[]byte`.

type ZeroX01

type ZeroX01 struct {
	UIBEncryptedLocationHash []byte   `protobuf:"bytes,1,opt,name=UIBEncryptedLocationHash,proto3" json:"UIBEncryptedLocationHash,omitempty"`
	EncryptedHash            []byte   `protobuf:"bytes,2,opt,name=encryptedHash,proto3" json:"encryptedHash,omitempty"`
	XXX_NoUnkeyedLiteral     struct{} `json:"-"`
	XXX_unrecognized         []byte   `json:"-"`
	XXX_sizecache            int32    `json:"-"`
}

Use hosted location where the decryptedhash is the same as the location. Location and encrypted hash are encrypted so only receipient can location and verify the message.

func NewZeroX01

func NewZeroX01(encrypter cipher.Encrypter, opts *CreateOpts) (*ZeroX01, error)

NewZeroX01 creates a new envelope of type ZeroX01. ZeroX01 envelope allows sending private messages with the minimal bytes by using `Uint64Bytes`.

func (*ZeroX01) ContentsHash

func (x *ZeroX01) ContentsHash(decrypter cipher.Decrypter) ([]byte, error)

ContentsHash returns a hash of the decrypted content. This can be used to verify the contents of the message have not been tampered with. UIBEncryptedLocationHash is decrypted to get a location hash. This is a UInt64Bytes and the data portion is the value for ContentsHash.

func (*ZeroX01) DecrypterKind added in v0.0.54

func (x *ZeroX01) DecrypterKind() (byte, error)

func (*ZeroX01) Descriptor

func (*ZeroX01) Descriptor() ([]byte, []int)

func (*ZeroX01) GetEncryptedHash

func (m *ZeroX01) GetEncryptedHash() []byte

func (*ZeroX01) GetUIBEncryptedLocationHash

func (m *ZeroX01) GetUIBEncryptedLocationHash() []byte

func (*ZeroX01) IntegrityHash

func (x *ZeroX01) IntegrityHash(decrypter cipher.Decrypter) ([]byte, error)

IntegrityHash returns a hash of the encrypted content. This can be used to validate the integrity of the contents before decrypting. Returns the value stored in EncryptedHash.

func (*ZeroX01) ProtoMessage

func (*ZeroX01) ProtoMessage()

func (*ZeroX01) Reset

func (m *ZeroX01) Reset()

func (*ZeroX01) String

func (m *ZeroX01) String() string

func (*ZeroX01) URL

func (x *ZeroX01) URL(decrypter cipher.Decrypter) (*url.URL, error)

URL returns the addressable location of the message, the URL may be encrypted requiring decrypter to be supplied. URL is contained in the UIBEncryptedLocationHash which must first be decrypted. The decrypted data is converted to `UInt64Bytes`. The extracted identified is used to look up the Message Location Indicator (MLI). MLI address and hash are combined to make an addressable URL.

func (*ZeroX01) Valid

func (x *ZeroX01) Valid() error

Valid checks the envelopes contents for no integrity issues which would prevent the envelope from being read.

func (*ZeroX01) XXX_DiscardUnknown

func (m *ZeroX01) XXX_DiscardUnknown()

func (*ZeroX01) XXX_Marshal

func (m *ZeroX01) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*ZeroX01) XXX_Merge

func (m *ZeroX01) XXX_Merge(src proto.Message)

func (*ZeroX01) XXX_Size

func (m *ZeroX01) XXX_Size() int

func (*ZeroX01) XXX_Unmarshal

func (m *ZeroX01) XXX_Unmarshal(b []byte) error

type ZeroX02 added in v0.0.51

type ZeroX02 struct {
	UIBEncryptedLocationHash []byte   `protobuf:"bytes,1,opt,name=UIBEncryptedLocationHash,proto3" json:"UIBEncryptedLocationHash,omitempty"`
	DecryptedHash            []byte   `protobuf:"bytes,2,opt,name=decryptedHash,proto3" json:"decryptedHash,omitempty"`
	XXX_NoUnkeyedLiteral     struct{} `json:"-"`
	XXX_unrecognized         []byte   `json:"-"`
	XXX_sizecache            int32    `json:"-"`
}

Use hosted location where the encrypted hash is the same as the location. Location and decrypted hash are encrypted so only receipient can location and verify the message.

func NewZeroX02 added in v0.0.51

func NewZeroX02(encrypter cipher.Encrypter, opts *CreateOpts) (*ZeroX02, error)

NewZeroX02 creates a new envelope of type ZeroX02. ZeroX02 envelope allows sending private messages with the minimal bytes by using `Uint64Bytes` where encryptedHash is the location.

func (*ZeroX02) ContentsHash added in v0.0.51

func (x *ZeroX02) ContentsHash(decrypter cipher.Decrypter) ([]byte, error)

ContentsHash returns a hash of the decrypted content. This can be used to verify the contents of the message have not been tampered with. Returns the value stored in DecryptedHash.

func (*ZeroX02) DecrypterKind added in v0.0.54

func (x *ZeroX02) DecrypterKind() (byte, error)

func (*ZeroX02) Descriptor added in v0.0.51

func (*ZeroX02) Descriptor() ([]byte, []int)

func (*ZeroX02) GetDecryptedHash added in v0.0.51

func (m *ZeroX02) GetDecryptedHash() []byte

func (*ZeroX02) GetUIBEncryptedLocationHash added in v0.0.51

func (m *ZeroX02) GetUIBEncryptedLocationHash() []byte

func (*ZeroX02) IntegrityHash added in v0.0.51

func (x *ZeroX02) IntegrityHash(decrypter cipher.Decrypter) ([]byte, error)

IntegrityHash returns a hash of the encrypted content. This can be used to validate the integrity of the contents before decrypting. UIBEncryptedLocationHash is decrypted to get a location hash. This is a UInt64Bytes and the data portion is the value for IntegrityHash.

func (*ZeroX02) ProtoMessage added in v0.0.51

func (*ZeroX02) ProtoMessage()

func (*ZeroX02) Reset added in v0.0.51

func (m *ZeroX02) Reset()

func (*ZeroX02) String added in v0.0.51

func (m *ZeroX02) String() string

func (*ZeroX02) URL added in v0.0.51

func (x *ZeroX02) URL(decrypter cipher.Decrypter) (*url.URL, error)

URL returns the addressable location of the message, the URL may be encrypted requiring decrypter to be supplied. URL is contained in the UIBEncryptedLocationHash which must first be decrypted. The decrypted data is converted to `UInt64Bytes`. The extracted identified is used to look up the Message Location Indicator (MLI). MLI address and hash are combined to make an addressable URL.

func (*ZeroX02) Valid added in v0.0.51

func (x *ZeroX02) Valid() error

Valid checks the envelopes contents for no integrity issues which would prevent the envelope from being read.

func (*ZeroX02) XXX_DiscardUnknown added in v0.0.51

func (m *ZeroX02) XXX_DiscardUnknown()

func (*ZeroX02) XXX_Marshal added in v0.0.51

func (m *ZeroX02) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*ZeroX02) XXX_Merge added in v0.0.51

func (m *ZeroX02) XXX_Merge(src proto.Message)

func (*ZeroX02) XXX_Size added in v0.0.51

func (m *ZeroX02) XXX_Size() int

func (*ZeroX02) XXX_Unmarshal added in v0.0.51

func (m *ZeroX02) XXX_Unmarshal(b []byte) error

type ZeroX50

type ZeroX50 struct {
	Version              int32    `protobuf:"varint,1,opt,name=version,proto3" json:"version,omitempty"`
	EncryptedURL         []byte   `protobuf:"bytes,2,opt,name=encryptedURL,proto3" json:"encryptedURL,omitempty"`
	DecryptedHash        []byte   `protobuf:"bytes,3,opt,name=decryptedHash,proto3" json:"decryptedHash,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

original message format

func (*ZeroX50) ContentsHash

func (d *ZeroX50) ContentsHash(decrypter cipher.Decrypter) ([]byte, error)

ContentsHash returns a hash of the decrypted content. This can be used to verify the contents of the message have not been tampered with. DecryptedHash is returned as the value for ContentsHash.

func (*ZeroX50) DecrypterKind added in v0.0.54

func (x *ZeroX50) DecrypterKind() (byte, error)

func (*ZeroX50) Descriptor

func (*ZeroX50) Descriptor() ([]byte, []int)

func (*ZeroX50) GetDecryptedHash

func (m *ZeroX50) GetDecryptedHash() []byte

func (*ZeroX50) GetEncryptedURL

func (m *ZeroX50) GetEncryptedURL() []byte

func (*ZeroX50) GetVersion

func (m *ZeroX50) GetVersion() int32

func (*ZeroX50) IntegrityHash

func (d *ZeroX50) IntegrityHash(decrypter cipher.Decrypter) ([]byte, error)

IntegrityHash returns a hash of the encrypted content. This can be used to validate the integrity of the contents before decrypting. Decrypts the encrypted URL to extract the integrity hash.

func (*ZeroX50) ProtoMessage

func (*ZeroX50) ProtoMessage()

func (*ZeroX50) Reset

func (m *ZeroX50) Reset()

func (*ZeroX50) String

func (m *ZeroX50) String() string

func (*ZeroX50) URL

func (d *ZeroX50) URL(decrypter cipher.Decrypter) (*url.URL, error)

URL returns the addressable location of the message, the URL may be encrypted requiring decrypter to be supplied. URL is contained in the EncryptedURL which must first be decrypted. The decrypted data is converted to a URL and returned.

func (*ZeroX50) Valid

func (d *ZeroX50) Valid() error

Valid will verify the contents of the envelope. Checks the presence of required fields encrypted URL and decrypted hash.

func (*ZeroX50) XXX_DiscardUnknown

func (m *ZeroX50) XXX_DiscardUnknown()

func (*ZeroX50) XXX_Marshal

func (m *ZeroX50) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*ZeroX50) XXX_Merge

func (m *ZeroX50) XXX_Merge(src proto.Message)

func (*ZeroX50) XXX_Size

func (m *ZeroX50) XXX_Size() int

func (*ZeroX50) XXX_Unmarshal

func (m *ZeroX50) XXX_Unmarshal(b []byte) error

Jump to

Keyboard shortcuts

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