needle

package
v0.0.0-...-0d32183 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: Unlicense Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HashLength is the length in bytes of the hash prefix in any message
	HashLength = len(Hash{})
	// PayloadLength is the length of the remaining bytes of the message.
	PayloadLength = len(Payload{})
	// NeedleLength is the number of bytes required for a valid needle.
	NeedleLength = HashLength + PayloadLength
	// ErrorDNE is returned when a key/value par does not exist
	ErrorDNE = errors.Error("Does Not Exist")
	// ErrorInvalidHash is an error for in invalid hash
	ErrorInvalidHash = errors.Error("invalid blake2b-256 hash")
	// ErrorByteSliceLength is an error for an invalid byte slice length passed in to New or FromBytes
	ErrorByteSliceLength = errors.Error("invalid byte slice length")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Hash

type Hash [32]byte

Hash represents an array of length HashLength

type Needle

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

Needle is an immutable container for a [192]byte array that containers a 160 byte payload and a 32 byte blake2b hash of the payload.

func FromBytes

func FromBytes(b []byte) (*Needle, error)

FromBytes is intended convert raw bytes (from UDP or storage) into a Needle. It takes a byte slice and expects it to be exactly the length of NeedleLength. The byte slice should consist of the first 32 bytes being the blake2b hash of the payload and the payload bytes. This function verifies the length of the byte slice, copies the bytes into a private [192]byte array, and validates the Needle. It returns a reference to a Needle and an error.

func New

func New(payload []byte) (*Needle, error)

New creates a Needle used for submitting a payload to a Haystack sever. It takes a Payload byte slice that is 160 bytes in length and returns a reference to a Needle and an error. The purpose of this function is to make it easy to create a new Needle from a payload. This function handles creating a blake2b hash of the payload, which is used by the Needle to submit to a haystack server.

func (Needle) Bytes

func (n Needle) Bytes() []byte

Bytes returns a byte slice of the entire 192 byte hash + payload

func (Needle) Hash

func (n Needle) Hash() Hash

Hash returns a copy of the bytes of the blake2b 256 hash of the Needle payload.

func (Needle) Payload

func (n Needle) Payload() Payload

Payload returns a byte slice of the Needle payload

type Payload

type Payload [160]byte

Payload represents an array of length PayloadLength

Jump to

Keyboard shortcuts

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