format

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: BSD-2-Clause Imports: 8 Imported by: 55

Documentation

Index

Constants

View Source
const (
	KeyFPLen        = 32
	MacLen          = 32
	EphemeralRIDLen = 8
	SIHLen          = 25
	RecipientIDLen  = EphemeralRIDLen + SIHLen

	MinimumPrimeSize = 2*MacLen + RecipientIDLen

	AssociatedDataSize = KeyFPLen + MacLen + RecipientIDLen
)

Variables

This section is empty.

Functions

func DigestContents

func DigestContents(c []byte) string

DigestContents - message.Digest that works without the message format

Types

type Fingerprint

type Fingerprint [KeyFPLen]byte

func NewFingerprint

func NewFingerprint(b []byte) Fingerprint

NewFingerprint generates a new Fingerprint with the provided bytes.

func (Fingerprint) Bytes

func (fp Fingerprint) Bytes() []byte

Bytes returns the fingerprint as a byte slice.

func (Fingerprint) MarshalJSON

func (fp Fingerprint) MarshalJSON() ([]byte, error)

MarshalJSON adheres to the json.Marshaler interface.

func (Fingerprint) String

func (fp Fingerprint) String() string

String returns the fingerprint as a base 64 encoded string. This functions satisfies the fmt.Stringer interface.

func (*Fingerprint) UnmarshalJSON

func (fp *Fingerprint) UnmarshalJSON(data []byte) error

UnmarshalJSON adheres to the json.Unmarshaler interface.

type Message

type Message struct {
	// contains filtered or unexported fields
}

Message structure stores all the data serially. Subsequent fields point to subsections of the serialised data.

func NewMessage

func NewMessage(numPrimeBytes int) Message

NewMessage creates a new empty message based upon the size of the encryption primes. All subcomponents point to locations in the internal data buffer. Panics if the prime size to too small.

func Unmarshal

func Unmarshal(b []byte) (Message, error)

Unmarshal unmarshalls a byte slice into a new Message.

func (Message) ContentsSize

func (m Message) ContentsSize() int

ContentsSize returns the maximum size of the contents.

func (Message) Copy

func (m Message) Copy() Message

Copy returns a copy of the message.

func (Message) Digest

func (m Message) Digest() string

Digest gets a digest of the message contents, primarily used for debugging

func (Message) GetContents

func (m Message) GetContents() []byte

GetContents returns the exact contents of the message. This size of the return is based on the size of the contents actually stored.

func (Message) GetEphemeralRID

func (m Message) GetEphemeralRID() []byte

GetEphemeralRID returns the ephemeral recipient ID.

func (Message) GetKeyFP

func (m Message) GetKeyFP() Fingerprint

GetKeyFP gets the key Fingerprint flips the first bit to 0 on return

func (Message) GetMac

func (m Message) GetMac() []byte

GetMac gets the MAC. flips the first bit to 0 on return

func (Message) GetPayloadA

func (m Message) GetPayloadA() []byte

GetPayloadA returns payload A, which is the first half of the message.

func (Message) GetPayloadB

func (m Message) GetPayloadB() []byte

GetPayloadB returns payload B, which is the last half of the message.

func (Message) GetPrimeByteLen

func (m Message) GetPrimeByteLen() int

GetPrimeByteLen returns the size of the prime used.

func (Message) GetRawContents

func (m Message) GetRawContents() []byte

GetRawContents returns the exact contents of the message. This field crosses over the group barrier and the setter of this is responsible for ensuring the underlying payloads are within the group. flips the first bit to 0 on return

func (Message) GetRawContentsSize

func (m Message) GetRawContentsSize() int

GetRawContentsSize returns the exact contents of the message.

func (Message) GetSIH

func (m Message) GetSIH() []byte

GetSIH return the Service Identification Hash.

func (Message) GoString

func (m Message) GoString() string

GoString returns the Message key fingerprint, MAC, ephemeral recipient ID, identity fingerprint, and contents as a string. This functions satisfies the fmt.GoStringer interface.

func (*Message) Marshal

func (m *Message) Marshal() []byte

Marshal marshals the message into a byte slice. Use this when sending over the wire or other socket connection. Do not use this if you ever want to compare a marshalled message with itself, because both the Ephemeral ID and SIH are modified on each send attempt.

func (*Message) MarshalImmutable

func (m *Message) MarshalImmutable() []byte

MarshalImmutable marshals the message into a byte slice. Note that the Ephemeral ID and the SIH both change every time a message is sent. This function 0's those fields to guarantee that the same message will be byte identical with itself when Marshalled.

func (Message) SetContents

func (m Message) SetContents(c []byte)

SetContents sets the contents of the message. This overwrites any storage already in the message but will not clear bits beyond the size of the passed contents. Panics if the passed contents is larger than the maximum contents size.

func (Message) SetEphemeralRID

func (m Message) SetEphemeralRID(ephemeralRID []byte)

SetEphemeralRID copies the ephemeral recipient ID bytes into the message.

func (Message) SetGroupBits

func (m Message) SetGroupBits(bitA, bitB bool)

SetGroupBits allows the first and second bits to be set in the payload. This should be used with code which determines if the bit can be set to 1 before proceeding.

func (Message) SetKeyFP

func (m Message) SetKeyFP(fp Fingerprint)

SetKeyFP sets the key Fingerprint. Checks that the first bit of the Key Fingerprint is 0, otherwise it panics.

func (Message) SetMac

func (m Message) SetMac(mac []byte)

SetMac sets the MAC. Checks that the first bit of the MAC is 0, otherwise it panics.

func (Message) SetPayloadA

func (m Message) SetPayloadA(payload []byte)

SetPayloadA copies the passed byte slice into payload A. If the specified byte slice is not exactly the same size as payload A, then it panics.

func (Message) SetPayloadB

func (m Message) SetPayloadB(payload []byte)

SetPayloadB copies the passed byte slice into payload B. If the specified byte slice is not exactly the same size as payload B, then it panics.

func (Message) SetRawContents

func (m Message) SetRawContents(c []byte)

SetRawContents sets the raw contents of the message. This field crosses over the group barrier and the setter of this is responsible for ensuring the underlying payloads are within the group. This will panic if the payload is greater than the maximum size. This overwrites any storage already in the message. If the passed contents is larger than the maximum contents size this will panic.

func (Message) SetSIH

func (m Message) SetSIH(identityFP []byte)

SetSIH sets the Service Identification Hash, which should be generated via fingerprint.IdentityFP.

func (*Message) Version

func (m *Message) Version() uint8

Version returns the encoding version.

Jump to

Keyboard shortcuts

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