keyman

package
v0.0.0-...-dde4a86 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2022 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const KsmFileName string = "key_state"

KsmFileName stores the name of the file used to store the key state (duh)

View Source
const PrimeSize int = 320 // 40 bytes

PrimeSize determines the size of the prime number to be used when creating the key

Variables

View Source
var ErrGenerationDeprecated = errors.New(
	"given generation was created before the current generation was set")

ErrGenerationDeprecated is self explanatory. Just read it.

Functions

This section is empty.

Types

type FingerMismatchError

type FingerMismatchError struct {
	ExpectedFingerprint [32]byte
	ActualFingerprint   [32]byte
}

FingerMismatchError is rained when the key fingerprint does not match

func (*FingerMismatchError) Error

func (e *FingerMismatchError) Error() string

type Generation

type Generation struct {
	//A list of all nodes included in the generation
	Nodes         []string
	CompleteNodes []string
	Elements      []*keyStateElement
}

Generation stores the information about specific key generation.

func (*Generation) AddCompleteNode

func (g *Generation) AddCompleteNode(ownerID string)

AddCompleteNode to the generation

func (*Generation) AddElement

func (g *Generation) AddElement(elem *keyStateElement)

AddElement to the generation

func (*Generation) RemoveCompleteNode

func (g *Generation) RemoveCompleteNode()

RemoveCompleteNode from the generation

func (*Generation) RemoveElement

func (g *Generation) RemoveElement()

RemoveElement fromm the generation

type Key

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

Key contains the full key together with its fingerprint

func GenerateKey

func GenerateKey(size int) (*Key, error)

GenerateKey creates a new key of the specified size. If the size does not equal 16, 24 or 32, an error is returned

func NewKey

func NewKey(data []byte) (*Key, error)

NewKey generates a new key from a set of bytes. If the number of bytes does not equal 16, 24 or 32, an error is returned

func RebuildKey

func RebuildKey(pieces []*KeyPiece) (*Key, error)

RebuildKey from a set of KeyPieces. This function will succeed iff len(pieces) >= requiredPieces from the Generate function.

func (Key) GetBytes

func (key Key) GetBytes() []byte

GetBytes returns the bytes of the key

func (Key) GetFingerprint

func (key Key) GetFingerprint() [32]byte

GetFingerprint returns the fingerprint of the key

type KeyPiece

type KeyPiece struct {
	Data              []byte
	ParentFingerprint [32]byte // The SHA-256 fingerprint of the key it was generated from.
	Prime             *big.Int // The prime number used in the generation of this KeyPiece.
	Seq               int64    // Where f(Seq) = Data, for some polynomial f
}

KeyPiece stores the individual information about a piece of the key

func GeneratePieces

func GeneratePieces(key *Key, numPieces, requiredPieces int64) ([]*KeyPiece, error)

GeneratePieces from key. The number is defined by numPieces. requiredPieces is the number of KeyPieces needed to reconstruct the original key.

type KeyStateMachine

type KeyStateMachine struct {
	CurrentGeneration    int64
	InProgressGeneration int64
	DeprecatedGeneration int64

	// The first index indicates the generation.
	// The second index is unimportant as order doesn't matter there.
	Generations map[int64]*Generation

	// This is, once again, to avoid an import cycle
	PfsDir string

	// Channel is pushed to every time a new generation is created.
	Events chan bool
	// contains filtered or unexported fields
}

KeyStateMachine controls the key state

var StateMachine *KeyStateMachine

StateMachine is an instance of KeyStateMachine

func NewKSM

func NewKSM(pfsDir string) *KeyStateMachine

NewKSM returns a new instantiated KeyStateMachine

func NewKSMFromPFSDir

func NewKSMFromPFSDir(pfsDir string) (*KeyStateMachine, error)

NewKSMFromPFSDir returns a new instantiated KeyStateMachine from the specific paranoid directory

func NewKSMFromReader

func NewKSMFromReader(reader io.Reader) (*KeyStateMachine, error)

NewKSMFromReader returns a new instantiated KeyStateMachine from the io.Reader interface

func (*KeyStateMachine) GetCurrentGeneration

func (ksm *KeyStateMachine) GetCurrentGeneration() int64

GetCurrentGeneration returns the number of the current gen.

func (*KeyStateMachine) GetInProgressGenertion

func (ksm *KeyStateMachine) GetInProgressGenertion() int64

GetInProgressGenertion returns the number of the new upcoming gen. TODO: s/GetInProgressGenertion/GetInProgressGeneration

func (*KeyStateMachine) GetNodes

func (ksm *KeyStateMachine) GetNodes(generation int64) ([]string, error)

GetNodes of the generation. If there is a problem with getting the nodes an error is returned

func (*KeyStateMachine) NeedsReplication

func (ksm *KeyStateMachine) NeedsReplication(uuid string, generationNumber int64) bool

NeedsReplication checks does a new generation have to be created TODO: Make sure this is correct.

func (*KeyStateMachine) NewGeneration

func (ksm *KeyStateMachine) NewGeneration(
	newNode string,
) (
	generationNumber int64, peers []string, err error,
)

NewGeneration creates a new generation when a new node is added.

func (*KeyStateMachine) NodeInGeneration

func (ksm *KeyStateMachine) NodeInGeneration(generationNumber int64, nodeID string) bool

NodeInGeneration checks is the specified node in the provided generation

func (*KeyStateMachine) OwnerComplete

func (ksm *KeyStateMachine) OwnerComplete(ownerID string, generation int64) error

OwnerComplete assigns an owner TODO: Make sure this is correct.

func (*KeyStateMachine) Serialise

func (ksm *KeyStateMachine) Serialise(writer io.Writer) error

Serialise to GOB encoding and write to the io.Writer

func (*KeyStateMachine) SerialiseToPFSDir

func (ksm *KeyStateMachine) SerialiseToPFSDir() error

SerialiseToPFSDir as gob and write to file

func (*KeyStateMachine) Update

func (ksm *KeyStateMachine) Update(req *pb.KeyStateCommand) error

Update the KeyStateMachine

func (*KeyStateMachine) UpdateFromStateFile

func (ksm *KeyStateMachine) UpdateFromStateFile(filePath string) error

UpdateFromStateFile updates the KeyStateMachine from a file.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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