utils

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// MaxChunkLength is the maximum size of a chunk
	MaxChunkLength = 4096

	// PathSeparator is string of unix filesystem
	PathSeparator = "/"

	// MaxPodNameLength defines how long a pod name can be
	MaxPodNameLength = 64

	// SpanLength of a chunk
	SpanLength = 8

	// DeletedFeedMagicWord is written in a feed after it gets deleted from fairOS
	DeletedFeedMagicWord = "__Fair__"
)
View Source
const (
	// AddressLength defines the length for the address
	AddressLength = 20
)

Variables

View Source
var (
	// ErrEmptyString is returned when a hex string is empty.
	ErrEmptyString = &decError{"empty hex string"}
	// ErrMissingPrefix is returned when a hex string does not have a 0x prefix.
	ErrMissingPrefix = &decError{"hex string without 0x prefix"}

	// ErrOddLength is returned when a hex string has an odd length.
	ErrOddLength = &decError{"hex string of odd length"}
)

Functions

func CombinePathAndFile added in v0.5.3

func CombinePathAndFile(path, fileName string) string

CombinePathAndFile joins filename with provided path

func Decode

func Decode(input string) ([]byte, error)

Decode decodes a hex string with 0x prefix.

func DecryptBytes added in v0.9.1

func DecryptBytes(passphrase, cipherText []byte) ([]byte, error)

DecryptBytes decrypts the cipherText using the passphrase

func Encode

func Encode(b []byte) string

Encode encodes b as a hex string with 0x prefix. skipcq: TCV-001

func EncryptBytes added in v0.9.1

func EncryptBytes(passphrase, message []byte) ([]byte, error)

EncryptBytes encrypts the message using the passphrase

func GetRandBytes added in v0.9.1

func GetRandBytes(n int) ([]byte, error)

GetRandBytes return random bytes array of length n

func GetRandString added in v0.8.0

func GetRandString(n int) (string, error)

GetRandString return random string of length n

func HashString

func HashString(path string) []byte

HashString returns the bmt hash of a string skipcq: TCV-001

func NewChunkWithSpan added in v0.5.0

func NewChunkWithSpan(data []byte) (swarm.Chunk, error)

NewChunkWithSpan returns a chunk with span

func NewChunkWithoutSpan added in v0.5.0

func NewChunkWithoutSpan(data []byte) (swarm.Chunk, error)

NewChunkWithoutSpan returns a chunk without span

Types

type Address

type Address [AddressLength]byte

Address is a simplified implementation of eth address

func HexToAddress

func HexToAddress(s string) Address

HexToAddress creates a new address from given hex string

func NewAddress

func NewAddress(b []byte) Address

NewAddress returns a new address from the given byte address

func (*Address) Hex

func (a *Address) Hex() string

Hex returns the hex of the corresponding address

func (*Address) SetBytes

func (a *Address) SetBytes(b []byte)

SetBytes sets address bytes

func (*Address) String

func (a *Address) String() string

func (*Address) ToBytes

func (a *Address) ToBytes() []byte

ToBytes returns the address bytes

type Reference

type Reference struct {
	R []byte `json:"swarm"`
}

Reference is used for creating pod sharing references

func NewReference

func NewReference(b []byte) Reference

NewReference creates a Reference

func ParseHexReference

func ParseHexReference(s string) (a Reference, err error)

ParseHexReference creates a Reference from a Reference string

func (Reference) Bytes

func (ref Reference) Bytes() []byte

Bytes returns the bytes form of the reference

func (Reference) String

func (ref Reference) String() string

type SharingReference

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

SharingReference is used for sharing files

func NewSharingReference

func NewSharingReference(b []byte, n int64) SharingReference

NewSharingReference creates a reference from swarm reference and time

func ParseSharingReference

func ParseSharingReference(s string) (a SharingReference, err error)

ParseSharingReference creates a SharingReference from a SharingReference string

func (SharingReference) GetNonce

func (ref SharingReference) GetNonce() int64

GetNonce returns the nonce

func (SharingReference) GetRef

func (ref SharingReference) GetRef() []byte

GetRef returns the reference

func (SharingReference) String

func (ref SharingReference) String() string

Jump to

Keyboard shortcuts

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