b64buff

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package b64buff implements a bit buffer that can be represented as URL string.

The bit buffer allows to read and write any number of bits. The encoding is similar to Base64 but different. It has no padding. Currently it cannot be changed.

Index

Constants

This section is empty.

Variables

View Source
var (
	WrongNbBits   = errors.New("Impossible number of bits")
	NotEnoughData = errors.New("No enough data to read")
	NotAligned    = errors.New("Buffer not aligned")
	EncodingError = errors.New("Error in encoding")
)

Functions

func RandomString

func RandomString(length uint32) (ret string, err error)

RandomString produces a random readable string of the given length. The returned string is a valid B64 encoded random value.

func RandomUInt32

func RandomUInt32(nbBits uint8) (uint32, error)

RandomUInt32 returns a uniform randow value between 0 and 2^nbBits - 1.

Types

type Buffer

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

Buffer is a bit buffer.

func NewRandom

func NewRandom(nbBits uint32) (ret *Buffer, err error)

Random create a Buffer containing at least nbBits random bits.

func (*Buffer) AlignRead

func (self *Buffer) AlignRead() (ret byte)

AlignRead forces the read to be aligned, by discarding surnumerous bits.

The discarded bits are the less significant bits that would have been returned by a call to ReadUInt32. Those bits are returned by the method.

func (*Buffer) B64Reader

func (self *Buffer) B64Reader() io.Reader

B64Reader return a encoded reader on the Buffer.

Calling Read on the returned value fail if the read is not aligned. The read is aligned if the sum of read bits from the buffer can be divided by 6.

func (*Buffer) Len

func (self *Buffer) Len() uint32

Len returns the number of bits in the buffer.

func (*Buffer) ReadAllB64

func (self *Buffer) ReadAllB64() (ret string, err error)

ReadAllB64 reads the whole buffer to the string.

The call fails if the read is not aligned. The read is aligned if the sum of read bits from the buffer can be divided by 6.

func (*Buffer) ReadUInt32

func (self *Buffer) ReadUInt32(nbBits uint8) (ret uint32, err error)

ReadUInt32 reads nbBits of the buffer into the lower bits of ret.

func (*Buffer) WriteB64

func (self *Buffer) WriteB64(str string) (err error)

WriteB64 writes the whole string into the buffer.

The string must have been correctly encoded by a call to ReadAllB64.

The call fails if the write is not aligned. The write is aligned if the sum of written bits into the buffer can be divided by 6.

func (*Buffer) WriteUInt32

func (self *Buffer) WriteUInt32(data uint32, nbBits uint8) error

WriteUInt32 writes the lower nbBits of data to the buffer.

Jump to

Keyboard shortcuts

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