lib

package module
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2022 License: AGPL-3.0 Imports: 39 Imported by: 2

README

1o.fyi

Hi there! This go module is currently unstable. 
Mostly, it serves as a place to aggregate 
commonly used bits and bobs for other go applications. 

A lot of this is the product of my own learning process.
As such you can expect the APIs to change without warning.

If you have any questions feel free to reach out!

Documentation

Index

Constants

View Source
const (
	BitFlagUse                                                 string = "bf"
	BitFlagShort                                               string = "interact with bitflags"
	BitFlagAlias0, BitFlagAlias1, BitFlagAlias2, BitFlagAlias3 string = "bflag", "bflags", "bit-flag", "bit-flags"
)

For cli interface

View Source
const (
	// uint8 values for 0, 1.
	Zero Bit = 48 + iota
	One
	// the probability to be distributed across the Sets of U.
	Probility float64 = 1.0
)
View Source
const (
	Application string = ""
	Library     string = "1ofi/lib"
)

The version is embeded into the library, stored in the following local structure A bash CLI exists for modifying this same structure https://git.sr.ht/~johns/tag

.tag
├── .tag/MNOR
├── .tag/MVAR
├── .tag/RLSE

Variables

View Source
var (
	ErrNotPEMEncoded     = errors.New("invalid: Not PEM Encoded")
	ErrExcessInput       = errors.New("invalid: Excess")
	ErrUnknownHeader     = errors.New("invalid: Unknown Header Type")
	ErrUnknownHash       = errors.New("invalid: Unknown Hash Type")
	ErrInvalidHeader     = errors.New("invalid: PEM Header")
	ErrMismatchedVersion = errors.New("invalid: Mismatched Version")
	ErrFutureTimestamp   = errors.New("invalid: Timestamp in the future")
)

Errors potentially returned from PEM decoding.

View Source
var (
	ErrServerPublicKey = errors.New("client: could not get serverkey")
)
View Source
var Major string
View Source
var Minor string
View Source
var Release string

We accept that release values may have arbitrary strings concatinated to the end of it and do not parse it to an integer.

View Source
var Version string

This is constructed from the embedded version tag

Functions

func Any

func Any(b ...bool) bool

Return any value in b true.

func Context

func Context(purpose string) string

Generates a context string in the format:

vX.X.X-purpose-time

func DecodeBase64

func DecodeBase64(arr []byte) chan []byte

func DecodeHex

func DecodeHex(src []byte) chan []byte

func DeriveCA

returns a new certificate authority issued from a parent x509 certificate

func Empty

func Empty(arr []byte) chan []byte

func EncodeBase64

func EncodeBase64(arr []byte) chan []byte

func EncodeHex

func EncodeHex(src []byte) chan []byte

func Even

func Even(i uint64) uint64

Rounds up odd uint64

func Expand

func Expand(k []byte, toSize int) []byte

func F_ALL

func F_ALL(s *Set) bool

Filter that guarentees all Sets of U. to have a filter that guarentees no sets use Inverse(F_ALL).

func F_LSB0

func F_LSB0(s *Set) bool

Filters for all Sets where the least significant bit == 0. To filter the set of Sets where lsb == 1 use Inverse(F_LSB0).

func F_MSB0

func F_MSB0(s *Set) bool

Filters for all sets where the most significant bit == 0. To filter the set of Sets where msb == 1 use Inverse(F_MSB0).

func FmtLetsEncrypt

func FmtLetsEncrypt(domain string) (string, string)

func GetMajor

func GetMajor() (int, error)

func GetMinor

func GetMinor() (int, error)

func Ham

func Ham(t0, t1 []byte) int

returns the hamming distance of two byte arrays.

func MaxEq

func MaxEq(x, y int) int

returns the maximum of x, y or x should x == y.

func MaxR

func MaxR() []byte

maximum sized single read of entropy

func MinEq

func MinEq(x, y int) int

returns the minimum of x, y or x should x == y.

func NewCName

func NewCName(commonName string) pkix.Name

creates a new pkix.Name with only a common name

func NewCsr

creates a new certificate signing request for a

