Documentation ¶
Overview ¶
Package decrypt implements the protocoll of the service to start a poll and decrypt a list of votes.
The service as to be initialized with decrypt.New(crypto_backend, storage_backend, [options...]).
Index ¶
- type Crypto
- type Decrypt
- func (d *Decrypt) Clear(ctx context.Context, pollID string) error
- func (d *Decrypt) PublicMainKey(ctx context.Context) []byte
- func (d *Decrypt) Start(ctx context.Context, pollID string) (pubKey []byte, pubKeySig []byte, err error)
- func (d *Decrypt) Stop(ctx context.Context, pollID string, voteList [][]byte) (decryptedContent, signature []byte, err error)
- type Option
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Crypto ¶
type Crypto interface { // CreatePollKey creates a new keypair for a poll. CreatePollKey() ([]byte, error) // PublicPollKey returns the public poll key and the signature for a given key. PublicPollKey(key []byte) (pubKey []byte, pubKeySig []byte, err error) // Decrypt returned the plaintext from value using the key. Decrypt(key []byte, value []byte) ([]byte, error) // Sign returns the signature for the given data. Sign(value []byte) []byte // PublicMainKey returns the public main key. PublicMainKey() []byte }
Crypto implements all required cryptographic functions.
type Decrypt ¶
type Decrypt struct {
// contains filtered or unexported fields
}
Decrypt holds the internal state of the decrypt component.
func (*Decrypt) PublicMainKey ¶
PublicMainKey returns the public main key.
func (*Decrypt) Start ¶
func (d *Decrypt) Start(ctx context.Context, pollID string) (pubKey []byte, pubKeySig []byte, err error)
Start starts the poll. Returns a public poll key.
It generates a cryptographic key, saves the poll meta data and returns the public key. It also returns a signature of the public key created with the main key.
If the method is called multiple times with the same pollID, it returns the same public key. This is at least true until Clear() is called.
func (*Decrypt) Stop ¶
func (d *Decrypt) Stop(ctx context.Context, pollID string, voteList [][]byte) (decryptedContent, signature []byte, err error)
Stop takes a list of ecrypted votes, decryptes them and returns them in a random order together with a signature.
If the function is called multiple times with the same pollID and voteList, it returns the same output. But if fails if it is called with different votes.
TODO: This implementation is wrong. Not the output has to be hashed and saved, but the input.
type Option ¶
type Option = func(*Decrypt)
Option for decrypt.New().
func WithListToContent ¶
WithListToContent takes a function that is used to create the content returned from the Stop() call.
The function taks an id and the randomized list of decrypted votes and createa the output format.
func WithMaxVotes ¶
WithMaxVotes sets the number of maximum votes, that are supported.
type Store ¶
type Store interface { // SaveKey stores the private key. // // Has to return an error `errorcode.Exist` if the key is already known. SaveKey(id string, key []byte) error // LoadKey returns the private key from the store. // // If the poll is unknown return `errorcode.NotExist` LoadKey(id string) (key []byte, err error) // ValidateSignature makes sure, that no other signature is saved for a // poll. Saves the signature for future calls. // // Has to return `errorcode.Invalid` if the hash differs from a privious // call. // // Has to return `errorcode.NotExist` when the id does not exist. ValidateSignature(id string, hash []byte) error // ClearPoll removes all data for the poll. // // Does not return an error if poll does not exist. ClearPoll(id string) error }
Store saves the data, that have to be persistent.