Documentation ¶
Overview ¶
Package keys holds E4 key material implementations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPubKeyNotFound occurs when a public key is missing when verifying a signature ErrPubKeyNotFound = errors.New("signer public key not found") )
Functions ¶
This section is empty.
Types ¶
type KeyMaterial ¶
type KeyMaterial interface { // ProtectMessage encrypt given payload using the topicKey // and returns the protected cipher, or an error ProtectMessage(payload []byte, topicKey TopicKey) ([]byte, error) // UnprotectMessage decrypt the given cipher using the topicKey // and returns the clear payload, or an error UnprotectMessage(protected []byte, topicKey TopicKey) ([]byte, error) // UnprotectCommand decrypt the given protected command using the key material private key // and returns the command, or an error UnprotectCommand(protected []byte) ([]byte, error) // SetKey sets the material private key, or return an error when the key is invalid SetKey(key []byte) error // MarshalJSON marshal the key material into json MarshalJSON() ([]byte, error) // contains filtered or unexported methods }
KeyMaterial defines an interface for E4 client key implementations It holds the client private key, and allows to defines how messages will be encrypted or decrypted, and how commands will be unprotected. A KeyMaterial must also marshal into a jsonKey, allowing the client to properly store and load the key material
func FromRawJSON ¶
func FromRawJSON(raw json.RawMessage) (KeyMaterial, error)
FromRawJSON allows to unmarshal a json encoded jsonKey from a json RawMessage It returns a ready to use KeyMaterial, or an error if it cannot decode it.
type PubKeyMaterial ¶
type PubKeyMaterial interface { KeyMaterial PubKeyStore PublicKey() ed25519.PublicKey }
PubKeyMaterial extends the ClientKey and PubKeyStore interfaces for public key implementations
func NewPubKeyMaterial ¶
func NewPubKeyMaterial(signerID []byte, privateKey ed25519.PrivateKey, c2PubKey e4crypto.Curve25519PublicKey) (PubKeyMaterial, error)
NewPubKeyMaterial creates a new KeyMaterial to work with public e4 client key
func NewRandomPubKeyMaterial ¶
func NewRandomPubKeyMaterial(signerID []byte, c2PubKey e4crypto.Curve25519PublicKey) (PubKeyMaterial, error)
NewRandomPubKeyMaterial creates a new PubKeyMaterial key from a random ed25519 key
type PubKeyStore ¶
type PubKeyStore interface { // AddPubKey allows to add a public key to the store, identified by ID. // If a key already exists with this ID, it will be replaced. AddPubKey(id []byte, key ed25519.PublicKey) error // GetPubKey returns the public key associated to the ID. // ErrPubKeyNotFound is returned when it cannot be found. GetPubKey(id []byte) (ed25519.PublicKey, error) // GetPubKeys returns all stored public keys, in a ID indexed map. GetPubKeys() map[string]ed25519.PublicKey // RemovePubKey removes a public key from the store by its ID, or returns // an error if it doesn't exists. RemovePubKey(id []byte) error // ResetPubKeys removes all public keys stored. ResetPubKeys() // SetC2PubKey replaces the current C2 public key with the newly transmitted one. SetC2PubKey(c2PubKey e4crypto.Curve25519PublicKey) error }
PubKeyStore interface defines methods to interact with a public key storage A key material implementing a PubKeyStore enable the client to receive any of the pubKey's commands. When the KeyMaterial doesn't implement it, such commands will return a ErrUnsupportedOperation error.
type SymKeyMaterial ¶
type SymKeyMaterial interface { KeyMaterial }
SymKeyMaterial extends the KeyMaterial interface for symmetric key implementations
func NewRandomSymKeyMaterial ¶
func NewRandomSymKeyMaterial() (SymKeyMaterial, error)
NewRandomSymKeyMaterial creates a new SymKeyMaterial from random value
func NewSymKeyMaterial ¶
func NewSymKeyMaterial(key []byte) (SymKeyMaterial, error)
NewSymKeyMaterial creates a new SymKeyMaterial