func NewEndEntityCert

func NewEndEntityCert(sk ed25519.PrivateKey, req *x509.CertificateRequest, parent *x509.Certificate) (*x509.Certificate, error)

issues a new certificate from a parent certificate authority

func NewName

func NewName(commonName, country, org string) pkix.Name

creates a new pkix.Name

func Nor

func Nor(err error) bool

func Outln

func Outln(ifces ...interface{}) error

func Outlnh

func Outlnh(ifces ...interface{}) error

func Outlnp

func Outlnp(ifces ...interface{}) error

func ParseURI

func ParseURI(u *url.URL) map[string]string

func PemDecodeCRL

func PemDecodeCRL(rawPemBytes []byte) (*pkix.CertificateList, error)

der encodes a pem encoded crl

func PemDecodeCRT

func PemDecodeCRT(rawCRT []byte) (*x509.Certificate, error)

der encodes a pem encoded crt

func PemDecodeCSR

func PemDecodeCSR(rawCSR []byte) (*x509.CertificateRequest, error)

pem encodes a der encoded csr

func PemEncodeCRL

func PemEncodeCRL(rawCRL []byte) []byte

pem encodes a der encoded crl

func PemEncodeCRT

func PemEncodeCRT(rawCRT []byte) []byte

pem encodes a der encoded crt

func PemEncodeCSR

func PemEncodeCSR(rawCSR []byte) []byte

pem encodes a der encoded csr

func R added in v0.0.7

func R(n int) *big.Int

returns a random big int of maximum n size

func Rb added in v0.0.7

func Rb() uint

Returns either 0, 1 with "equal" probability

func RedirectServer

func RedirectServer() *http.Server

func Ri added in v0.0.7

func Ri(n *big.Int) *big.Int

returns a random big int of maximum n size

func Rp

func Rp(s int) *big.Int

returns a random prime with s+-1 bits

func Rpb

func Rpb(s int) []byte

conveniance wrapper around Rp

func SelfSignedCA

func SelfSignedCA(sk ed25519.PrivateKey, req *x509.CertificateRequest) (*x509.Certificate, error)

returns a new self-signed certificate

func Sock

func Sock(at string, with []byte) error

func Split

func Split(k []byte, p int) ([][]byte, int)

Splits a k sized byte array p pieces. Returns the sliced array of arrays and the amount of spillover.

func Sum

func Sum(x []byte) int

func ToBase

func ToBase(raw []byte, base int) []byte

func TransformRange

func TransformRange(value, xMin, xMax, nMin, nMax float64) float64

performs a linear transform on value from a known xMin, xMax to the new range nMin, nMax

func XorK

func XorK(x []byte, k byte) []byte

func XorY

func XorY(x, y []byte) []byte

Types

type Alg

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

func Establish

func Establish(t, n string) *Alg

Returns a raw socket connection to the subsystem. If any errors are encountered while establishing the socket connection, return nil.

type Bit

type Bit uint8

representative of individual bits.

func AbsEq added in v0.0.7

func AbsEq(x, y *big.Int) Bit

type Bitflag

type Bitflag uint8

A standad bitmask for flags

func New

func New(u uint8) *Bitflag

create a new flag

func (*Bitflag) IsOn

func (fg *Bitflag) IsOn() bool

checks if a bitflag is on

func (*Bitflag) Toggle

func (fg *Bitflag) Toggle() *Bitflag

flips; then returns *uflag

type DirectoryGraph

type DirectoryGraph struct {

	// at creation Node is the serialized FileNode at path
	Node *ring.Ring
	// contains filtered or unexported fields
}

func NewDirectoryGraph

func NewDirectoryGraph(root string) DirectoryGraph

Creates a new directory graph, all subdirectories of root are recursively traversed when this function is called

func NewGraphRing

func NewGraphRing(roots ...string) DirectoryGraph

Creates an array of new directory graphs and links them into one ring

func (DirectoryGraph) FilterFor

func (e DirectoryGraph) FilterFor(exts ...FileExtension) ExtToFileNode

filters the DirectoryGraph using the FileExtensions (keys) of extMap for each extension we populate an array of all FileNode using that extension

func (DirectoryGraph) Flatten added in v0.0.12

func (e DirectoryGraph) Flatten() []*FileNode

Returns an array of FileNodes. The results were serialized when the DirectoryGraph were created' therefore this struct may contain stale data.

func (DirectoryGraph) InvertByExt

func (e DirectoryGraph) InvertByExt() ExtToFileNode

inverts a DirectoryGraph creating a constant time lookup from map[FileExtension][]FileNode This includes the SysInfo last acquired from serialize() Acquires a lock on the result & e.DirectoryGraph while populating the index

func (DirectoryGraph) Open added in v0.0.12

func (e DirectoryGraph) Open() []*os.File

Returns an array of open files. If any errors are encountered while attempting to open a file in the graph they are silently ignored. The output may be empty.

func (DirectoryGraph) OpenAll

func (e DirectoryGraph) OpenAll(exts ...FileExtension) []*os.File

type EncodingSet

type EncodingSet [2]Transform

[0] encodes bytes & [1] decodes bytes, theorhetically atleast

type ExtToFileNode

type ExtToFileNode map[FileExtension][]FileNode

func FindKeys

func FindKeys(filepaths ...string) ExtToFileNode

returns any files using a common set of certificate file extensions from a ring of all children of filepaths should a given filepath have any. see DirectoryGraph for more details

func InitExtMap

func InitExtMap(exts ...FileExtension) ExtToFileNode

func (ExtToFileNode) Exists

func (e ExtToFileNode) Exists(ext FileExtension) bool

func (ExtToFileNode) Flatten

func (e ExtToFileNode) Flatten() []FileNode

flattens the FileNodes (values) down to an array

func (ExtToFileNode) OpenAll

func (e ExtToFileNode) OpenAll() []*os.File

type FileExtension

type FileExtension string
const (
	EXT_JSON  FileExtension = ".json"
	EXT_CSV   FileExtension = ".csv"
	EXT_TXT   FileExtension = ".txt"
	EXT_MD    FileExtension = ".md"
	EXT_MOV   FileExtension = ".mov"
	EXT_WAV   FileExtension = ".wav"
	EXT_GIF   FileExtension = ".gif"
	EXT_PNG   FileExtension = ".png"
	EXT_JPG   FileExtension = ".jpg"
	EXT_JPEG  FileExtension = ".jpeg"
	EXT_CRT   FileExtension = ".crt"
	EXT_CERT  FileExtension = ".cert"
	EXT_PEM   FileExtension = ".pem"
	EXT_CSR   FileExtension = ".csr"
	EXT_SH    FileExtension = ".sh"
	EXT_GO    FileExtension = ".go"
	EXT_JS    FileExtension = ".js"
	EXT_PY    FileExtension = ".py"
	EXT_C     FileExtension = ".c"
	EXT_AGE   FileExtension = ".age"
	EXT_NOEXT FileExtension = ""
)

type FileNode

type FileNode struct {
	Path      string
	Ext       FileExtension
	Dir       fs.DirEntry
	TarHeader *tar.Header
	Sys       SysInfo
}

type FlagToEncodingSet

type FlagToEncodingSet map[string]EncodingSet

maps flags to their possible encoding functions

func GenEncSet

func GenEncSet() FlagToEncodingSet

Mapping of cli flags to encoding sets, including the default mapped to ""

func (FlagToEncodingSet) GetOrDefault

func (set FlagToEncodingSet) GetOrDefault(flag string) (Transform, Transform)

Gets the encoding set or returns athe default select encoding

type LClient

type LClient struct {
	API, User            string
	PublicKey, ServerKey *age.X25519Recipient
	// contains filtered or unexported fields
}

func NewClient

func NewClient(api, user string, key *age.X25519Identity) (*LClient, error)

func NewClientFromFile

func NewClientFromFile(api, user string, f *os.File) (*LClient, error)

func NewClientFromPath

func NewClientFromPath(api, user, path string) (*LClient, error)

func (*LClient) Decrypt

func (c *LClient) Decrypt(dst, src *bytes.Buffer) (*bytes.Buffer, error)

func (*LClient) Encrypt

func (c *LClient) Encrypt(dst, src *bytes.Buffer) (*bytes.Buffer, error)

func (*LClient) FmtRequest

func (c *LClient) FmtRequest(endpoint ValidEndpoint, args ...string) *bytes.Buffer

func (*LClient) Get

func (c *LClient) Get(key string) ([]byte, error)

func (*LClient) GetKey

func (c *LClient) GetKey() ([]byte, error)

func (*LClient) GetServerKey

func (c *LClient) GetServerKey() (*age.X25519Recipient, error)

func (*LClient) Home

func (c *LClient) Home() ([]byte, error)

func (*LClient) Set

func (c *LClient) Set(key, val string) ([]byte, error)

func (*LClient) SetKey

func (c *LClient) SetKey() ([]byte, error)

type Linker

type Linker struct {
	S  *http.Server
	RC *redis.Client
	SM map[string]func(rw http.ResponseWriter, r *http.Request)
}

func NewLinker

func NewLinker(pubDomain, redisDomain string) (*Linker, error)

Creates a new linker pubDomain is the public-facing domain name used by the server. (e.g. foo.com) redisDomain is the domain name of the redis instance to connect to. if no port is specified on the end of either domain (e.g. foo.com:443) then a default port of 443 will be used for pubDomain and a default port of 31527 will be used for the redis instance.

func (*Linker) AddRoute

func (l *Linker) AddRoute(route string, f func(rw http.ResponseWriter, r *http.Request))

func (*Linker) Kill

func (l *Linker) Kill() error

func (*Linker) Serve

func (l *Linker) Serve(cert, key string) error

type Set

type Set struct {
	V *big.Int // value.
	P float64  // probability.
}

func S

func S(i *big.Int) *Set

Returns a new Set from a big.Int.

func Sb

func Sb(raw []byte) *Set

Returns a new Set from a byte array.

func Sf added in v0.0.7

func Sf(b int, raw []byte) *Set

Returns a new Set from a byte array.

func Si

func Si(i int) *Set

Returns a new Set from an int.

func Ss

func Ss(s string) *Set

Returns a new Set from a string.

func (*Set) Base

func (set *Set) Base(base int) []byte

Returns the base representation of a Set.

func (*Set) Bitsize added in v0.0.7

func (s *Set) Bitsize() int

Returns the number of bits in s.

func (*Set) Buffer added in v0.0.7

func (s *Set) Buffer() *bytes.Buffer

Returns a Buffer of s.

func (*Set) Bytes

func (s *Set) Bytes() []byte

Returns the set as a []byte.

func (*Set) Bytesize added in v0.0.7

func (s *Set) Bytesize() int

Returns the number of bytes in s.

func (*Set) Clear

func (s *Set) Clear() *Set

Clears the value of s and returns s.

func (*Set) Eq

func (set *Set) Eq(x *Set) bool

Checks the equality of two Sets.

func (*Set) Expand added in v0.0.7

func (s *Set) Expand(to []byte) []byte

func (*Set) Flipflop added in v0.0.9

func (set *Set) Flipflop() *Set

Like the kind you wear to the beach.

func (*Set) Gt

func (s *Set) Gt(set *Set) bool

Checks if Set s > set.

func (*Set) Ham

func (s *Set) Ham(set *Set) *Set

Returns a new Set containing the hamming distance between s and set. s is not changed.

func (*Set) LShift added in v0.0.7

func (s *Set) LShift() *Set

func (*Set) Lsb

func (set *Set) Lsb() Bit

Returns the least significant bit of set.

func (*Set) Lsbs

func (set *Set) Lsbs(last uint) []Bit

Returns the least significant bit(s) of set.

func (*Set) Lt

func (s *Set) Lt(set *Set) bool

Checks if Set s < set.

func (*Set) MaxEq

func (s *Set) MaxEq(set *Set) *Set

func (*Set) MinEq

func (s *Set) MinEq(set *Set) *Set

func (*Set) Msb

func (set *Set) Msb() Bit

Returns the most significant bit of set.

func (*Set) Msbs

func (set *Set) Msbs(last uint) []Bit

Returns the most significant bit(s) of set.

func (*Set) Out added in v0.0.7

func (s *Set) Out()

Writes s to Stdout.

func (*Set) Permutate added in v0.0.7

func (s *Set) Permutate() *Universe

Returns a universe of bitlen(s)^2 permutations of s.

func (*Set) Permute added in v0.0.7

func (s *Set) Permute(bit int) (*Set, *Set, *Set)

Returns two permutations of s and a pseudo random prime of equal bit-length to s.

func (*Set) RShift added in v0.0.7

func (s *Set) RShift() *Set

func (*Set) Reader

func (s *Set) Reader() *bytes.Reader

Returns a Reader of s.

func (*Set) Scanner

func (s *Set) Scanner() *bufio.Scanner

Returns a Scanner of s.

func (*Set) Set added in v0.0.7

func (s *Set) Set(buff []byte) *Set

Replaces s with buff, return s.

func (*Set) Split added in v0.0.9

func (s *Set) Split() (*Set, *Set)

Creates and returns two deep copies of s and shifts each a single bit to the left or right, respectively. s is not changed.

func (*Set) String added in v0.0.7

func (s *Set) String() string

Returns the set as a []byte.

func (*Set) Sum added in v0.0.7

func (s *Set) Sum() *Set

Sets s to the 32-byte blake3 sum of s, return s.

func (*Set) T added in v0.0.7

func (s *Set) T(t Transform) *Set

Sets s equal to t(s), return s.

func (*Set) Weight

func (s *Set) Weight() *Set

func (*Set) Write added in v0.0.7

func (s *Set) Write(f *os.File) (int, error)

Writes s to f.

func (*Set) WriteAs added in v0.0.7

func (s *Set) WriteAs(base int, f *os.File) (int, error)

Writes s to f in form b.

func (*Set) Xor

func (s *Set) Xor(set *Set) *Set

Sets s equal to s xor set, return s.

type SysInfo

type SysInfo struct {
	Dev, Rdev, Size, Blksize, Nlink, Mode, Uid, Ino, Gid, X__pad0, Blocks int
	Atim, Mtim, Ctim                                                      Tsec
	X__unused                                                             [3]int
}

type Transform

type Transform func([]byte) chan []byte

The interface of decode & encode

type Tsec

type Tsec struct {
	Sec  int
	Nsec int
}

type Universe

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

a ring of discrete Sets. https://en.wikipedia.org/wiki/Discrete

func DecodePEM

func DecodePEM(raw []byte) (*Universe, error)

Decodes and Unmarshals a raw PEM encoded Universe; or return nil, error.

func DecodePEMFile

func DecodePEMFile(path string) (*Universe, error)

Attempts to read/decode a file at path into a Universe. Returns an error if the file cannot be read or decoded.

func PointDistribution

func PointDistribution(bits int) *Universe

Distributes all probability onto U0 where U == U[0..2]^bit and returns U.

func Uniform added in v0.0.12

func Uniform(N int64) *Universe

Evenly distributes U[0..N] over U, return U.

func UniformByExp added in v0.0.12

func UniformByExp(N, S int64) *Universe

Evenly distributes U[0..S^N] over U and returns U.

func UniformByPow added in v0.0.12

func UniformByPow(N, S int64) *Universe

Evenly distributes U[0^S..1^S..N] over U, return U.

func UniformDistribution

func UniformDistribution(N int64) *Universe

Evenly distributes U[0..2]^N over U and returns U.

func UniformDistributionRp

func UniformDistributionRp(N int64, Z int) *Universe

Evenly distributes U[Rp(Z)]^N over U and returns U.

func UniformFrom

func UniformFrom(bytes ...[]byte) *Universe

Returns a uniformly distributed Universe of ...bytes.

func UniformOfPrimes added in v0.0.13

func UniformOfPrimes(N, S int64) *Universe

Evenly distributes (probably) all primes between U[0..N] over U, return U. A Miller-Rabin test with S pseudorandomly chosen bases as well as a Baillie-PSW test is run on each number between U[0..N]. S = 1 is a solid default choice.

func UniformOver

func UniformOver(sets ...*Set) *Universe

Returns a uniformly distributed Universe of ...sets.

func UniformRange added in v0.0.7

func UniformRange(n, N int64) *Universe

Uniformly distributes U[2^n..2^N] returns U.

func (*Universe) Add

func (u *Universe) Add(y *Set) *Universe

Sets every Set s over u equal to U[s] + y, return u.

func (*Universe) Apply

func (u *Universe) Apply(t func(*Set, *Set) *Set, z *Set) *Universe

Sets every Set s over u equal to t(Si, z), return u.

func (*Universe) Bdp

func (u *Universe) Bdp() int

Returns the number of samples of U required to satisfy the bd paradox.

func (*Universe) Collect

func (u *Universe) Collect() map[string]int

Hashes every Set s over u with BLAKE3 and returns a map[hash]frequency.

func (*Universe) Div

func (u *Universe) Div(y *Set) *Universe

Sets every Set s over u equal to u[s] / y, return u.

func (*Universe) EncodePEM

func (u *Universe) EncodePEM() []byte

Returns a raw, pem encoded representation of all Sets over U.

func (*Universe) Expand added in v0.0.7

func (u *Universe) Expand() *Universe

Sets u equal to u ⋃ U, return u.

func (*Universe) Factorial

func (u *Universe) Factorial() *Set

Returns the factorial of u.

func (*Universe) Filter

func (u *Universe) Filter(f func(s *Set) bool) *Universe

Returns the uring of Sets satisfactory f.

func (*Universe) Headers

func (u *Universe) Headers() map[string]string

Returns formatted PEM headers for u.

func (*Universe) Insert

func (u *Universe) Insert(sets ...*Set) *Universe

Inserts sets to the end of u, return u.

func (*Universe) Intersection

func (u *Universe) Intersection(U *Universe) *Universe

Sets u equal to u ⋂ U, return u.

func (*Universe) Inverse

func (u *Universe) Inverse(f func(s *Set) bool) *Universe

Returns the uring of Sets inequal f.

func (*Universe) Join

func (u *Universe) Join(together ...*Universe) *Universe

Sets u equal to the intersection of ...together. Unlike Intersection, Join will not filter unique values.

func (*Universe) Mul

func (u *Universe) Mul(y *Set) *Universe

Sets every Set s over u equal to U[s] * y, return u.

func (*Universe) P

func (u *Universe) P() float64

Returns the probability across U.

func (*Universe) Push added in v0.0.7

func (u *Universe) Push(set *Set) *Universe

Links set to the end of u, return u.

func (*Universe) Sample added in v0.0.12

func (u *Universe) Sample() *Set

Returns a random *Set from u.

func (*Universe) Size

func (u *Universe) Size() int

returns the underlying ring size.

func (*Universe) SizeF

func (u *Universe) SizeF() float64

returns the underlying ring size.

func (*Universe) Slice

func (u *Universe) Slice(f func(s *Set) bool) (*Universe, *Universe)

Slices a Universe with f - returns the [satisfactory, inequal] subests

func (*Universe) Sqrt

func (u *Universe) Sqrt() float64

Returns the sqrt of U.

func (*Universe) Sum

func (u *Universe) Sum() *Set

Returns the sum of sets over u.

func (*Universe) Union

func (u *Universe) Union(U *Universe) *Universe

Sets u equal to u ⋃ U, return u.

func (*Universe) Write

func (u *Universe) Write(f *os.File, base int)

Writes u to f. The caller is responsible for closing f.

func (*Universe) WritePEM

func (u *Universe) WritePEM(f *os.File) (int, error)

PEM Encodes u and writes the result to f. The caller is responsible for closing f.

func (*Universe) Xor

func (u *Universe) Xor(y *Set) *Universe

Sets every Set s over u equal to U[s] XOR y, return u.

type ValidEndpoint

type ValidEndpoint string
const (
	GET_KEY ValidEndpoint = "get"
	SET_KEY ValidEndpoint = "set"
	HOME    ValidEndpoint = ""
)

Jump to

Keyboard shortcuts

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